Mass: finish implementing the saving feature.

Oh, and also remove a blank line, but that's not important.
This commit is contained in:
Guillaume Jacquemin 2021-10-29 10:23:34 +02:00
parent af71806e13
commit 0900f92b9f
2 changed files with 144 additions and 1 deletions

View file

@ -652,7 +652,6 @@ auto Mass::writeArmourPart(UnsignedLong index) -> bool {
auto decals_array = part_prop->at<ArrayProperty>("Decals_42_F358794A4F18497970F56BA9627D3603"); auto decals_array = part_prop->at<ArrayProperty>("Decals_42_F358794A4F18497970F56BA9627D3603");
for(UnsignedInt i = 0; i < decals_array->items.size(); i++) { for(UnsignedInt i = 0; i < decals_array->items.size(); i++) {
auto decal_prop = decals_array->at<GenericStructProperty>(i); auto decal_prop = decals_array->at<GenericStructProperty>(i);
auto& decal = part.decals[i]; auto& decal = part.decals[i];
decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id; decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id;
@ -775,6 +774,10 @@ void Mass::getMeleeWeapons() {
getWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7", _weapons.melee); getWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7", _weapons.melee);
} }
auto Mass::writeMeleeWeapons() -> bool {
return writeWeaponType("WeaponCC_22_0BBEC58C4A0EA1DB9E037B9339EE26A7", _weapons.melee);
}
auto Mass::shields() -> Containers::ArrayView<Weapon> { auto Mass::shields() -> Containers::ArrayView<Weapon> {
return _weapons.shields; return _weapons.shields;
} }
@ -783,6 +786,10 @@ void Mass::getShields() {
getWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E", _weapons.shields); getWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E", _weapons.shields);
} }
auto Mass::writeShields() -> bool {
return writeWeaponType("Shield_53_839BFD7945481BAEA3E43A9C5CA8E92E", _weapons.shields);
}
auto Mass::bulletShooters() -> Containers::ArrayView<Weapon> { auto Mass::bulletShooters() -> Containers::ArrayView<Weapon> {
return _weapons.bulletShooters; return _weapons.bulletShooters;
} }
@ -791,6 +798,10 @@ void Mass::getBulletShooters() {
getWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED", _weapons.bulletShooters); getWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED", _weapons.bulletShooters);
} }
auto Mass::writeBulletShooters() -> bool {
return writeWeaponType("WeaponBS_35_6EF6E0104FD7A138DF47F88CB57A83ED", _weapons.bulletShooters);
}
auto Mass::energyShooters() -> Containers::ArrayView<Weapon> { auto Mass::energyShooters() -> Containers::ArrayView<Weapon> {
return _weapons.energyShooters; return _weapons.energyShooters;
} }
@ -799,6 +810,10 @@ void Mass::getEnergyShooters() {
getWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99", _weapons.energyShooters); getWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99", _weapons.energyShooters);
} }
auto Mass::writeEnergyShooters() -> bool {
return writeWeaponType("WeaponES_37_1A295D544528623880A0B1AC2C7DEE99", _weapons.energyShooters);
}
auto Mass::bulletLaunchers() -> Containers::ArrayView<Weapon> { auto Mass::bulletLaunchers() -> Containers::ArrayView<Weapon> {
return _weapons.bulletLaunchers; return _weapons.bulletLaunchers;
} }
@ -807,6 +822,10 @@ void Mass::getBulletLaunchers() {
getWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E", _weapons.bulletLaunchers); getWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E", _weapons.bulletLaunchers);
} }
auto Mass::writeBulletLaunchers() -> bool {
return writeWeaponType("WeaponBL_36_5FD7C41E4613A75B44AB0E90B362846E", _weapons.bulletLaunchers);
}
auto Mass::energyLaunchers() -> Containers::ArrayView<Weapon> { auto Mass::energyLaunchers() -> Containers::ArrayView<Weapon> {
return _weapons.energyLaunchers; return _weapons.energyLaunchers;
} }
@ -815,6 +834,10 @@ void Mass::getEnergyLaunchers() {
getWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995", _weapons.energyLaunchers); getWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995", _weapons.energyLaunchers);
} }
auto Mass::writeEnergyLaunchers() -> bool {
return writeWeaponType("WeaponEL_38_9D23F3884ACA15902C9E6CA6E4995995", _weapons.energyLaunchers);
}
auto Mass::globalStyles() -> Containers::ArrayView<CustomStyle> { auto Mass::globalStyles() -> Containers::ArrayView<CustomStyle> {
return _globalStyles; return _globalStyles;
} }
@ -1054,3 +1077,122 @@ void Mass::getWeaponType(const char* prop_name, Containers::ArrayView<Weapon> we
weapon.effectColour = Color4{effect_colour->r, effect_colour->g, effect_colour->b, effect_colour->a}; weapon.effectColour = Color4{effect_colour->r, effect_colour->g, effect_colour->b, effect_colour->a};
} }
} }
auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array) -> bool {
auto unit_data = _mass->at<GenericStructProperty>("UnitData");
if(!unit_data) {
_state = State::Invalid;
return false;
}
auto prop = unit_data->at<ArrayProperty>(prop_name);
if(!prop) {
_state = State::Invalid;
return false;
}
if(prop->items.size() != weapon_array.size()) {
_state = State::Invalid;
return false;
}
for(UnsignedInt i = 0; i < weapon_array.size(); i++) {
auto weapon_prop = prop->at<GenericStructProperty>(i);
auto& weapon = weapon_array[i];
weapon_prop->at<StringProperty>("Name_13_7BF0D31F4E50C50C47231BB36A485D92")->value = weapon.name;
weapon_prop->at<ByteProperty>("Type_2_35ABA8C3406F8D9BBF14A89CD6BCE976")->enumValue = weapon.type;
auto parts_prop = weapon_prop->at<ArrayProperty>("Element_6_8E4617CC4B2C1F1490435599784EC6E0");
if(parts_prop->items.size() != weapon_array.size()) {
_state = State::Invalid;
return false;
}
for(UnsignedInt j = 0; j < parts_prop->items.size(); j++) {
auto part_prop = parts_prop->at<GenericStructProperty>(j);
auto& part = weapon.parts[j];
part_prop->at<IntProperty>("ID_2_A74D75434308158E5926178822DD28EE")->value = part.id;
auto part_styles = part_prop->at<ArrayProperty>("Styles_17_994C97C34A90667BE5B716BFD0B97588");
for(UnsignedInt k = 0; k < part_styles->items.size(); k++) {
part_styles->at<IntProperty>(k)->value = part.styles[k];
}
auto part_decals = part_prop->at<ArrayProperty>("Decals_13_8B81112B453D7230C0CDE982185E14F1");
for(UnsignedInt k = 0; k < part_decals->items.size(); k++) {
auto decal_prop = part_decals->at<GenericStructProperty>(k);
auto& decal = part.decals[k];
decal_prop->at<IntProperty>("ID_3_694C0B35404D8A3168AEC89026BC8CF9")->value = decal.id;
auto colour_prop = decal_prop->at<ColourStructProperty>("Color_8_1B0B9D2B43DA6AAB9FA549B374D3E606");
colour_prop->r = decal.colour.r();
colour_prop->g = decal.colour.g();
colour_prop->b = decal.colour.b();
colour_prop->a = decal.colour.a();
auto pos_prop = decal_prop->at<VectorStructProperty>("Position_41_022C8FE84E1AAFE587261E88F2C72250");
pos_prop->x = decal.position.x();
pos_prop->y = decal.position.y();
pos_prop->z = decal.position.z();
auto u_prop = decal_prop->at<VectorStructProperty>("UAxis_37_EBEB715F45491AECACCC07A1AE4646D1");
u_prop->x = decal.uAxis.x();
u_prop->y = decal.uAxis.y();
u_prop->z = decal.uAxis.z();
auto v_prop = decal_prop->at<VectorStructProperty>("VAxis_39_C31EB2664EE202CAECFBBB84100B5E35");
v_prop->x = decal.vAxis.x();
v_prop->y = decal.vAxis.y();
v_prop->z = decal.vAxis.z();
auto offset_prop = decal_prop->at<Vector2DStructProperty>("Offset_29_B02BBBB74FC60F5EDBEBAB8020738020");
offset_prop->x = decal.offset.x();
offset_prop->y = decal.offset.y();
decal_prop->at<FloatProperty>("Scale_32_959D1C2747AFD8D62808468235CBBA40")->value = decal.scale;
decal_prop->at<FloatProperty>("Rotation_27_12D7C314493D203D5C2326A03C5F910F")->value = decal.rotation;
decal_prop->at<BoolProperty>("Flip_35_CECCFB184CCD9412BD93FE9A8B656BE1")->value = decal.flip;
decal_prop->at<BoolProperty>("Wrap_43_A7C68CDF4A92AF2ECDA53F953EE7CA62")->value = decal.wrap;
}
if(!_demo) {
auto part_accs = part_prop->at<ArrayProperty>("Accessories_21_3878DE8B4ED0EA0DB725E98BCDC20E0C");
if(!part_accs) {
_demo = true;
continue;
}
if(part_accs->items.size() != part.accessories.size()) {
_state = State::Invalid;
return false;
}
getAccessories(part.accessories, part_accs);
}
}
auto custom_styles = weapon_prop->at<ArrayProperty>("Styles_10_8C3C82444B986AD7A99595AD4985912D");
if(!custom_styles) {
_state = State::Invalid;
return false;
}
if(custom_styles->items.size() != weapon.customStyles.size()) {
_state = State::Invalid;
return false;
}
for(UnsignedInt j = 0; j < weapon.customStyles.size(); j++) {
setCustomStyle(weapon.customStyles[j], j, custom_styles);
}
weapon_prop->at<BoolProperty>("Attach_15_D00AABBD4AD6A04778D56D81E51927B3")->value = weapon.attached;
weapon_prop->at<ByteProperty>("DamageType_18_E1FFA53540591A9087EC698117A65C83")->enumValue = weapon.damageType;
weapon_prop->at<BoolProperty>("DualWield_20_B2EB2CEA4A6A233DC7575996B6DD1222")->value = weapon.dualWield;
weapon_prop->at<ByteProperty>("ColorEfxMode_24_D254BCF943E852BF9ADB8AAA8FD80014")->enumValue = weapon.effectColourMode;
auto effect_colour = weapon_prop->at<ColourStructProperty>("ColorEfx_26_D921B62946C493E487455A831F4520AC");
effect_colour->r = weapon.effectColour.r();
effect_colour->g = weapon.effectColour.g();
effect_colour->b = weapon.effectColour.b();
effect_colour->a = weapon.effectColour.a();
}
return _mass->saveToFile();
}

View file

@ -206,6 +206,7 @@ class Mass {
void getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array); void getAccessories(Containers::ArrayView<Accessory> accessories, ArrayProperty* accessory_array);
void getWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array); void getWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array);
auto writeWeaponType(const char* prop_name, Containers::ArrayView<Weapon> weapon_array) -> bool;
Containers::Optional<UESaveFile> _mass; Containers::Optional<UESaveFile> _mass;