From 28db82c8a9db68ef9ee0dec5e1fb0e4570b6efea Mon Sep 17 00:00:00 2001 From: William JCM Date: Wed, 9 Feb 2022 14:17:05 +0100 Subject: [PATCH] Weapon,Mass,SaveTool: refactor some more code. --- src/CMakeLists.txt | 1 + src/Maps/DamageTypes.hpp | 24 ++++++++++++++++++++++++ src/Mass/Mass.cpp | 19 ++++++++++++++++--- src/Mass/Weapon.h | 11 ++++++++++- src/SaveTool/SaveTool_MassViewer.cpp | 24 ++++++++++++------------ 5 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 src/Maps/DamageTypes.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 500b132..e6bb24e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,6 +137,7 @@ add_executable(MassBuilderSaveTool WIN32 Maps/Accessories.h Maps/ArmourSets.h Maps/ArmourSlots.h + Maps/DamageTypes.hpp Maps/LastMissionId.h Maps/StoryProgress.h Maps/StyleNames.h diff --git a/src/Maps/DamageTypes.hpp b/src/Maps/DamageTypes.hpp new file mode 100644 index 0000000..5665f65 --- /dev/null +++ b/src/Maps/DamageTypes.hpp @@ -0,0 +1,24 @@ +// 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 . + +#ifdef c +c(Physical, "enuDamageProperty::NewEnumerator0") +c(Piercing, "enuDamageProperty::NewEnumerator1") +c(Heat, "enuDamageProperty::NewEnumerator2") +c(Freeze, "enuDamageProperty::NewEnumerator3") +c(Shock, "enuDamageProperty::NewEnumerator4") +c(Plasma, "enuDamageProperty::NewEnumerator5") +#endif diff --git a/src/Mass/Mass.cpp b/src/Mass/Mass.cpp index eff9fdd..9371ade 100644 --- a/src/Mass/Mass.cpp +++ b/src/Mass/Mass.cpp @@ -1063,7 +1063,7 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we auto& weapon = weapon_array[i]; weapon.name = weapon_prop->at("Name_13_7BF0D31F4E50C50C47231BB36A485D92")->value; - std::string& weapon_type = weapon_prop->at("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue; + auto& weapon_type = weapon_prop->at("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue; #define c(enumerator, strenum, name) if(weapon_type == (strenum)) { weapon.type = WeaponType::enumerator; } else #include "../Maps/WeaponTypes.hpp" #undef c @@ -1124,7 +1124,14 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView we getCustomStyles(weapon.customStyles, custom_styles); weapon.attached = weapon_prop->at("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value; - weapon.damageType = weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue; + auto& damage_type = weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue; + #define c(enumerator, strenum) if(damage_type == (strenum)) { weapon.damageType = DamageType::enumerator; } else + #include "../Maps/DamageTypes.hpp" + #undef c + { + _state = State::Invalid; + Utility::Warning{} << "Invalid damage type enum value in getWeaponType()."; + } weapon.dualWield = weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value; weapon.effectColourMode = weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue; auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"); @@ -1244,7 +1251,13 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView } weapon_prop->at("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value = weapon.attached; - weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue = weapon.damageType; + switch(weapon.damageType) { + #define c(enumerator, strenum) case DamageType::enumerator: weapon_prop->at("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue = strenum; break; + #include "../Maps/DamageTypes.hpp" + #undef c + default: + Utility::Warning{} << "Invalid damage type enum value in writeWeaponType()."; + } weapon_prop->at("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value = weapon.dualWield; weapon_prop->at("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = weapon.effectColourMode; auto effect_colour = weapon_prop->at("ColorEfx_26_D921B62946C493E487455A831F4520AC"); diff --git a/src/Mass/Weapon.h b/src/Mass/Weapon.h index ee7eddd..25785b4 100644 --- a/src/Mass/Weapon.h +++ b/src/Mass/Weapon.h @@ -39,6 +39,15 @@ enum class WeaponType { EnergyLauncher = 4, }; +enum class DamageType { + Physical = 0, + Piercing = 1, + Plasma = 5, + Heat = 2, + Freeze = 3, + Shock = 4, +}; + struct Weapon { Weapon() = default; @@ -54,7 +63,7 @@ struct Weapon { Containers::Array parts; Containers::StaticArray<16, CustomStyle> customStyles{ValueInit}; bool attached = false; - std::string damageType; + DamageType damageType = DamageType::Physical; bool dualWield = false; std::string effectColourMode; Color4 effectColour{0.0f}; diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index 0b4fb8f..ffaa054 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -911,31 +911,31 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { if(weapon.type != WeaponType::Shield) { if(weapon.type == WeaponType::Melee && - ImGui::RadioButton("Physical##NoElement", weapon.damageType == "enuDamageProperty::NewEnumerator0")) + ImGui::RadioButton("Physical##NoElement", weapon.damageType == DamageType::Physical)) { - weapon.damageType = "enuDamageProperty::NewEnumerator0"; + weapon.damageType = DamageType::Physical; } else if((weapon.type == WeaponType::BulletShooter || weapon.type == WeaponType::BulletLauncher) && - ImGui::RadioButton("Piercing##NoElement", weapon.damageType == "enuDamageProperty::NewEnumerator1")) + ImGui::RadioButton("Piercing##NoElement", weapon.damageType == DamageType::Piercing)) { - weapon.damageType = "enuDamageProperty::NewEnumerator1"; + weapon.damageType = DamageType::Piercing; } else if((weapon.type == WeaponType::EnergyShooter || weapon.type == WeaponType::EnergyLauncher) && - ImGui::RadioButton("Plasma##NoElement", weapon.damageType == "enuDamageProperty::NewEnumerator5")) + ImGui::RadioButton("Plasma##NoElement", weapon.damageType == DamageType::Plasma)) { - weapon.damageType = "enuDamageProperty::NewEnumerator5"; + weapon.damageType = DamageType::Plasma; } ImGui::SameLine(); - if(ImGui::RadioButton("Heat##Heat", weapon.damageType == "enuDamageProperty::NewEnumerator2")) { - weapon.damageType = "enuDamageProperty::NewEnumerator2"; + if(ImGui::RadioButton("Heat##Heat", weapon.damageType == DamageType::Heat)) { + weapon.damageType = DamageType::Heat; } ImGui::SameLine(); - if(ImGui::RadioButton("Freeze##Freeze", weapon.damageType == "enuDamageProperty::NewEnumerator3")) { - weapon.damageType = "enuDamageProperty::NewEnumerator3"; + if(ImGui::RadioButton("Freeze##Freeze", weapon.damageType == DamageType::Freeze)) { + weapon.damageType = DamageType::Freeze; } ImGui::SameLine(); - if(ImGui::RadioButton("Shock##Shock", weapon.damageType == "enuDamageProperty::NewEnumerator4")) { - weapon.damageType = "enuDamageProperty::NewEnumerator4"; + if(ImGui::RadioButton("Shock##Shock", weapon.damageType == DamageType::Freeze)) { + weapon.damageType = DamageType::Freeze; } }