GameObjects: improve Mass error reporting.

This commit is contained in:
Guillaume Jacquemin 2024-12-06 20:15:33 +01:00
parent a35cddfc0c
commit 9e627f5100
Signed by: williamjcm
SSH key fingerprint: SHA256:AYLOg+iTV0ElElnlu4vqM4edFazVdRiuQB0Y5LoKc4A

View file

@ -136,21 +136,21 @@ void
Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) { Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) {
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA); auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
if(!unit_data) { if(!unit_data) {
LOG_ERROR_FORMAT("Couldn't find {} in {}.", MASS_UNIT_DATA, _filename); LOG_ERROR(_lastError = Utility::format("Couldn't find {} in {}.", MASS_UNIT_DATA, _filename));
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto prop = unit_data->at<Gvas::Types::ArrayProperty>(prop_name); auto prop = unit_data->at<Gvas::Types::ArrayProperty>(prop_name);
if(!prop) { if(!prop) {
LOG_ERROR_FORMAT("Couldn't find {} in {}.", prop_name, _filename); LOG_ERROR(_lastError = Utility::format("Couldn't find {} in {}.", prop_name, _filename));
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(prop->items.size() != weapon_array.size()) { if(prop->items.size() != weapon_array.size()) {
LOG_ERROR_FORMAT("Weapon arrays are not of the same size. Expected {}, got {} instead.", LOG_ERROR(_lastError = Utility::format("Weapon arrays are not of the same size. Expected {}, got {} instead.",
weapon_array.size(), prop->items.size()); weapon_array.size(), prop->items.size()));
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -165,7 +165,7 @@ Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weap
#include "../Maps/WeaponTypes.hpp" #include "../Maps/WeaponTypes.hpp"
#undef c #undef c
{ {
LOG_ERROR_FORMAT("Invalid weapon type {} in {}.", weapon_type, _filename); LOG_ERROR(_lastError = Utility::format("Invalid weapon type {} in {}.", weapon_type, _filename));
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -205,19 +205,24 @@ Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weap
auto custom_styles = weapon_prop->at<Gvas::Types::ArrayProperty>(MASS_CUSTOM_WEAPON_STYLES); auto custom_styles = weapon_prop->at<Gvas::Types::ArrayProperty>(MASS_CUSTOM_WEAPON_STYLES);
if(!custom_styles) { if(!custom_styles) {
LOG_ERROR_FORMAT("Can't find weapon custom styles in {}", _filename); LOG_ERROR(_lastError = Utility::format("Can't find weapon custom styles in {}", _filename));
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(custom_styles->items.size() != weapon.customStyles.size()) { if(custom_styles->items.size() != weapon.customStyles.size()) {
LOG_ERROR_FORMAT("Custom weapon style arrays are not of the same size. Expected {}, got {} instead.", _lastError = Utility::format("Custom weapon style arrays are not of the same size. Expected {}, got {} instead.",
weapon.customStyles.size(), custom_styles->items.size()); weapon.customStyles.size(), custom_styles->items.size());
if(!weapon.parts.isEmpty()) {
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
LOG_WARNING(_lastError);
}
else {
getCustomStyles(weapon.customStyles, custom_styles); getCustomStyles(weapon.customStyles, custom_styles);
}
for(auto& style : weapon.customStyles) { for(auto& style : weapon.customStyles) {
style.type = CustomStyle::Type::Weapon; style.type = CustomStyle::Type::Weapon;
@ -229,7 +234,7 @@ Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weap
#include "../Maps/DamageTypes.hpp" #include "../Maps/DamageTypes.hpp"
#undef c #undef c
{ {
LOG_ERROR_FORMAT("Invalid damage type {} in {}.", damage_type, _filename); LOG_ERROR(_lastError = Utility::format("Invalid damage type {} in {}.", damage_type, _filename));
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -239,7 +244,7 @@ Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weap
#include "../Maps/EffectColourModes.hpp" #include "../Maps/EffectColourModes.hpp"
#undef c #undef c
{ {
LOG_ERROR_FORMAT("Invalid effect colour mode {} in {}.", effect_colour_mode, _filename); LOG_ERROR(_lastError = Utility::format("Invalid effect colour mode {} in {}.", effect_colour_mode, _filename));
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -252,24 +257,21 @@ bool
Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) { Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) {
auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA); auto unit_data = _mass->at<Gvas::Types::GenericStructProperty>(MASS_UNIT_DATA);
if(!unit_data) { if(!unit_data) {
_lastError = "No unit data in "_s + _filename; LOG_ERROR(_lastError = Utility::format("No unit data in {}", _filename));
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return false; return false;
} }
auto prop = unit_data->at<Gvas::Types::ArrayProperty>(prop_name); auto prop = unit_data->at<Gvas::Types::ArrayProperty>(prop_name);
if(!prop) { if(!prop) {
_lastError = prop_name + " not found in "_s + _filename; LOG_ERROR(_lastError = Utility::format("Property {} not found in {}.", prop_name, _filename));
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return false; return false;
} }
if(prop->items.size() != weapon_array.size()) { if(prop->items.size() != weapon_array.size()) {
_lastError = Utility::format("Weapon arrays are not of the same size. Expected {}, got {} instead.", LOG_ERROR(_lastError = Utility::format("Weapon arrays are not of the same size. Expected {}, got {} instead.",
weapon_array.size(), prop->items.size()); weapon_array.size(), prop->items.size()));
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return false; return false;
} }
@ -284,16 +286,14 @@ Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<We
#include "../Maps/WeaponTypes.hpp" #include "../Maps/WeaponTypes.hpp"
#undef c #undef c
default: default:
_lastError = Utility::format("Invalid weapon type at index {}.", i); LOG_ERROR(_lastError = Utility::format("Invalid weapon type at index {}.", i));
LOG_ERROR(_lastError);
return false; return false;
} }
auto parts_prop = weapon_prop->at<Gvas::Types::ArrayProperty>(MASS_WEAPON_ELEMENT); auto parts_prop = weapon_prop->at<Gvas::Types::ArrayProperty>(MASS_WEAPON_ELEMENT);
if(parts_prop->items.size() != weapon.parts.size()) { if(parts_prop->items.size() != weapon.parts.size()) {
_lastError = Utility::format("Weapon part arrays are not of the same size. Expected {}, got {} instead.", LOG_ERROR(_lastError = Utility::format("Weapon part arrays are not of the same size. Expected {}, got {} instead.",
weapon.parts.size(), parts_prop->items.size()); weapon.parts.size(), parts_prop->items.size()));
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return false; return false;
} }
@ -318,9 +318,8 @@ Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<We
} }
if(part_accs->items.size() != part.accessories.size()) { if(part_accs->items.size() != part.accessories.size()) {
_lastError = Utility::format("Part accessory arrays are not of the same size. Expected {}, got {} instead.", LOG_ERROR(_lastError = Utility::format("Part accessory arrays are not of the same size. Expected {}, got {} instead.",
part.accessories.size(), part_accs->items.size()); part.accessories.size(), part_accs->items.size()));
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return false; return false;
} }
@ -330,16 +329,14 @@ Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<We
auto custom_styles = weapon_prop->at<Gvas::Types::ArrayProperty>(MASS_CUSTOM_WEAPON_STYLES); auto custom_styles = weapon_prop->at<Gvas::Types::ArrayProperty>(MASS_CUSTOM_WEAPON_STYLES);
if(!custom_styles) { if(!custom_styles) {
_lastError = "No custom styles found for weapon."_s; LOG_ERROR(_lastError = "No custom styles found for weapon."_s);
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return false; return false;
} }
if(custom_styles->items.size() != weapon.customStyles.size()) { if(custom_styles->items.size() != weapon.customStyles.size()) {
_lastError = Utility::format("Custom style arrays are not of the same size. Expected {}, got {} instead.", LOG_ERROR(_lastError = Utility::format("Custom style arrays are not of the same size. Expected {}, got {} instead.",
weapon.customStyles.size(), custom_styles->items.size()); weapon.customStyles.size(), custom_styles->items.size()));
LOG_ERROR(_lastError);
_state = State::Invalid; _state = State::Invalid;
return false; return false;
} }
@ -354,8 +351,7 @@ Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<We
#include "../Maps/DamageTypes.hpp" #include "../Maps/DamageTypes.hpp"
#undef c #undef c
default: default:
_lastError = Utility::format("Invalid damage type at index {}.", i); LOG_ERROR(_lastError = Utility::format("Invalid damage type at index {}.", i));
LOG_ERROR(_lastError);
return false; return false;
} }
weapon_prop->at<Gvas::Types::BoolProperty>(MASS_WEAPON_DUAL_WIELD)->value = weapon.dualWield; weapon_prop->at<Gvas::Types::BoolProperty>(MASS_WEAPON_DUAL_WIELD)->value = weapon.dualWield;
@ -366,8 +362,7 @@ Mass::writeWeaponType(Containers::StringView prop_name, Containers::ArrayView<We
#include "../Maps/EffectColourModes.hpp" #include "../Maps/EffectColourModes.hpp"
#undef c #undef c
default: default:
_lastError = Utility::format("Invalid damage type at index {}.", i); LOG_ERROR(_lastError = Utility::format("Invalid damage type at index {}.", i));
LOG_ERROR(_lastError);
return false; return false;
} }
auto effect_colour = weapon_prop->at<Gvas::Types::ColourStructProperty>(MASS_WEAPON_COLOUR_EFX); auto effect_colour = weapon_prop->at<Gvas::Types::ColourStructProperty>(MASS_WEAPON_COLOUR_EFX);