Mass: improve logging.

This commit is contained in:
Guillaume Jacquemin 2022-03-30 19:51:00 +02:00
parent 677bf21c9f
commit 718a6fd754
6 changed files with 51 additions and 0 deletions

View file

@ -18,6 +18,7 @@
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Pair.h> #include <Corrade/Containers/Pair.h>
#include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Utility/Path.h> #include <Corrade/Utility/Path.h>
#include "../UESaveFile/Types/ArrayProperty.h" #include "../UESaveFile/Types/ArrayProperty.h"
@ -79,7 +80,12 @@ auto Mass::getNameFromFile(Containers::StringView path) -> Containers::Optional<
} }
void Mass::refreshValues() { void Mass::refreshValues() {
Utility::Debug{} << "=Refreshing values for" << _filename << Utility::Debug::nospace << "=";
Containers::ScopeGuard guard{[]{ Utility::Error{} << "Refresh failed."; }};
if(!Utility::Path::exists(Utility::Path::join(_folder, _filename))) { if(!Utility::Path::exists(Utility::Path::join(_folder, _filename))) {
Utility::Warning{} << _filename << "does not exist in" << _folder;
_state = State::Empty; _state = State::Empty;
return; return;
} }
@ -87,12 +93,14 @@ void Mass::refreshValues() {
if(!_mass) { if(!_mass) {
_mass.emplace(Utility::Path::join(_folder, _filename)); _mass.emplace(Utility::Path::join(_folder, _filename));
if(!_mass->valid()) { if(!_mass->valid()) {
Utility::Error{} << _mass->lastError();
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
} }
else { else {
if(!_mass->reloadData()) { if(!_mass->reloadData()) {
Utility::Error{} << _mass->lastError();
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -100,6 +108,7 @@ void Mass::refreshValues() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Couldn't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -107,6 +116,7 @@ void Mass::refreshValues() {
auto name_prop = unit_data->at<StringProperty>("Name_45_A037C5D54E53456407BDF091344529BB"_s); auto name_prop = unit_data->at<StringProperty>("Name_45_A037C5D54E53456407BDF091344529BB"_s);
if(!name_prop) { if(!name_prop) {
Utility::Error{} << "Couldn't find a M.A.S.S. name in" << _filename;
_name = Containers::NullOpt; _name = Containers::NullOpt;
_state = State::Invalid; _state = State::Invalid;
return; return;
@ -191,12 +201,16 @@ void Mass::refreshValues() {
auto account_prop = _mass->at<StringProperty>("Account"_s); auto account_prop = _mass->at<StringProperty>("Account"_s);
if(!account_prop) { if(!account_prop) {
Utility::Error{} << "Couldn't find an account ID in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
_account = account_prop->value; _account = account_prop->value;
guard.release();
guard = Containers::ScopeGuard{[]{Utility::Debug{} << "Refresh successful.";}};
_state = State::Valid; _state = State::Valid;
} }
@ -317,6 +331,7 @@ void Mass::getTuningCategory(Containers::StringView big_node_prop_name, Int& big
{ {
auto node_id = _mass->at<IntProperty>(big_node_prop_name); auto node_id = _mass->at<IntProperty>(big_node_prop_name);
if(!node_id) { if(!node_id) {
Utility::Error{} << "Couldn't find" << big_node_prop_name << "in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -324,11 +339,13 @@ void Mass::getTuningCategory(Containers::StringView big_node_prop_name, Int& big
auto node_ids = _mass->at<ArrayProperty>(small_nodes_prop_name); auto node_ids = _mass->at<ArrayProperty>(small_nodes_prop_name);
if(!node_ids) { if(!node_ids) {
Utility::Error{} << "Couldn't find" << small_nodes_prop_name << "in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(node_ids->items.size() != small_nodes_ids.size()) { if(node_ids->items.size() != small_nodes_ids.size()) {
Utility::Error{} << "Node ID arrays are not of the same size. Expected" << small_nodes_ids.size() << Utility::Debug::nospace << ", got" << node_ids->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }

View file

@ -34,17 +34,20 @@ auto Mass::armourParts() -> Containers::ArrayView<ArmourPart> {
void Mass::getArmourParts() { void Mass::getArmourParts() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Couldn't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto armour_array = unit_data->at<ArrayProperty>("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"_s); auto armour_array = unit_data->at<ArrayProperty>("Armor_10_12E266C44116DDAF57E99ABB575A4B3C"_s);
if(!armour_array) { if(!armour_array) {
Utility::Error{} << "Couldn't find the armour parts array in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(armour_array->items.size() != _armour.parts.size()) { if(armour_array->items.size() != _armour.parts.size()) {
Utility::Error{} << "Armour arrays are not of the same size. Expected" << _armour.parts.size() << Utility::Debug::nospace << ", got" << armour_array->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -66,11 +69,13 @@ void Mass::getArmourParts() {
auto part_styles = part_prop->at<ArrayProperty>("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"_s); auto part_styles = part_prop->at<ArrayProperty>("Styles_47_3E31870441DFD7DB8BEE5C85C26B365B"_s);
if(!part_styles) { if(!part_styles) {
Utility::Error{} << "Part styles not found for part number" << i << "in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(part_styles->items.size() != part.styles.size()) { if(part_styles->items.size() != part.styles.size()) {
Utility::Error{} << "Part style arrays are not of the same size. Expected" << part.styles.size() << Utility::Debug::nospace << ", got" << part_styles->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -81,6 +86,7 @@ void Mass::getArmourParts() {
auto decals_array = part_prop->at<ArrayProperty>("Decals_42_F358794A4F18497970F56BA9627D3603"_s); auto decals_array = part_prop->at<ArrayProperty>("Decals_42_F358794A4F18497970F56BA9627D3603"_s);
if(!decals_array) { if(!decals_array) {
Utility::Error{} << "Part decals not found for part number" << i << "in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -91,6 +97,7 @@ void Mass::getArmourParts() {
auto accs_array = part_prop->at<ArrayProperty>("Accessories_52_D902DD4241FA0050C2529596255153F3"_s); auto accs_array = part_prop->at<ArrayProperty>("Accessories_52_D902DD4241FA0050C2529596255153F3"_s);
if(!accs_array) { if(!accs_array) {
Utility::Error{} << "Part accessories not found for part number" << i << "in" << _filename;
part.accessories = Containers::Array<Accessory>{}; part.accessories = Containers::Array<Accessory>{};
continue; continue;
} }
@ -174,6 +181,7 @@ auto Mass::bulletLauncherAttachments() -> Containers::ArrayView<BulletLauncherAt
void Mass::getBulletLauncherAttachments() { void Mass::getBulletLauncherAttachments() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Couldn't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -188,6 +196,7 @@ void Mass::getBulletLauncherAttachments() {
if(attach_style_prop && !attach_array) { if(attach_style_prop && !attach_array) {
_armour.blAttachmentStyle = BulletLauncherAttachmentStyle::NotFound; _armour.blAttachmentStyle = BulletLauncherAttachmentStyle::NotFound;
Utility::Error{} << "Couldn't find bullet launcher attachments in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -335,17 +344,20 @@ auto Mass::armourCustomStyles() -> Containers::ArrayView<CustomStyle> {
void Mass::getArmourCustomStyles() { void Mass::getArmourCustomStyles() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Couldn't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto armour_styles = unit_data->at<ArrayProperty>("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"_s); auto armour_styles = unit_data->at<ArrayProperty>("ArmorStyle_42_E2F6AC3647788CB366BD469B3B7E899E"_s);
if(!armour_styles) { if(!armour_styles) {
Utility::Error{} << "Couldn't find custom armour styles in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(armour_styles->items.size() != _armour.customStyles.size()) { if(armour_styles->items.size() != _armour.customStyles.size()) {
Utility::Error{} << "Custom armour style arrays are not of the same size. Expected" << _armour.customStyles.size() << Utility::Debug::nospace << ", got" << armour_styles->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }

View file

@ -31,6 +31,7 @@ using namespace Containers::Literals;
void Mass::getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) { void Mass::getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) {
for(UnsignedInt i = 0; i < decal_array->items.size(); i++) { for(UnsignedInt i = 0; i < decal_array->items.size(); i++) {
auto decal_prop = decal_array->at<GenericStructProperty>(i); auto decal_prop = decal_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(decal_prop);
auto& decal = decals[i]; auto& decal = decals[i];
decal.id = decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value; decal.id = decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value;
@ -54,6 +55,7 @@ void Mass::getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_a
void Mass::writeDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) { void Mass::writeDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) {
for(UnsignedInt i = 0; i < decal_array->items.size(); i++) { for(UnsignedInt i = 0; i < decal_array->items.size(); i++) {
auto decal_prop = decal_array->at<GenericStructProperty>(i); auto decal_prop = decal_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(decal_prop);
auto& decal = decals[i]; auto& decal = decals[i];
decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value = decal.id; decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9"_s)->value = decal.id;
@ -87,6 +89,7 @@ void Mass::writeDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal
void Mass::getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array) { void Mass::getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array) {
for(UnsignedInt i = 0; i < accessory_array->items.size(); i++) { for(UnsignedInt i = 0; i < accessory_array->items.size(); i++) {
auto acc_prop = accessory_array->at<GenericStructProperty>(i); auto acc_prop = accessory_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(acc_prop);
auto& accessory = accessories[i]; auto& accessory = accessories[i];
accessory.attachIndex = acc_prop->at<IntProperty>("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value; accessory.attachIndex = acc_prop->at<IntProperty>("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value;
@ -111,6 +114,7 @@ void Mass::getAccessories(Containers::ArrayView<Accessory> accessories, ArrayPro
void Mass::writeAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accs_array) { void Mass::writeAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accs_array) {
for(UnsignedInt i = 0; i < accs_array->items.size(); i++) { for(UnsignedInt i = 0; i < accs_array->items.size(); i++) {
auto acc_prop = accs_array->at<GenericStructProperty>(i); auto acc_prop = accs_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(acc_prop);
auto& accessory = accessories[i]; auto& accessory = accessories[i];
acc_prop->at<IntProperty>("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value = accessory.attachIndex; acc_prop->at<IntProperty>("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value = accessory.attachIndex;

View file

@ -31,12 +31,14 @@ auto Mass::jointSliders() -> Joints& {
void Mass::getJointSliders() { void Mass::getJointSliders() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
if(!frame_prop) { if(!frame_prop) {
Utility::Error{} << "Can't find frame data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -179,23 +181,27 @@ auto Mass::frameStyles() -> Containers::ArrayView<Int> {
void Mass::getFrameStyles() { void Mass::getFrameStyles() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
if(!frame_prop) { if(!frame_prop) {
Utility::Error{} << "Can't find frame data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto frame_styles = frame_prop->at<ArrayProperty>("Styles_32_00A3B3284B37F1E7819458844A20EB48"_s); auto frame_styles = frame_prop->at<ArrayProperty>("Styles_32_00A3B3284B37F1E7819458844A20EB48"_s);
if(!frame_styles) { if(!frame_styles) {
Utility::Error{} << "Can't find frame styles in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(frame_styles->items.size() != _frame.styles.size()) { if(frame_styles->items.size() != _frame.styles.size()) {
Utility::Error{} << "Frame style arrays are not of the same size. Expected" << _frame.styles.size() << Utility::Debug::nospace << ", got" << frame_styles->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -246,18 +252,21 @@ auto Mass::eyeFlareColour() -> Color4& {
void Mass::getEyeFlareColour() { void Mass::getEyeFlareColour() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s); auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
if(!frame_prop) { if(!frame_prop) {
Utility::Error{} << "Can't find frame data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto eye_flare_prop = frame_prop->at<ColourStructProperty>("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"_s); auto eye_flare_prop = frame_prop->at<ColourStructProperty>("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"_s);
if(!eye_flare_prop) { if(!eye_flare_prop) {
Utility::Error{} << "Can't find eye flare data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -307,17 +316,20 @@ auto Mass::frameCustomStyles() -> Containers::ArrayView<CustomStyle> {
void Mass::getFrameCustomStyles() { void Mass::getFrameCustomStyles() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto frame_styles = unit_data->at<ArrayProperty>("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"_s); auto frame_styles = unit_data->at<ArrayProperty>("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"_s);
if(!frame_styles) { if(!frame_styles) {
Utility::Error{} << "Can't find frame styles in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(frame_styles->items.size() != _frame.customStyles.size()) { if(frame_styles->items.size() != _frame.customStyles.size()) {
Utility::Error{} << "Frame custom style arrays are not of the same size. Expected" << _frame.customStyles.size() << Utility::Debug::nospace << ", got" << frame_styles->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }

View file

@ -32,6 +32,7 @@ auto Mass::globalStyles() -> Containers::ArrayView<CustomStyle> {
void Mass::getGlobalStyles() { void Mass::getGlobalStyles() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }

View file

@ -101,17 +101,20 @@ auto Mass::writeEnergyLaunchers() -> bool {
void Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) { void Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s); auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) { if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
auto prop = unit_data->at<ArrayProperty>(prop_name); auto prop = unit_data->at<ArrayProperty>(prop_name);
if(!prop) { if(!prop) {
Utility::Error{} << "Can't find" << prop_name << "in" << _filename;
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
if(prop->items.size() != weapon_array.size()) { if(prop->items.size() != weapon_array.size()) {
Utility::Error{} << "Weapon arrays are not of the same size. Expected" << weapon_array.size() << Utility::Debug::nospace << ", got" << prop->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }
@ -165,11 +168,13 @@ void Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView
auto custom_styles = weapon_prop->at<ArrayProperty>("Styles_10_8C3C82444B986AD7A99595AD4985912D"_s); auto custom_styles = weapon_prop->at<ArrayProperty>("Styles_10_8C3C82444B986AD7A99595AD4985912D"_s);
if(!custom_styles) { if(!custom_styles) {
Utility::Error{} << "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()) {
Utility::Error{} << "Weapon custom style arrays are not of the same size. Expected" << weapon.customStyles.size() << Utility::Debug::nospace << ", got" << custom_styles->items.size() << "instead.";
_state = State::Invalid; _state = State::Invalid;
return; return;
} }