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