Weapon,Mass,SaveTool: refactor some more code.

This commit is contained in:
Guillaume Jacquemin 2022-02-09 14:17:05 +01:00
parent 9f324c30fd
commit 28db82c8a9
5 changed files with 63 additions and 16 deletions

View file

@ -137,6 +137,7 @@ add_executable(MassBuilderSaveTool WIN32
Maps/Accessories.h Maps/Accessories.h
Maps/ArmourSets.h Maps/ArmourSets.h
Maps/ArmourSlots.h Maps/ArmourSlots.h
Maps/DamageTypes.hpp
Maps/LastMissionId.h Maps/LastMissionId.h
Maps/StoryProgress.h Maps/StoryProgress.h
Maps/StyleNames.h Maps/StyleNames.h

24
src/Maps/DamageTypes.hpp Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
#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

View file

@ -1063,7 +1063,7 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView<Weapon> we
auto& weapon = weapon_array[i]; auto& weapon = weapon_array[i];
weapon.name = weapon_prop->at<StringProperty>("Name_13_7BF0D31F4E50C50C47231BB36A485D92")->value; weapon.name = weapon_prop->at<StringProperty>("Name_13_7BF0D31F4E50C50C47231BB36A485D92")->value;
std::string& weapon_type = weapon_prop->at<ByteProperty>("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue; auto& weapon_type = weapon_prop->at<ByteProperty>("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue;
#define c(enumerator, strenum, name) if(weapon_type == (strenum)) { weapon.type = WeaponType::enumerator; } else #define c(enumerator, strenum, name) if(weapon_type == (strenum)) { weapon.type = WeaponType::enumerator; } else
#include "../Maps/WeaponTypes.hpp" #include "../Maps/WeaponTypes.hpp"
#undef c #undef c
@ -1124,7 +1124,14 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView<Weapon> we
getCustomStyles(weapon.customStyles, custom_styles); getCustomStyles(weapon.customStyles, custom_styles);
weapon.attached = weapon_prop->at<BoolProperty>("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value; weapon.attached = weapon_prop->at<BoolProperty>("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value;
weapon.damageType = weapon_prop->at<ByteProperty>("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue; auto& damage_type = weapon_prop->at<ByteProperty>("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<BoolProperty>("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value; weapon.dualWield = weapon_prop->at<BoolProperty>("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value;
weapon.effectColourMode = weapon_prop->at<ByteProperty>("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue; weapon.effectColourMode = weapon_prop->at<ByteProperty>("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue;
auto effect_colour = weapon_prop->at<ColourStructProperty>("ColorEfx_26_D921B62946C493E487455A831F4520AC"); auto effect_colour = weapon_prop->at<ColourStructProperty>("ColorEfx_26_D921B62946C493E487455A831F4520AC");
@ -1244,7 +1251,13 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView<Weapon>
} }
weapon_prop->at<BoolProperty>("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value = weapon.attached; weapon_prop->at<BoolProperty>("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value = weapon.attached;
weapon_prop->at<ByteProperty>("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue = weapon.damageType; switch(weapon.damageType) {
#define c(enumerator, strenum) case DamageType::enumerator: weapon_prop->at<ByteProperty>("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<BoolProperty>("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value = weapon.dualWield; weapon_prop->at<BoolProperty>("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value = weapon.dualWield;
weapon_prop->at<ByteProperty>("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = weapon.effectColourMode; weapon_prop->at<ByteProperty>("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = weapon.effectColourMode;
auto effect_colour = weapon_prop->at<ColourStructProperty>("ColorEfx_26_D921B62946C493E487455A831F4520AC"); auto effect_colour = weapon_prop->at<ColourStructProperty>("ColorEfx_26_D921B62946C493E487455A831F4520AC");

View file

@ -39,6 +39,15 @@ enum class WeaponType {
EnergyLauncher = 4, EnergyLauncher = 4,
}; };
enum class DamageType {
Physical = 0,
Piercing = 1,
Plasma = 5,
Heat = 2,
Freeze = 3,
Shock = 4,
};
struct Weapon { struct Weapon {
Weapon() = default; Weapon() = default;
@ -54,7 +63,7 @@ struct Weapon {
Containers::Array<WeaponPart> parts; Containers::Array<WeaponPart> parts;
Containers::StaticArray<16, CustomStyle> customStyles{ValueInit}; Containers::StaticArray<16, CustomStyle> customStyles{ValueInit};
bool attached = false; bool attached = false;
std::string damageType; DamageType damageType = DamageType::Physical;
bool dualWield = false; bool dualWield = false;
std::string effectColourMode; std::string effectColourMode;
Color4 effectColour{0.0f}; Color4 effectColour{0.0f};

View file

@ -911,31 +911,31 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) {
if(weapon.type != WeaponType::Shield) { if(weapon.type != WeaponType::Shield) {
if(weapon.type == WeaponType::Melee && 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) && 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) && 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(); ImGui::SameLine();
if(ImGui::RadioButton("Heat##Heat", weapon.damageType == "enuDamageProperty::NewEnumerator2")) { if(ImGui::RadioButton("Heat##Heat", weapon.damageType == DamageType::Heat)) {
weapon.damageType = "enuDamageProperty::NewEnumerator2"; weapon.damageType = DamageType::Heat;
} }
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::RadioButton("Freeze##Freeze", weapon.damageType == "enuDamageProperty::NewEnumerator3")) { if(ImGui::RadioButton("Freeze##Freeze", weapon.damageType == DamageType::Freeze)) {
weapon.damageType = "enuDamageProperty::NewEnumerator3"; weapon.damageType = DamageType::Freeze;
} }
ImGui::SameLine(); ImGui::SameLine();
if(ImGui::RadioButton("Shock##Shock", weapon.damageType == "enuDamageProperty::NewEnumerator4")) { if(ImGui::RadioButton("Shock##Shock", weapon.damageType == DamageType::Freeze)) {
weapon.damageType = "enuDamageProperty::NewEnumerator4"; weapon.damageType = DamageType::Freeze;
} }
} }