Compare commits

...

4 commits

Author SHA1 Message Date
5705f408a5 MassManager: this piece of code is in SaveTool.
Why the Hell is it still here ?
2022-03-30 20:35:04 +02:00
4ed7aff835 MassManager: change how hangars are handled. 2022-03-30 20:34:37 +02:00
718a6fd754 Mass: improve logging. 2022-03-30 19:51:00 +02:00
677bf21c9f Mass: slight formatting update.
Seriously, how did this slip through the cracks ?
2022-03-30 19:46:09 +02:00
8 changed files with 57 additions and 12 deletions

View file

@ -18,6 +18,7 @@
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Pair.h>
#include <Corrade/Containers/ScopeGuard.h>
#include <Corrade/Utility/Path.h>
#include "../UESaveFile/Types/ArrayProperty.h"
@ -79,7 +80,12 @@ auto Mass::getNameFromFile(Containers::StringView path) -> Containers::Optional<
}
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))) {
Utility::Warning{} << _filename << "does not exist in" << _folder;
_state = State::Empty;
return;
}
@ -87,12 +93,14 @@ void Mass::refreshValues() {
if(!_mass) {
_mass.emplace(Utility::Path::join(_folder, _filename));
if(!_mass->valid()) {
Utility::Error{} << _mass->lastError();
_state = State::Invalid;
return;
}
}
else {
if(!_mass->reloadData()) {
Utility::Error{} << _mass->lastError();
_state = State::Invalid;
return;
}
@ -100,6 +108,7 @@ void Mass::refreshValues() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) {
Utility::Error{} << "Couldn't find unit data in" << _filename;
_state = State::Invalid;
return;
}
@ -107,6 +116,7 @@ void Mass::refreshValues() {
auto name_prop = unit_data->at<StringProperty>("Name_45_A037C5D54E53456407BDF091344529BB"_s);
if(!name_prop) {
Utility::Error{} << "Couldn't find a M.A.S.S. name in" << _filename;
_name = Containers::NullOpt;
_state = State::Invalid;
return;
@ -191,12 +201,16 @@ void Mass::refreshValues() {
auto account_prop = _mass->at<StringProperty>("Account"_s);
if(!account_prop) {
Utility::Error{} << "Couldn't find an account ID in" << _filename;
_state = State::Invalid;
return;
}
_account = account_prop->value;
guard.release();
guard = Containers::ScopeGuard{[]{Utility::Debug{} << "Refresh successful.";}};
_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);
if(!node_id) {
Utility::Error{} << "Couldn't find" << big_node_prop_name << "in" << _filename;
_state = State::Invalid;
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);
if(!node_ids) {
Utility::Error{} << "Couldn't find" << small_nodes_prop_name << "in" << _filename;
_state = State::Invalid;
return;
}
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;
return;
}

View file

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

View file

@ -31,6 +31,7 @@ using namespace Containers::Literals;
void Mass::getDecals(Containers::ArrayView<Decal> decals, ArrayProperty* decal_array) {
for(UnsignedInt i = 0; i < decal_array->items.size(); i++) {
auto decal_prop = decal_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(decal_prop);
auto& decal = decals[i];
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) {
for(UnsignedInt i = 0; i < decal_array->items.size(); i++) {
auto decal_prop = decal_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(decal_prop);
auto& decal = decals[i];
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) {
for(UnsignedInt i = 0; i < accessory_array->items.size(); i++) {
auto acc_prop = accessory_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(acc_prop);
auto& accessory = accessories[i];
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) {
for(UnsignedInt i = 0; i < accs_array->items.size(); i++) {
auto acc_prop = accs_array->at<GenericStructProperty>(i);
CORRADE_INTERNAL_ASSERT(acc_prop);
auto& accessory = accessories[i];
acc_prop->at<IntProperty>("AttachIndex_2_4AFCF6024E4BA7426C6B9F80B8179D20"_s)->value = accessory.attachIndex;

View file

@ -31,12 +31,14 @@ auto Mass::jointSliders() -> Joints& {
void Mass::getJointSliders() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid;
return;
}
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
if(!frame_prop) {
Utility::Error{} << "Can't find frame data in" << _filename;
_state = State::Invalid;
return;
}
@ -179,23 +181,27 @@ auto Mass::frameStyles() -> Containers::ArrayView<Int> {
void Mass::getFrameStyles() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid;
return;
}
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
if(!frame_prop) {
Utility::Error{} << "Can't find frame data in" << _filename;
_state = State::Invalid;
return;
}
auto frame_styles = frame_prop->at<ArrayProperty>("Styles_32_00A3B3284B37F1E7819458844A20EB48"_s);
if(!frame_styles) {
Utility::Error{} << "Can't find frame styles in" << _filename;
_state = State::Invalid;
return;
}
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;
return;
}
@ -246,18 +252,21 @@ auto Mass::eyeFlareColour() -> Color4& {
void Mass::getEyeFlareColour() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid;
return;
}
auto frame_prop = unit_data->at<GenericStructProperty>("Frame_3_F92B0F6A44A15088AF7F41B9FF290653"_s);
if(!frame_prop) {
Utility::Error{} << "Can't find frame data in" << _filename;
_state = State::Invalid;
return;
}
auto eye_flare_prop = frame_prop->at<ColourStructProperty>("EyeFlareColor_36_AF79999C40FCA0E88A2F9A84488A38CA"_s);
if(!eye_flare_prop) {
Utility::Error{} << "Can't find eye flare data in" << _filename;
_state = State::Invalid;
return;
}
@ -307,17 +316,20 @@ auto Mass::frameCustomStyles() -> Containers::ArrayView<CustomStyle> {
void Mass::getFrameCustomStyles() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid;
return;
}
auto frame_styles = unit_data->at<ArrayProperty>("FrameStyle_44_04A44C9440363CCEC5443D98BFAF22AA"_s);
if(!frame_styles) {
Utility::Error{} << "Can't find frame styles in" << _filename;
_state = State::Invalid;
return;
}
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;
return;
}

View file

@ -32,6 +32,7 @@ auto Mass::globalStyles() -> Containers::ArrayView<CustomStyle> {
void Mass::getGlobalStyles() {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid;
return;
}
@ -87,8 +88,8 @@ void Mass::getCustomStyles(Containers::ArrayView<CustomStyle> styles, ArrayPrope
style.patternId = style_prop->at<IntProperty>("PatternID_14_516DB85641DAF8ECFD2920BE2BDF1311"_s)->value;
style.opacity = style_prop->at<FloatProperty>("Opacity_30_53BD060B4DFCA1C92302D6A0F7831131"_s)->value;
style.offset = Vector2{
style_prop->at<FloatProperty>("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48"_s)->value,
style_prop->at<FloatProperty>("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F"_s)->value
style_prop->at<FloatProperty>("OffsetX_23_70FC2E814C64BBB82452748D2AF9CD48"_s)->value,
style_prop->at<FloatProperty>("OffsetY_24_5E1F866C4C054D9B2EE337ADC180C17F"_s)->value
};
style.rotation = style_prop->at<FloatProperty>("Rotation_25_EC2DFAD84AD0A6BD3FA841ACD52EDD6D"_s)->value;
style.scale = style_prop->at<FloatProperty>("Scale_26_19DF0708409262183E1247B317137671"_s)->value;

View file

@ -101,17 +101,20 @@ auto Mass::writeEnergyLaunchers() -> bool {
void Mass::getWeaponType(Containers::StringView prop_name, Containers::ArrayView<Weapon> weapon_array) {
auto unit_data = _mass->at<GenericStructProperty>("UnitData"_s);
if(!unit_data) {
Utility::Error{} << "Can't find unit data in" << _filename;
_state = State::Invalid;
return;
}
auto prop = unit_data->at<ArrayProperty>(prop_name);
if(!prop) {
Utility::Error{} << "Can't find" << prop_name << "in" << _filename;
_state = State::Invalid;
return;
}
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;
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);
if(!custom_styles) {
Utility::Error{} << "Can't find weapon custom styles in" << _filename;
_state = State::Invalid;
return;
}
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;
return;
}

View file

@ -29,16 +29,10 @@ MassManager::MassManager(Containers::StringView save_path, Containers::StringVie
_demo{demo},
_stagingAreaDirectory{staging_dir}
{
Containers::arrayReserve(_hangars, 32);
Containers::String mass_filename = "";
for(int i = 0; i < 32; i++) {
for(UnsignedInt i = 0; i < _hangars.size(); i++) {
mass_filename = Utility::Path::join(_saveDirectory, Utility::format("{}Unit{:.2d}{}.sav", demo ? "Demo"_s : ""_s, i, _account));
Containers::arrayAppend(_hangars, Mass{mass_filename});
}
if(!Utility::Path::exists(_stagingAreaDirectory)) {
Utility::Path::make(_stagingAreaDirectory);
new(&_hangars[i]) Mass{mass_filename};
}
refreshStagedMasses();

View file

@ -18,7 +18,7 @@
#include <map>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/StringView.h>
@ -53,7 +53,7 @@ class MassManager {
Containers::String _lastError;
Containers::Array<Mass> _hangars;
Containers::StaticArray<32, Mass> _hangars{NoInit};
Containers::StringView _stagingAreaDirectory;