William JCM
9c074c24bd
Magnum's type names are fine, but I'd rather limit what depends on Magnum as much as possible. Vector types are still allowed, though. No way I'll write my own.
152 lines
8.1 KiB
C++
152 lines
8.1 KiB
C++
// MassBuilderSaveTool
|
|
// Copyright (C) 2021-2022 Guillaume Jacquemin
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include "PropertyNames.h"
|
|
#include "../UESaveFile/Types/ArrayProperty.h"
|
|
#include "../UESaveFile/Types/BoolProperty.h"
|
|
#include "../UESaveFile/Types/ColourStructProperty.h"
|
|
#include "../UESaveFile/Types/FloatProperty.h"
|
|
#include "../UESaveFile/Types/GenericStructProperty.h"
|
|
#include "../UESaveFile/Types/RotatorStructProperty.h"
|
|
#include "../UESaveFile/Types/VectorStructProperty.h"
|
|
#include "../UESaveFile/Types/Vector2DStructProperty.h"
|
|
#include "../UESaveFile/Types/IntProperty.h"
|
|
|
|
#include "Mass.h"
|
|
|
|
using namespace Containers::Literals;
|
|
|
|
void
|
|
Mass::getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) {
|
|
for(std::uint32_t i = 0; i < decal_array->items.size(); i++) {
|
|
auto decal_prop = decal_array->at<GenericStructProperty>(i);
|
|
CORRADE_INTERNAL_ASSERT(decal_prop);
|
|
auto& decal = decals[i];
|
|
|
|
decal.id = decal_prop->at<IntProperty>(MASS_DECAL_ID)->value;
|
|
auto colour_prop = decal_prop->at<ColourStructProperty>(MASS_DECAL_COLOUR);
|
|
decal.colour = Color4{colour_prop->r, colour_prop->g, colour_prop->b, colour_prop->a};
|
|
auto pos_prop = decal_prop->at<VectorStructProperty>(MASS_DECAL_POSITION);
|
|
decal.position = Vector3{pos_prop->x, pos_prop->y, pos_prop->z};
|
|
auto u_prop = decal_prop->at<VectorStructProperty>(MASS_DECAL_UAXIS);
|
|
decal.uAxis = Vector3{u_prop->x, u_prop->y, u_prop->z};
|
|
auto v_prop = decal_prop->at<VectorStructProperty>(MASS_DECAL_VAXIS);
|
|
decal.vAxis = Vector3{v_prop->x, v_prop->y, v_prop->z};
|
|
auto offset_prop = decal_prop->at<Vector2DStructProperty>(MASS_DECAL_OFFSET);
|
|
decal.offset = Vector2{offset_prop->x, offset_prop->y};
|
|
decal.scale = decal_prop->at<FloatProperty>(MASS_DECAL_SCALE)->value;
|
|
decal.rotation = decal_prop->at<FloatProperty>(MASS_DECAL_ROTATION)->value;
|
|
decal.flip = decal_prop->at<BoolProperty>(MASS_DECAL_FLIP)->value;
|
|
decal.wrap = decal_prop->at<BoolProperty>(MASS_DECAL_WRAP)->value;
|
|
}
|
|
}
|
|
|
|
void
|
|
Mass::writeDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) {
|
|
for(std::uint32_t i = 0; i < decal_array->items.size(); i++) {
|
|
auto decal_prop = decal_array->at<GenericStructProperty>(i);
|
|
CORRADE_INTERNAL_ASSERT(decal_prop);
|
|
auto& decal = decals[i];
|
|
|
|
decal_prop->at<IntProperty>(MASS_DECAL_ID)->value = decal.id;
|
|
auto colour_prop = decal_prop->at<ColourStructProperty>(MASS_DECAL_COLOUR);
|
|
colour_prop->r = decal.colour.r();
|
|
colour_prop->g = decal.colour.g();
|
|
colour_prop->b = decal.colour.b();
|
|
colour_prop->a = decal.colour.a();
|
|
auto pos_prop = decal_prop->at<VectorStructProperty>(MASS_DECAL_POSITION);
|
|
pos_prop->x = decal.position.x();
|
|
pos_prop->y = decal.position.y();
|
|
pos_prop->z = decal.position.z();
|
|
auto u_prop = decal_prop->at<VectorStructProperty>(MASS_DECAL_UAXIS);
|
|
u_prop->x = decal.uAxis.x();
|
|
u_prop->y = decal.uAxis.y();
|
|
u_prop->z = decal.uAxis.z();
|
|
auto v_prop = decal_prop->at<VectorStructProperty>(MASS_DECAL_VAXIS);
|
|
v_prop->x = decal.vAxis.x();
|
|
v_prop->y = decal.vAxis.y();
|
|
v_prop->z = decal.vAxis.z();
|
|
auto offset_prop = decal_prop->at<Vector2DStructProperty>(MASS_DECAL_OFFSET);
|
|
offset_prop->x = decal.offset.x();
|
|
offset_prop->y = decal.offset.y();
|
|
decal_prop->at<FloatProperty>(MASS_DECAL_SCALE)->value = decal.scale;
|
|
decal_prop->at<FloatProperty>(MASS_DECAL_ROTATION)->value = decal.rotation;
|
|
decal_prop->at<BoolProperty>(MASS_DECAL_FLIP)->value = decal.flip;
|
|
decal_prop->at<BoolProperty>(MASS_DECAL_WRAP)->value = decal.wrap;
|
|
}
|
|
}
|
|
|
|
void
|
|
Mass::getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array) {
|
|
for(std::uint32_t i = 0; i < accessory_array->items.size(); i++) {
|
|
auto acc_prop = accessory_array->at<GenericStructProperty>(i);
|
|
CORRADE_INTERNAL_ASSERT(acc_prop);
|
|
auto& accessory = accessories[i];
|
|
|
|
accessory.attachIndex = acc_prop->at<IntProperty>(MASS_ACCESSORY_ATTACH_INDEX)->value;
|
|
accessory.id = acc_prop->at<IntProperty>(MASS_ACCESSORY_ID)->value;
|
|
auto acc_styles = acc_prop->at<ArrayProperty>(MASS_ACCESSORY_STYLES);
|
|
for(std::uint32_t j = 0; j < acc_styles->items.size(); j++) {
|
|
accessory.styles[j] = acc_styles->at<IntProperty>(j)->value;
|
|
}
|
|
auto rel_pos_prop = acc_prop->at<VectorStructProperty>(MASS_ACCESSORY_RELPOS);
|
|
accessory.relativePosition = Vector3{rel_pos_prop->x, rel_pos_prop->y, rel_pos_prop->z};
|
|
auto rel_pos_offset_prop = acc_prop->at<VectorStructProperty>(MASS_ACCESSORY_OFFPOS);
|
|
accessory.relativePositionOffset = Vector3{rel_pos_offset_prop->x, rel_pos_offset_prop->y, rel_pos_offset_prop->z};
|
|
auto rel_rot_prop = acc_prop->at<RotatorStructProperty>(MASS_ACCESSORY_RELROT);
|
|
accessory.relativeRotation = Vector3{rel_rot_prop->x, rel_rot_prop->y, rel_rot_prop->z};
|
|
auto rel_rot_offset_prop = acc_prop->at<RotatorStructProperty>(MASS_ACCESSORY_OFFROT);
|
|
accessory.relativeRotationOffset = Vector3{rel_rot_offset_prop->x, rel_rot_offset_prop->y, rel_rot_offset_prop->z};
|
|
auto local_scale_prop = acc_prop->at<VectorStructProperty>(MASS_ACCESSORY_SCALE);
|
|
accessory.localScale = Vector3{local_scale_prop->x, local_scale_prop->y, local_scale_prop->z};
|
|
}
|
|
}
|
|
|
|
void
|
|
Mass::writeAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accs_array) {
|
|
for(std::uint32_t i = 0; i < accs_array->items.size(); i++) {
|
|
auto acc_prop = accs_array->at<GenericStructProperty>(i);
|
|
CORRADE_INTERNAL_ASSERT(acc_prop);
|
|
auto& accessory = accessories[i];
|
|
|
|
acc_prop->at<IntProperty>(MASS_ACCESSORY_ATTACH_INDEX)->value = accessory.attachIndex;
|
|
acc_prop->at<IntProperty>(MASS_ACCESSORY_ID)->value = accessory.id;
|
|
auto acc_styles = acc_prop->at<ArrayProperty>(MASS_ACCESSORY_STYLES);
|
|
for(std::uint32_t j = 0; j < acc_styles->items.size(); j++) {
|
|
acc_styles->at<IntProperty>(j)->value = accessory.styles[j];
|
|
}
|
|
auto rel_pos_prop = acc_prop->at<VectorStructProperty>(MASS_ACCESSORY_RELPOS);
|
|
rel_pos_prop->x = accessory.relativePosition.x();
|
|
rel_pos_prop->y = accessory.relativePosition.y();
|
|
rel_pos_prop->z = accessory.relativePosition.z();
|
|
auto rel_pos_offset_prop = acc_prop->at<VectorStructProperty>(MASS_ACCESSORY_OFFPOS);
|
|
rel_pos_offset_prop->x = accessory.relativePositionOffset.x();
|
|
rel_pos_offset_prop->y = accessory.relativePositionOffset.y();
|
|
rel_pos_offset_prop->z = accessory.relativePositionOffset.z();
|
|
auto rel_rot_prop = acc_prop->at<RotatorStructProperty>(MASS_ACCESSORY_RELROT);
|
|
rel_rot_prop->x = accessory.relativeRotation.x();
|
|
rel_rot_prop->y = accessory.relativeRotation.y();
|
|
rel_rot_prop->z = accessory.relativeRotation.z();
|
|
auto rel_rot_offset_prop = acc_prop->at<RotatorStructProperty>(MASS_ACCESSORY_OFFROT);
|
|
rel_rot_offset_prop->x = accessory.relativeRotationOffset.x();
|
|
rel_rot_offset_prop->y = accessory.relativeRotationOffset.y();
|
|
rel_rot_offset_prop->z = accessory.relativeRotationOffset.z();
|
|
auto local_scale_prop = acc_prop->at<VectorStructProperty>(MASS_ACCESSORY_SCALE);
|
|
local_scale_prop->x = accessory.localScale.x();
|
|
local_scale_prop->y = accessory.localScale.y();
|
|
local_scale_prop->z = accessory.localScale.z();
|
|
}
|
|
}
|