diff --git a/src/Mass/ArmourPart.h b/src/Mass/ArmourPart.h index 4374764..7246b89 100644 --- a/src/Mass/ArmourPart.h +++ b/src/Mass/ArmourPart.h @@ -18,6 +18,7 @@ #include +#include #include #include @@ -73,7 +74,6 @@ struct ArmourPart { ArmourSlot slot = ArmourSlot::Face; Int id = 0; Containers::StaticArray<4, Int> styles{ValueInit}; - UnsignedInt demoDecals = 8; - Containers::StaticArray<8, Decal> decals{ValueInit}; - Containers::StaticArray<8, Accessory> accessories{ValueInit}; + Containers::Array decals; + Containers::Array accessories; }; diff --git a/src/Mass/Mass.cpp b/src/Mass/Mass.cpp index 9c8a18a..3cc7bd4 100644 --- a/src/Mass/Mass.cpp +++ b/src/Mass/Mass.cpp @@ -174,12 +174,9 @@ void Mass::refreshValues() { return; } - if(!_demo) - { - getGlobalStyles(); - if(_state == State::Invalid) { - return; - } + getGlobalStyles(); + if(_state == State::Invalid) { + return; } getTuning(); @@ -232,10 +229,6 @@ auto Mass::state() -> State { return _state; } -auto Mass::demo() const -> bool { - return _demo; -} - auto Mass::dirty() const -> bool { return _dirty; } @@ -615,55 +608,53 @@ void Mass::getArmourParts() { return; } - if(decals_array->items.size() != part.decals.size()) { - part.demoDecals = decals_array->items.size(); - _demo = true; - } + part.decals = Containers::Array{decals_array->items.size()}; getDecals(part.decals, decals_array); - if(!_demo) { - auto accs_array = part_prop->at("Accessories_52_D902DD4241FA0050C2529596255153F3"); - if(!accs_array) { - _demo = true; - continue; - } - - if(accs_array->items.size() != part.accessories.size()) { - _state = State::Invalid; - return; - } - - getAccessories(part.accessories, accs_array); + auto accs_array = part_prop->at("Accessories_52_D902DD4241FA0050C2529596255153F3"); + if(!accs_array) { + part.accessories = Containers::Array{}; + continue; } + + if(part.accessories.size() != accs_array->items.size()) { + part.accessories = Containers::Array{accs_array->items.size()}; + } + + getAccessories(part.accessories, accs_array); } } -auto Mass::writeArmourPart(UnsignedLong index) -> bool { - if(index > _armour.parts.size()) { - return false; - } +auto Mass::writeArmourPart(ArmourSlot slot) -> bool { + auto& part = *std::find_if(_armour.parts.begin(), _armour.parts.end(), [&slot](const ArmourPart& part){ return slot == part.slot; }); auto unit_data = _mass->at("UnitData"); auto armour_array = unit_data->at("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"); - auto part_prop = armour_array->at(index); - - auto& part = _armour.parts[index]; - - auto& armour_slot = part_prop->at("Slot_3_408BA56F4C9605C7E805CF91B642249C")->enumValue; - switch(part.slot) { - #define c(enumerator, strenum, name) case ArmourSlot::enumerator: \ - if((strenum) != armour_slot) { \ - _lastError = "Armour part slot doesn't match save file."; \ - return false; \ - } \ + const char* slot_str = nullptr; + switch(slot) { + #define c(enumerator, strenum, name) case ArmourSlot::enumerator: \ + slot_str = strenum; \ break; #include "../Maps/ArmourSlots.hpp" #undef c } + GenericStructProperty* part_prop = nullptr; + + for(UnsignedInt i = 0; i < armour_array->items.size(); i++) { + part_prop = armour_array->at(i); + if(slot_str != part_prop->at("Slot_3_408BA56F4C9605C7E805CF91B642249C")->value) { + part_prop = nullptr; + } + } + + if(!part_prop) { + return false; + } + part_prop->at("ID_5_ACD101864D3481DE96EDACACC09BDD25")->value = part.id; auto part_styles = part_prop->at("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"); @@ -672,72 +663,11 @@ auto Mass::writeArmourPart(UnsignedLong index) -> bool { } auto decals_array = part_prop->at("Decals_42_F358794A4F18497970F56BA9627D3603"); - for(UnsignedInt i = 0; i < decals_array->items.size(); i++) { - auto decal_prop = decals_array->at(i); - auto& decal = part.decals[i]; + writeDecals(part.decals, decals_array); - decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id; - auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"); - 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("Position_41_022C8FE84E1AAFE587261E88F2C72250"); - pos_prop->x = decal.position.x(); - pos_prop->y = decal.position.y(); - pos_prop->z = decal.position.z(); - auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"); - u_prop->x = decal.uAxis.x(); - u_prop->y = decal.uAxis.y(); - u_prop->z = decal.uAxis.z(); - auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"); - v_prop->x = decal.vAxis.x(); - v_prop->y = decal.vAxis.y(); - v_prop->z = decal.vAxis.z(); - auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"); - offset_prop->x = decal.offset.x(); - offset_prop->y = decal.offset.y(); - decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40")->value = decal.scale; - decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F")->value = decal.rotation; - decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1")->value = decal.flip; - decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62")->value = decal.wrap; - } - - if(!_demo) { + if(part.accessories.size() != 0) { auto accs_array = part_prop->at("Accessories_52_D902DD4241FA0050C2529596255153F3"); - - for(UnsignedInt i = 0; i < accs_array->items.size(); i++) { - auto acc_prop = accs_array->at(i); - - auto& accessory = part.accessories[i]; - - acc_prop->at("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20")->value = accessory.attachIndex; - acc_prop->at("ID_4_5757B32647BAE263266259B8A7DFFFC1")->value = accessory.id; - auto acc_styles = acc_prop->at("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"); - for(UnsignedInt j = 0; j < acc_styles->items.size(); j++) { - acc_styles->at(j)->value = accessory.styles[j]; - } - auto rel_pos_prop = acc_prop->at("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"); - 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("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"); - 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("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"); - 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("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"); - 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("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"); - local_scale_prop->x = accessory.localScale.x(); - local_scale_prop->y = accessory.localScale.y(); - local_scale_prop->z = accessory.localScale.z(); - } + writeAccessories(part.accessories, accs_array); } return _mass->saveToFile(); @@ -873,12 +803,12 @@ void Mass::getGlobalStyles() { auto global_styles = unit_data->at("GlobalStyles_57_6A681C114035241F7BDAAE9B43A8BF1B"); if(!global_styles) { - _state = State::Invalid; + _globalStyles = Containers::Array{0}; return; } if(global_styles->items.size() != _globalStyles.size()) { - _state = State::Invalid; + _globalStyles = Containers::Array{global_styles->items.size()}; return; } @@ -946,6 +876,10 @@ auto Mass::techs() -> Containers::ArrayView { return _tuning.techIds; } +auto Mass::account() -> const std::string& { + return _account; +} + auto Mass::updateAccount(const std::string& new_account) -> bool { _account = new_account; @@ -1032,6 +966,39 @@ void Mass::getDecals(Containers::ArrayView decals, ArrayProperty* decal_a } } +void Mass::writeDecals(Containers::ArrayView decals, ArrayProperty* decal_array) { + for(UnsignedInt i = 0; i < decal_array->items.size(); i++) { + auto decal_prop = decal_array->at(i); + auto& decal = decals[i]; + + decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id; + auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"); + 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("Position_41_022C8FE84E1AAFE587261E88F2C72250"); + pos_prop->x = decal.position.x(); + pos_prop->y = decal.position.y(); + pos_prop->z = decal.position.z(); + auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"); + u_prop->x = decal.uAxis.x(); + u_prop->y = decal.uAxis.y(); + u_prop->z = decal.uAxis.z(); + auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"); + v_prop->x = decal.vAxis.x(); + v_prop->y = decal.vAxis.y(); + v_prop->z = decal.vAxis.z(); + auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"); + offset_prop->x = decal.offset.x(); + offset_prop->y = decal.offset.y(); + decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40")->value = decal.scale; + decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F")->value = decal.rotation; + decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1")->value = decal.flip; + decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62")->value = decal.wrap; + } +} + void Mass::getAccessories(Containers::ArrayView accessories, ArrayProperty* accessory_array) { for(UnsignedInt i = 0; i < accessory_array->items.size(); i++) { auto acc_prop = accessory_array->at(i); @@ -1056,6 +1023,40 @@ void Mass::getAccessories(Containers::ArrayView accessories, ArrayPro } } +void Mass::writeAccessories(Containers::ArrayView accessories, ArrayProperty* accs_array) { + for(UnsignedInt i = 0; i < accs_array->items.size(); i++) { + auto acc_prop = accs_array->at(i); + auto& accessory = accessories[i]; + + acc_prop->at("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20")->value = accessory.attachIndex; + acc_prop->at("ID_4_5757B32647BAE263266259B8A7DFFFC1")->value = accessory.id; + auto acc_styles = acc_prop->at("Styles_7_91DEB0F24E24D13FC9472882C11D0DFD"); + for(UnsignedInt j = 0; j < acc_styles->items.size(); j++) { + acc_styles->at(j)->value = accessory.styles[j]; + } + auto rel_pos_prop = acc_prop->at("RelativePosition_14_BE8FB2A94074F34B3EDA6683B227D3A1"); + 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("RelativePositionOffset_15_98FD0CE74E44BBAFC2D46FB4CA4E0ED6"); + 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("RelativeRotation_20_C78C73274E6E78E7878F8C98ECA342C0"); + 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("RelativeRotationOffset_21_E07FA0EC46728B7BA763C6861249ABAA"); + 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("LocalScale_24_DC2D93A742A41A46E7E61D988F15ED53"); + local_scale_prop->x = accessory.localScale.x(); + local_scale_prop->y = accessory.localScale.y(); + local_scale_prop->z = accessory.localScale.z(); + } +} + void Mass::getWeaponType(const char* prop_name, Containers::ArrayView weapon_array) { auto unit_data = _mass->at("UnitData"); if(!unit_data) { @@ -1104,26 +1105,21 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we auto part_decals = part_prop->at("Decals_13_8B81112B453D7230C0CDE982185E14F1"); if(part_decals->items.size() != part.decals.size()) { - _demo = true; - part.demoDecals = part_decals->items.size(); + part.decals = Containers::Array{part_decals->items.size()}; } getDecals(part.decals, part_decals); - if(!_demo) { - auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"); - if(!part_accs) { - _demo = true; - continue; - } - - if(part_accs->items.size() != part.accessories.size()) { - _state = State::Invalid; - return; - } - - getAccessories(part.accessories, part_accs); + auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"); + if(!part_accs) { + part.accessories = Containers::Array{0}; + continue; } + + if(part_accs->items.size() != part.accessories.size()) { + part.accessories = Containers::Array{part_accs->items.size()}; + } + getAccessories(part.accessories, part_accs); } auto custom_styles = weapon_prop->at("Styles_10_8C3C82444B986AD7A99595AD4985912D"); @@ -1204,51 +1200,19 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView } auto part_decals = part_prop->at("Decals_13_8B81112B453D7230C0CDE982185E14F1"); - for(UnsignedInt k = 0; k < part_decals->items.size(); k++) { - auto decal_prop = part_decals->at(k); - auto& decal = part.decals[k]; + writeDecals(part.decals, part_decals); - decal_prop->at("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id; - auto colour_prop = decal_prop->at("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606"); - 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("Position_41_022C8FE84E1AAFE587261E88F2C72250"); - pos_prop->x = decal.position.x(); - pos_prop->y = decal.position.y(); - pos_prop->z = decal.position.z(); - auto u_prop = decal_prop->at("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1"); - u_prop->x = decal.uAxis.x(); - u_prop->y = decal.uAxis.y(); - u_prop->z = decal.uAxis.z(); - auto v_prop = decal_prop->at("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35"); - v_prop->x = decal.vAxis.x(); - v_prop->y = decal.vAxis.y(); - v_prop->z = decal.vAxis.z(); - auto offset_prop = decal_prop->at("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020"); - offset_prop->x = decal.offset.x(); - offset_prop->y = decal.offset.y(); - decal_prop->at("Scale_32_959D1C2747AFD8D62808468235CBBA40")->value = decal.scale; - decal_prop->at("Rotation_27_12D7C314493D203D5C2326A03C5F910F")->value = decal.rotation; - decal_prop->at("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1")->value = decal.flip; - decal_prop->at("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62")->value = decal.wrap; + auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"); + if(!part_accs) { + continue; } - if(!_demo) { - auto part_accs = part_prop->at("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C"); - if(!part_accs) { - _demo = true; - continue; - } - - if(part_accs->items.size() != part.accessories.size()) { - _state = State::Invalid; - return false; - } - - getAccessories(part.accessories, part_accs); + if(part_accs->items.size() != part.accessories.size()) { + _state = State::Invalid; + return false; } + + writeAccessories(part.accessories, part_accs); } auto custom_styles = weapon_prop->at("Styles_10_8C3C82444B986AD7A99595AD4985912D"); diff --git a/src/Mass/Mass.h b/src/Mass/Mass.h index c89c9f3..f46a4e9 100644 --- a/src/Mass/Mass.h +++ b/src/Mass/Mass.h @@ -69,8 +69,6 @@ class Mass { auto state() -> State; - auto demo() const -> bool; - auto dirty() const -> bool; void setDirty(bool dirty = true); @@ -92,7 +90,7 @@ class Mass { auto armourParts() -> Containers::ArrayView; void getArmourParts(); - auto writeArmourPart(UnsignedLong index) -> bool; + auto writeArmourPart(ArmourSlot slot) -> bool; auto armourCustomStyles() -> Containers::ArrayView; void getArmourCustomStyles(); @@ -145,7 +143,10 @@ class Mass { auto setCustomStyle(const CustomStyle& style, UnsignedLong index, ArrayProperty* style_array) -> bool; void getDecals(Containers::ArrayView decals, ArrayProperty* decal_array); + void writeDecals(Containers::ArrayView decals, ArrayProperty* decal_array); + void getAccessories(Containers::ArrayView accessories, ArrayProperty* accessory_array); + void writeAccessories(Containers::ArrayView accessories, ArrayProperty* accs_array); void getWeaponType(const char* prop_name, Containers::ArrayView weapon_array); auto writeWeaponType(const char* prop_name, Containers::ArrayView weapon_array) -> bool; @@ -160,7 +161,6 @@ class Mass { std::string _folder; std::string _filename; State _state = State::Empty; - bool _demo = false; bool _dirty = false; @@ -191,7 +191,7 @@ class Mass { Containers::StaticArray<4, Weapon> energyLaunchers; } _weapons; - Containers::StaticArray<16, CustomStyle> _globalStyles; + Containers::Array _globalStyles; struct { Int engineId; diff --git a/src/Mass/WeaponPart.h b/src/Mass/WeaponPart.h index a6cb1a4..227b5af 100644 --- a/src/Mass/WeaponPart.h +++ b/src/Mass/WeaponPart.h @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include #include @@ -27,9 +28,39 @@ using namespace Corrade; using namespace Magnum; struct WeaponPart { + WeaponPart() = default; + + WeaponPart(const WeaponPart& other) { + id = other.id; + styles = other.styles; + decals = Containers::Array{other.decals.size()}; + for(UnsignedInt i = 0; i < decals.size(); i++) { + decals[i] = other.decals[i]; + } + accessories = Containers::Array{other.accessories.size()}; + for(UnsignedInt i = 0; i < accessories.size(); i++) { + accessories[i] = other.accessories[i]; + } + } + WeaponPart& operator=(const WeaponPart& other) { + id = other.id; + styles = other.styles; + decals = Containers::Array{other.decals.size()}; + for(UnsignedInt i = 0; i < decals.size(); i++) { + decals[i] = other.decals[i]; + } + accessories = Containers::Array{other.accessories.size()}; + for(UnsignedInt i = 0; i < accessories.size(); i++) { + accessories[i] = other.accessories[i]; + } + return *this; + } + + WeaponPart(WeaponPart&& other) = default; + WeaponPart& operator=(WeaponPart&& other) = default; + Int id = 0; Containers::StaticArray<4, Int> styles{ValueInit}; - UnsignedInt demoDecals = 8; - Containers::StaticArray<8, Decal> decals{ValueInit}; - Containers::StaticArray<8, Accessory> accessories{ValueInit}; + Containers::Array decals{}; + Containers::Array accessories{}; }; diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index 942c68c..a73a866 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -133,7 +133,7 @@ void SaveTool::drawMassViewer() { ImGui::EndTabItem(); } - if(!_currentMass->demo() && ImGui::BeginTabItem("Global styles")) { + if(!_currentMass->globalStyles().size() != 0 && ImGui::BeginTabItem("Global styles")) { drawGlobalStyles(); ImGui::EndTabItem(); } @@ -547,7 +547,7 @@ void SaveTool::drawArmour() { ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("Showing/editing decal"); - for(UnsignedLong j = 0; j < part.demoDecals; j++) { + for(UnsignedLong j = 0; j < part.decals.size(); j++) { ImGui::SameLine(); ImGui::RadioButton(std::to_string(j + 1).c_str(), &_selectedArmourDecals[i], j); } @@ -556,7 +556,7 @@ void SaveTool::drawArmour() { ImGui::PopID(); - if(!_currentMass->demo()) { + if(!part.accessories.size()) { ImGui::Separator(); ImGui::PushID("Accessory"); @@ -576,7 +576,7 @@ void SaveTool::drawArmour() { ImGui::Separator(); if(drawUnsafeWidget([]{ return ImGui::Button(ICON_FA_SAVE " Save"); })) { - _currentMass->writeArmourPart(i); + _currentMass->writeArmourPart(part.slot); } } @@ -1016,7 +1016,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("Showing/editing decal"); - for(UnsignedLong i = 0; i < part.demoDecals; i++) { + for(UnsignedLong i = 0; i < part.decals.size(); i++) { ImGui::SameLine(); ImGui::RadioButton(std::to_string(i + 1).c_str(), &_selectedWeaponDecal, i); } @@ -1025,7 +1025,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::PopID(); - if(_currentMass->demo() == false) { + if(part.accessories.size() != 0) { ImGui::Separator(); ImGui::PushID("Accessory");