25. Attribut accessors complete

There is some jank, with the ability system init on character (I'll fix later).
Cog replaces the usuals showdebug command
This commit is contained in:
2024-04-13 18:35:19 -04:00
parent ced71b6a22
commit c2e5793a7d
16 changed files with 265 additions and 32 deletions

View File

@ -13,26 +13,26 @@ using namespace gen;
#define path_gasa_ability_system path_module_gasa "AbilitySystem/"
void def_attribute_fields( CodeBody body, Array<StringCached> fields )
void def_attribute_properties( CodeBody body, Array<StringCached> properties )
{
for ( String field : fields )
for ( StringCached property : properties )
{
Code field_uproperty = code_str(
UPROPERTY(ReplicatedUsing=Client_OnRep_Health, EditAnywhere, BlueprintReadWrite, Category="Attributes")
);
Code field_uproperty = code_fmt( "property", (StrC)property, stringize(
UPROPERTY(ReplicatedUsing=Client_OnRep_<property>, EditAnywhere, BlueprintReadWrite, Category="Attributes")
));
CodeType type_FGameplayAttributeData = def_type( txt("FGameplayAttributeData"));
body.append(fmt_newline);
body.append( field_uproperty );
body.append(fmt_newline);
body.append( def_variable( type_FGameplayAttributeData, StrC(field)) );
body.append( def_variable( type_FGameplayAttributeData, StrC(property)) );
}
}
void def_attribute_field_on_reps( CodeBody body, Array<StringCached> fields )
{
for ( String field : fields )
for ( StringCached field : fields )
{
Code umeta_UFUNCTION = code_str( UFUNCTION() );
@ -45,17 +45,89 @@ void def_attribute_field_on_reps( CodeBody body, Array<StringCached> fields )
}
}
void impl_attribute_fields( CodeBody body, Array<StringCached> fields )
void def_attribute_field_property_getters( CodeBody body, StrC class_name, Array<StringCached> properties )
{
for ( String field : fields )
for ( String property : properties )
{
body.append(fmt_newline);
CodeFn field_impl = parse_function( token_fmt( "field", (StrC)field, stringize(
void UGasaAttributeSet::Client_OnRep_<field>(FGameplayAttributeData& Prev<field>)
CodeFn generated_get_attribute = parse_function(
token_fmt( "class_name", class_name, "property", (StrC)property,
stringize(
static FGameplayAttribute Get<property>Attribute()
{
static FProperty* Prop = FindFieldChecked<FProperty>(<class_name>::StaticClass(), GET_MEMBER_NAME_CHECKED(<class_name>, <property>));
return Prop;
}
)));
body.append( generated_get_attribute );
}
}
void def_attribute_field_value_getters( CodeBody body, Array<StringCached> properties )
{
for ( String property : properties )
{
#pragma push_macro(FORCEINLINE)
#undef FORCEINLINE
body.append( code_fmt( "property", (StrC)property,
stringize(
FORCEINLINE float Get<property>() const
{
GAMEPLAYATTRIBUTE_REPNOTIFY(UGasaAttributeSet, <field>, Prev<field>)
return <property>.GetCurrentValue();
}
)));
#pragma pop_macro(FORCEINLINE)
}
}
void def_attribute_field_value_setters( CodeBody body, Array<StringCached> properties )
{
for ( String property : properties )
{
body.append( code_fmt( "property", (StrC)property,
stringize(
FORCEINLINE void Set<property>(float NewVal)
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if (ensure(AbilityComp))
{
AbilityComp->SetNumericAttributeBase(Get<property>Attribute(), NewVal);
};
}
)));
}
}
void def_attribute_field_initers ( CodeBody body, Array<StringCached> properties )
{
for ( String property : properties )
{
body.append( code_fmt( "property", (StrC)property,
stringize(
FORCEINLINE void Init<property>(float NewVal)
{
<property>.SetBaseValue(NewVal);
<property>.SetCurrentValue(NewVal);
}
)));
}
}
void impl_attribute_fields( CodeBody body, StrC class_name, Array<StringCached> properties )
{
for ( String property : properties )
{
body.append(fmt_newline);
CodeFn field_impl = parse_function( token_fmt( "class_name", class_name, "property", (StrC)property,
stringize(
void <class_name>::Client_OnRep_<property>(FGameplayAttributeData& Prev<property>)
{
GAMEPLAYATTRIBUTE_REPNOTIFY(<class_name>, <property>, Prev<property>)
}
)));
body.append( field_impl );
}
}
@ -79,12 +151,16 @@ int gen_main()
attribute_fields.append( get_cached_string(txt("Mana")));
attribute_fields.append( get_cached_string(txt("MaxMana")));
StrC attributeset_name = txt("UGasaAttributeSet");
Builder header = Builder::open( path_gasa_ability_system "GasaAttributeSet.h");
{
header.print(generation_notice);
header.print(fmt_newline);
{
CodeInclude Include_AttributeSet = def_include(txt("AttributeSet.h"));
CodeInclude Include_AbilitySystemComponent = def_include(txt("AbilitySystemComponent.h"));
CodeInclude Include_GasaAttributeSet_Generated = def_include(txt("GasaAttributeSet.generated.h"));
CodeAttributes attributes = def_attributes( gasa_api->Name);
@ -97,7 +173,7 @@ int gen_main()
body.append( fmt_newline);
body.append( access_public );
def_attribute_fields( body, attribute_fields);
def_attribute_properties( body, attribute_fields);
body.append(fmt_newline);
body.append( def_constructor() );
@ -105,7 +181,19 @@ int gen_main()
def_attribute_field_on_reps( body, attribute_fields);
body.append(fmt_newline);
body.append(fmt_newline);
body.append( fmt_newline );
body.append( def_pragma(code( region Getters )));
def_attribute_field_property_getters( body, attributeset_name, attribute_fields );
def_attribute_field_value_getters( body, attribute_fields );
body.append( def_pragma(code( endregion Getters )));
body.append( fmt_newline );
body.append( def_pragma(code( region Setters )));
def_attribute_field_value_setters( body, attribute_fields );
def_attribute_field_initers( body, attribute_fields );
body.append( def_pragma(code( endregion Setters )));
body.append( fmt_newline );
body.append( def_pragma( txt("region UObject")));
body.append( parse_function( code(
@ -121,7 +209,7 @@ int gen_main()
}
header.print( Include_AttributeSet);
header.print( fmt_newline);
header.print( Include_AbilitySystemComponent);
header.print( Include_GasaAttributeSet_Generated);
header.print( fmt_newline);
header.print(umeta_uclass);
@ -142,11 +230,17 @@ int gen_main()
CodeBody body = def_body( CodeT::Global_Body );
body.append(fmt_newline);
body.append(code_str(
UGasaAttributeSet::UGasaAttributeSet() {}
UGasaAttributeSet::UGasaAttributeSet()
{
InitHealth( 100.f );
InitMaxHealth( 100.f );
InitMana(( 50.f ));
InitMaxMana( 50.f );
}
));
body.append(fmt_newline);
impl_attribute_fields(body, attribute_fields);
impl_attribute_fields( body, attributeset_name, attribute_fields);
CodeFn GetLifetimeOfReplicatedProps;
{