diff --git a/src/Mass/Mass.cpp b/src/Mass/Mass.cpp index f07bf65..7b4a028 100644 --- a/src/Mass/Mass.cpp +++ b/src/Mass/Mass.cpp @@ -290,94 +290,94 @@ auto Mass::writeJointSliders() -> bool { return false; } - auto length = frame_prop->at("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"); - if(!length && _frame.joints.neck != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"); - arrayAppend(frame_prop->properties, std::move(length_prop)); - } - if(length) { + Containers::Array temp; + + auto length = frame_prop->atMove("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"); + if(_frame.joints.neck != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("NeckLength_6_ED6AF79849C27CD1A9D523A09E2BFE58"); + } length->value = _frame.joints.neck; + arrayAppend(temp, std::move(length)); } - length = frame_prop->at("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"); - if(!length && _frame.joints.body != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"); - arrayAppend(frame_prop->properties, std::move(length_prop)); - } - if(length) { + length = frame_prop->atMove("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"); + if(_frame.joints.body != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("BodyLength_7_C16287754CBA96C93BAE36A5C154996A"); + } length->value = _frame.joints.body; + arrayAppend(temp, std::move(length)); } - length = frame_prop->at("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"); - if(!length && _frame.joints.shoulders != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"); - arrayAppend(frame_prop->properties, std::move(length_prop)); - } - if(length) { + length = frame_prop->atMove("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"); + if(_frame.joints.shoulders != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("ShoulderLength_8_220EDF304F1C1226F0D8D39117FB3883"); + } length->value = _frame.joints.shoulders; + arrayAppend(temp, std::move(length)); } - length = frame_prop->at("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"); - if(!length && _frame.joints.hips != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"); - arrayAppend(frame_prop->properties, std::move(length_prop)); - } - if(length) { - length->value = _frame.joints.hips; - } - - length = frame_prop->at("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"); - if(!length && _frame.joints.upperArms != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"); - arrayAppend(frame_prop->properties, std::move(length_prop)); - } - if(length) { + length = frame_prop->atMove("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"); + if(_frame.joints.upperArms != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("ArmUpperLength_10_249FDA3E4F3B399E7B9E5C9B7C765EAE"); + } length->value = _frame.joints.upperArms; + arrayAppend(temp, std::move(length)); } - length = frame_prop->at("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"); - if(!length && _frame.joints.lowerArms != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"); - arrayAppend(frame_prop->properties, std::move(length_prop)); - } - if(length) { + length = frame_prop->atMove("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"); + if(_frame.joints.lowerArms != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("ArmLowerLength_12_ACD0F02745C28882619376926292FB36"); + } length->value = _frame.joints.lowerArms; + arrayAppend(temp, std::move(length)); } - length = frame_prop->at("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"); - if(!length && _frame.joints.upperLegs != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"); - arrayAppend(frame_prop->properties, std::move(length_prop)); + length = frame_prop->atMove("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"); + if(_frame.joints.hips != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("HipLength_14_02AEEEAC4376087B9C51F0AA7CC92818"); + } + length->value = _frame.joints.hips; + arrayAppend(temp, std::move(length)); } - if(length) { + + length = frame_prop->atMove("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"); + if(_frame.joints.upperLegs != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("LegUpperLength_16_A7C4C71249A3776F7A543D96819C0C61"); + } length->value = _frame.joints.upperLegs; + arrayAppend(temp, std::move(length)); } - length = frame_prop->at("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"); - if(!length && _frame.joints.lowerLegs != 0.0f) { - length = new FloatProperty; - auto length_prop = FloatProperty::ptr{length}; - length_prop->name.emplace("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"); - arrayAppend(frame_prop->properties, std::move(length_prop)); - } - if(length) { + length = frame_prop->atMove("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"); + if(_frame.joints.lowerLegs != 0.0f) { + if(!length) { + length.emplace(); + length->name.emplace("LegLowerLength_18_D2DF39964EA0F2A2129D0491B08A032F"); + } length->value = _frame.joints.lowerLegs; + arrayAppend(temp, std::move(length)); } + arrayAppend(temp, std::move(frame_prop->properties[frame_prop->properties.size() - 3])); + arrayAppend(temp, std::move(frame_prop->properties[frame_prop->properties.size() - 2])); + arrayAppend(temp, std::move(frame_prop->properties[frame_prop->properties.size() - 1])); + + frame_prop->properties = std::move(temp); + if(!_mass->saveToFile()) { _lastError = "Couldn't write data to " + _filename; return false; diff --git a/src/UESaveFile/Types/GenericStructProperty.h b/src/UESaveFile/Types/GenericStructProperty.h index 2e5b8bb..7ff3cfb 100644 --- a/src/UESaveFile/Types/GenericStructProperty.h +++ b/src/UESaveFile/Types/GenericStructProperty.h @@ -36,5 +36,16 @@ struct GenericStructProperty : public StructProperty { return nullptr; } + template + std::enable_if_t::value, typename T::ptr> + atMove(const std::string& name) { + for(auto& item : properties) { + if(item && item->name == name) { + return Containers::Pointer{static_cast(item.release())}; + } + } + return nullptr; + } + Containers::Array properties; };