2022-03-06 09:51:57 +01:00
// MassBuilderSaveTool
// Copyright (C) 2021-2022 Guillaume Jacquemin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2022-11-21 18:00:38 +01:00
# include "PropertyNames.h"
2022-03-06 09:51:57 +01:00
# include "../UESaveFile/Types/ArrayProperty.h"
# include "../UESaveFile/Types/ColourStructProperty.h"
# include "../UESaveFile/Types/FloatProperty.h"
# include "../UESaveFile/Types/GenericStructProperty.h"
# include "../UESaveFile/Types/IntProperty.h"
# include "Mass.h"
using namespace Containers : : Literals ;
auto Mass : : jointSliders ( ) - > Joints & {
return _frame . joints ;
}
void Mass : : getJointSliders ( ) {
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find unit data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
2022-11-21 18:00:38 +01:00
auto frame_prop = unit_data - > at < GenericStructProperty > ( MASS_FRAME ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_prop ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find frame data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
2022-11-21 18:00:38 +01:00
auto length = frame_prop - > at < FloatProperty > ( MASS_JOINT_NECK ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . neck = ( length ? length - > value : 0.0f ) ;
2022-11-21 18:00:38 +01:00
length = frame_prop - > at < FloatProperty > ( MASS_JOINT_BODY ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . body = ( length ? length - > value : 0.0f ) ;
2022-11-21 18:00:38 +01:00
length = frame_prop - > at < FloatProperty > ( MASS_JOINT_SHOULDER ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . shoulders = ( length ? length - > value : 0.0f ) ;
2022-11-21 18:00:38 +01:00
length = frame_prop - > at < FloatProperty > ( MASS_JOINT_HIP ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . hips = ( length ? length - > value : 0.0f ) ;
2022-11-21 18:00:38 +01:00
length = frame_prop - > at < FloatProperty > ( MASS_JOINT_ARM_UPPER ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . upperArms = ( length ? length - > value : 0.0f ) ;
2022-11-21 18:00:38 +01:00
length = frame_prop - > at < FloatProperty > ( MASS_JOINT_ARM_LOWER ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . lowerArms = ( length ? length - > value : 0.0f ) ;
2022-11-21 18:00:38 +01:00
length = frame_prop - > at < FloatProperty > ( MASS_JOINT_LEG_UPPER ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . upperLegs = ( length ? length - > value : 0.0f ) ;
2022-11-21 18:00:38 +01:00
length = frame_prop - > at < FloatProperty > ( MASS_JOINT_LEG_LOWER ) ;
2022-03-06 09:51:57 +01:00
_frame . joints . lowerLegs = ( length ? length - > value : 0.0f ) ;
}
auto Mass : : writeJointSliders ( ) - > bool {
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
_state = State : : Invalid ;
_lastError = " No unit data in " _s + _filename ;
return false ;
}
2022-11-21 18:00:38 +01:00
auto frame_prop = unit_data - > at < GenericStructProperty > ( MASS_FRAME ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_prop ) {
_state = State : : Invalid ;
_lastError = " No frame data in " _s + _filename ;
return false ;
}
Containers : : Array < UnrealPropertyBase : : ptr > temp ;
2022-11-21 18:00:38 +01:00
auto length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_NECK ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . neck ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_NECK ) ;
2022-03-06 09:51:57 +01:00
}
length - > value = _frame . joints . neck ;
arrayAppend ( temp , std : : move ( length ) ) ;
}
2022-11-21 18:00:38 +01:00
length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_BODY ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . body ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_BODY ) ;
2022-03-06 09:51:57 +01:00
}
length - > value = _frame . joints . body ;
arrayAppend ( temp , std : : move ( length ) ) ;
}
2022-11-21 18:00:38 +01:00
length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_SHOULDER ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . shoulders ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_SHOULDER ) ;
2022-03-06 09:51:57 +01:00
}
length - > value = _frame . joints . shoulders ;
arrayAppend ( temp , std : : move ( length ) ) ;
}
2022-11-21 18:00:38 +01:00
length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_ARM_UPPER ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . upperArms ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_ARM_UPPER ) ;
2022-03-06 09:51:57 +01:00
}
length - > value = _frame . joints . upperArms ;
arrayAppend ( temp , std : : move ( length ) ) ;
}
2022-11-21 18:00:38 +01:00
length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_ARM_LOWER ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . lowerArms ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_ARM_LOWER ) ;
2022-03-06 09:51:57 +01:00
}
length - > value = _frame . joints . lowerArms ;
arrayAppend ( temp , std : : move ( length ) ) ;
}
2022-11-21 18:00:38 +01:00
length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_HIP ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . hips ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_HIP ) ;
2022-03-06 09:51:57 +01:00
}
length - > value = _frame . joints . hips ;
arrayAppend ( temp , std : : move ( length ) ) ;
}
2022-11-21 18:00:38 +01:00
length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_LEG_UPPER ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . upperLegs ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_LEG_UPPER ) ;
2022-03-06 09:51:57 +01:00
}
length - > value = _frame . joints . upperLegs ;
arrayAppend ( temp , std : : move ( length ) ) ;
}
2022-11-21 18:00:38 +01:00
length = frame_prop - > atMove < FloatProperty > ( MASS_JOINT_LEG_LOWER ) ;
2022-03-06 09:51:57 +01:00
if ( _frame . joints . lowerLegs ! = 0.0f ) {
if ( ! length ) {
length . emplace ( ) ;
2022-11-21 18:00:38 +01:00
length - > name . emplace ( MASS_JOINT_LEG_LOWER ) ;
2022-03-06 09:51:57 +01:00
}
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 = _mass - > lastError ( ) ;
return false ;
}
return true ;
}
auto Mass : : frameStyles ( ) - > Containers : : ArrayView < Int > {
return _frame . styles ;
}
void Mass : : getFrameStyles ( ) {
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find unit data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
2022-11-21 18:00:38 +01:00
auto frame_prop = unit_data - > at < GenericStructProperty > ( MASS_FRAME ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_prop ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find frame data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
2022-11-21 18:00:38 +01:00
auto frame_styles = frame_prop - > at < ArrayProperty > ( MASS_FRAME_STYLES ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_styles ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find frame styles in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
if ( frame_styles - > items . size ( ) ! = _frame . styles . size ( ) ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Frame style arrays are not of the same size. Expected " < < _frame . styles . size ( ) < < Utility : : Debug : : nospace < < " , got " < < frame_styles - > items . size ( ) < < " instead. " ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
for ( UnsignedInt i = 0 ; i < frame_styles - > items . size ( ) ; i + + ) {
_frame . styles [ i ] = frame_styles - > at < IntProperty > ( i ) - > value ;
}
}
auto Mass : : writeFrameStyles ( ) - > bool {
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
_state = State : : Invalid ;
_lastError = " No unit data in " _s + _filename ;
return false ;
}
2022-11-21 18:00:38 +01:00
auto frame = unit_data - > at < GenericStructProperty > ( MASS_FRAME ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame ) {
_state = State : : Invalid ;
_lastError = " No frame data in " _s + _filename ;
return false ;
}
2022-11-21 18:00:38 +01:00
auto frame_styles = frame - > at < ArrayProperty > ( MASS_FRAME_STYLES ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_styles ) {
_state = State : : Invalid ;
_lastError = " No frame styles in " _s + _filename ;
return false ;
}
for ( UnsignedInt i = 0 ; i < frame_styles - > items . size ( ) ; i + + ) {
frame_styles - > at < IntProperty > ( i ) - > value = _frame . styles [ i ] ;
}
if ( ! _mass - > saveToFile ( ) ) {
_lastError = _mass - > lastError ( ) ;
return false ;
}
return true ;
}
auto Mass : : eyeFlareColour ( ) - > Color4 & {
return _frame . eyeFlare ;
}
void Mass : : getEyeFlareColour ( ) {
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find unit data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
2022-11-21 18:00:38 +01:00
auto frame_prop = unit_data - > at < GenericStructProperty > ( MASS_FRAME ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_prop ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find frame data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
2022-11-21 18:00:38 +01:00
auto eye_flare_prop = frame_prop - > at < ColourStructProperty > ( MASS_EYE_FLARE ) ;
2022-03-06 09:51:57 +01:00
if ( ! eye_flare_prop ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find eye flare data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
_frame . eyeFlare = Color4 { eye_flare_prop - > r , eye_flare_prop - > g , eye_flare_prop - > b , eye_flare_prop - > a } ;
}
auto Mass : : writeEyeFlareColour ( ) - > bool {
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
_state = State : : Invalid ;
_lastError = " No unit data in " _s + _filename ;
return false ;
}
2022-11-21 18:00:38 +01:00
auto frame = unit_data - > at < GenericStructProperty > ( MASS_FRAME ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame ) {
_state = State : : Invalid ;
_lastError = " No frame data in " _s + _filename ;
return false ;
}
2022-11-21 18:00:38 +01:00
auto eye_flare_prop = frame - > at < ColourStructProperty > ( MASS_EYE_FLARE ) ;
2022-03-06 09:51:57 +01:00
if ( ! eye_flare_prop ) {
_state = State : : Invalid ;
_lastError = " No eye flare property in " _s + _filename ;
return false ;
}
eye_flare_prop - > r = _frame . eyeFlare . r ( ) ;
eye_flare_prop - > g = _frame . eyeFlare . g ( ) ;
eye_flare_prop - > b = _frame . eyeFlare . b ( ) ;
eye_flare_prop - > a = _frame . eyeFlare . a ( ) ;
if ( ! _mass - > saveToFile ( ) ) {
_lastError = _mass - > lastError ( ) ;
return false ;
}
return true ;
}
auto Mass : : frameCustomStyles ( ) - > Containers : : ArrayView < CustomStyle > {
return _frame . customStyles ;
}
void Mass : : getFrameCustomStyles ( ) {
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find unit data in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
2022-11-21 18:00:38 +01:00
auto frame_styles = unit_data - > at < ArrayProperty > ( MASS_CUSTOM_FRAME_STYLES ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_styles ) {
2022-03-30 19:51:00 +02:00
Utility : : Error { } < < " Can't find frame styles in " < < _filename ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
if ( frame_styles - > items . size ( ) ! = _frame . customStyles . size ( ) ) {
2022-03-30 19:51:00 +02:00
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. " ;
2022-03-06 09:51:57 +01:00
_state = State : : Invalid ;
return ;
}
getCustomStyles ( _frame . customStyles , frame_styles ) ;
}
auto Mass : : writeFrameCustomStyle ( UnsignedLong index ) - > bool {
if ( index > _frame . customStyles . size ( ) ) {
_lastError = " Style index out of range. " _s ;
return false ;
}
2022-11-21 18:00:38 +01:00
auto unit_data = _mass - > at < GenericStructProperty > ( MASS_UNIT_DATA ) ;
2022-03-06 09:51:57 +01:00
if ( ! unit_data ) {
_state = State : : Invalid ;
_lastError = " No unit data in " _s + _filename ;
return false ;
}
2022-11-21 18:00:38 +01:00
auto frame_styles = unit_data - > at < ArrayProperty > ( MASS_CUSTOM_FRAME_STYLES ) ;
2022-03-06 09:51:57 +01:00
if ( ! frame_styles ) {
_state = State : : Invalid ;
_lastError = " No frame styles in " _s + _filename ;
return false ;
}
return writeCustomStyle ( _frame . customStyles [ index ] , index , frame_styles ) ;
}