2024-04-14 18:51:14 -07:00
|
|
|
|
// Used in the GasaGen.cpp translation unit
|
2024-04-21 06:51:51 -07:00
|
|
|
|
#if GASA_INTELLISENSE_DIRECTIVES
|
|
|
|
|
#pragma once
|
|
|
|
|
#define GEN_EXPOSE_BACKEND
|
|
|
|
|
#include "gen.hpp"
|
|
|
|
|
#include "gen.builder.hpp"
|
|
|
|
|
#include "GasaGenCommon.cpp"
|
|
|
|
|
#endif
|
2024-04-14 18:51:14 -07:00
|
|
|
|
|
2024-04-21 15:56:57 -07:00
|
|
|
|
void def_attribute_properties ( CodeBody body, Array<StringCached> properties );
|
|
|
|
|
void def_attribute_field_on_reps ( CodeBody body, Array<StringCached> properties );
|
|
|
|
|
void def_attribute_field_property_getters ( CodeBody body, StrC class_name, Array<StringCached> properties );
|
|
|
|
|
void def_attribute_field_value_getters ( CodeBody body, Array<StringCached> properties );
|
|
|
|
|
void def_attribute_field_value_setters ( CodeBody body, Array<StringCached> properties );
|
|
|
|
|
void def_attribute_field_property_setter_inlines( CodeBody body, StrC class_name, Array<StringCached> properties );
|
|
|
|
|
void def_attribute_field_initers ( CodeBody body, Array<StringCached> properties );
|
|
|
|
|
void impl_attribute_fields ( CodeBody body, StrC class_name, Array<StringCached> properties );
|
2024-04-14 18:51:14 -07:00
|
|
|
|
|
2024-04-21 21:30:29 -07:00
|
|
|
|
Array<StringCached> get_gasa_attribute_fields()
|
|
|
|
|
{
|
|
|
|
|
local_persist
|
|
|
|
|
Array<StringCached> attribute_fields = Array<StringCached>::init_reserve(GlobalAllocator, 64);
|
|
|
|
|
|
|
|
|
|
for (local_persist s32 do_once = 0; do_once == 0; ++ do_once) {
|
|
|
|
|
attribute_fields.append( get_cached_string(txt("Health")));
|
|
|
|
|
attribute_fields.append( get_cached_string(txt("MaxHealth")));
|
|
|
|
|
attribute_fields.append( get_cached_string(txt("Mana")));
|
|
|
|
|
attribute_fields.append( get_cached_string(txt("MaxMana")));
|
|
|
|
|
}
|
|
|
|
|
return attribute_fields;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-14 18:51:14 -07:00
|
|
|
|
void gen_UGasaAttributeSet()
|
|
|
|
|
{
|
|
|
|
|
CodeType type_UAttributeSet = def_type( txt("UAttributeSet") );
|
2024-04-21 15:56:57 -07:00
|
|
|
|
CodeComment generation_notice = def_comment(txt("Generated by GasaGen/GasaGen_UGasaAttributeSet.cpp"));
|
2024-04-14 18:51:14 -07:00
|
|
|
|
|
2024-04-21 21:30:29 -07:00
|
|
|
|
Array<StringCached> attribute_fields = get_gasa_attribute_fields();
|
2024-04-14 18:51:14 -07:00
|
|
|
|
|
|
|
|
|
StrC class_name = txt("UGasaAttributeSet");
|
|
|
|
|
|
|
|
|
|
Builder header = Builder::open( path_gasa_ability_system "GasaAttributeSet.h");
|
|
|
|
|
{
|
|
|
|
|
header.print(generation_notice);
|
2024-04-21 15:56:57 -07:00
|
|
|
|
header.print(pragma_once);
|
2024-04-14 18:51:14 -07:00
|
|
|
|
header.print(fmt_newline);
|
|
|
|
|
{
|
|
|
|
|
CodeInclude Include_AttributeSet = def_include(txt("AttributeSet.h"));
|
|
|
|
|
CodeInclude Include_GasaAttributeSet_Generated = def_include(txt("GasaAttributeSet.generated.h"));
|
|
|
|
|
|
2024-04-21 06:51:51 -07:00
|
|
|
|
CodeAttributes api_attribute= def_attributes( UModule_GASA_API->Name);
|
2024-04-14 18:51:14 -07:00
|
|
|
|
|
|
|
|
|
CodeClass GasaAttributeSet = {};
|
|
|
|
|
{
|
|
|
|
|
CodeBody body = def_body( CodeT::Class_Body );
|
|
|
|
|
{
|
2024-04-21 06:51:51 -07:00
|
|
|
|
body.append( UHT_GENERATED_BODY);
|
2024-04-14 18:51:14 -07:00
|
|
|
|
body.append( access_public );
|
|
|
|
|
|
|
|
|
|
def_attribute_properties( body, attribute_fields);
|
|
|
|
|
|
|
|
|
|
body.append(fmt_newline);
|
|
|
|
|
body.append( def_constructor() );
|
2024-04-21 06:51:51 -07:00
|
|
|
|
body.append(fmt_newline);
|
2024-04-14 18:51:14 -07:00
|
|
|
|
|
|
|
|
|
def_attribute_field_on_reps( body, attribute_fields);
|
|
|
|
|
|
|
|
|
|
body.append(fmt_newline);
|
|
|
|
|
|
|
|
|
|
body.append( fmt_newline );
|
|
|
|
|
body.append( def_pragma(code( region Getters )));
|
|
|
|
|
def_attribute_field_property_getters( body, class_name, attribute_fields );
|
2024-04-21 15:56:57 -07:00
|
|
|
|
body.append( fmt_newline );
|
2024-04-14 18:51:14 -07:00
|
|
|
|
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 );
|
2024-04-21 15:56:57 -07:00
|
|
|
|
body.append( fmt_newline );
|
|
|
|
|
body.append( fmt_newline );
|
2024-04-14 18:51:14 -07:00
|
|
|
|
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")));
|
2024-04-16 14:18:06 -07:00
|
|
|
|
CodeFn GetLifetimeOfReplicatedProps = parse_function( code(
|
2024-04-14 18:51:14 -07:00
|
|
|
|
void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
2024-04-16 14:18:06 -07:00
|
|
|
|
));
|
|
|
|
|
body.append( GetLifetimeOfReplicatedProps );
|
2024-04-14 18:51:14 -07:00
|
|
|
|
body.append( def_pragma( txt("endregion UObject")));
|
|
|
|
|
}
|
|
|
|
|
GasaAttributeSet = def_class( class_name, body
|
|
|
|
|
, type_UAttributeSet, AccessSpec::Public
|
|
|
|
|
, api_attribute
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
header.print( Include_AttributeSet);
|
|
|
|
|
header.print( Include_GasaAttributeSet_Generated);
|
|
|
|
|
header.print( fmt_newline);
|
2024-04-21 06:51:51 -07:00
|
|
|
|
header.print( UHT_UCLASS );
|
2024-04-14 18:51:14 -07:00
|
|
|
|
header.print(GasaAttributeSet);
|
|
|
|
|
}
|
|
|
|
|
header.write();
|
2024-04-21 06:51:51 -07:00
|
|
|
|
format_file(path_gasa_ability_system "GasaAttributeSet.h");
|
2024-04-14 18:51:14 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 15:56:57 -07:00
|
|
|
|
Builder inlines = Builder::open( path_gasa_ability_system "GasaAttributeSet_Inlines.h");
|
|
|
|
|
{
|
|
|
|
|
inlines.print(generation_notice);
|
|
|
|
|
inlines.print(pragma_once);
|
|
|
|
|
inlines.print(fmt_newline);
|
|
|
|
|
inlines.print( def_include( txt("GasaAttributeSet.h")));
|
|
|
|
|
inlines.print( def_include(txt("AbilitySystemComponent.h")));
|
|
|
|
|
inlines.print(fmt_newline);
|
|
|
|
|
|
|
|
|
|
CodeBody body = def_body(CodeT::Global_Body);
|
|
|
|
|
{
|
|
|
|
|
def_attribute_field_property_setter_inlines( body, class_name, attribute_fields );
|
|
|
|
|
}
|
|
|
|
|
inlines.print(body);
|
|
|
|
|
inlines.print(fmt_newline);
|
|
|
|
|
|
|
|
|
|
CodeNS ns_gasa = parse_namespace( code(
|
|
|
|
|
namespace Gasa
|
|
|
|
|
{
|
|
|
|
|
inline
|
|
|
|
|
UGasaAttributeSet const* GetAttributeSet( UAbilitySystemComponent* ASC )
|
|
|
|
|
{
|
|
|
|
|
return Cast<UGasaAttributeSet>(ASC->GetAttributeSet( UGasaAttributeSet::StaticClass() ));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
inlines.print(ns_gasa);
|
|
|
|
|
inlines.write();
|
|
|
|
|
format_file(path_gasa_ability_system "GasaAttributeSet_Inlines.h");
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-14 18:51:14 -07:00
|
|
|
|
Builder source = Builder::open( path_gasa_ability_system "GasaAttributeSet.cpp" );
|
|
|
|
|
{
|
|
|
|
|
source.print(generation_notice);
|
|
|
|
|
header.print(fmt_newline);
|
|
|
|
|
source.print( def_include( txt("GasaAttributeSet.h")));
|
2024-04-21 15:56:57 -07:00
|
|
|
|
source.print( def_include( txt("GasaAttributeSet_Inlines.h")));
|
2024-04-14 18:51:14 -07:00
|
|
|
|
source.print(fmt_newline);
|
|
|
|
|
source.print( def_include( txt("AbilitySystemComponent.h")));
|
|
|
|
|
source.print( def_include( txt("Net/UnrealNetwork.h")));
|
|
|
|
|
source.print( def_include( txt("Networking/GasaNetLibrary.h")));
|
|
|
|
|
{
|
|
|
|
|
CodeBody body = def_body( CodeT::Global_Body );
|
|
|
|
|
body.append(fmt_newline);
|
|
|
|
|
|
|
|
|
|
CodeConstructor constructor_for_UGasaAttributeSet = parse_constructor( code(
|
|
|
|
|
UGasaAttributeSet::UGasaAttributeSet()
|
|
|
|
|
{
|
|
|
|
|
InitHealth( 100.f );
|
|
|
|
|
InitMaxHealth( 100.f );
|
2024-04-15 20:09:46 -07:00
|
|
|
|
InitMana( 50.f );
|
2024-04-14 18:51:14 -07:00
|
|
|
|
InitMaxMana( 50.f );
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
body.append(constructor_for_UGasaAttributeSet );
|
|
|
|
|
|
|
|
|
|
impl_attribute_fields( body, class_name, attribute_fields);
|
|
|
|
|
|
|
|
|
|
CodeFn GetLifetimeOfReplicatedProps;
|
|
|
|
|
{
|
|
|
|
|
CodeBody field_lifetimes = def_body( CodeT::Function_Body);
|
2024-04-21 06:51:51 -07:00
|
|
|
|
field_lifetimes.append(fmt_newline);
|
|
|
|
|
field_lifetimes.append(fmt_newline);
|
2024-04-14 18:51:14 -07:00
|
|
|
|
for (StringCached field : attribute_fields)
|
|
|
|
|
{
|
|
|
|
|
field_lifetimes.append( code_fmt( "field", (StrC)field, stringize(
|
|
|
|
|
DOREPLIFETIME_DEFAULT_GAS(UGasaAttributeSet, <field>);
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 09:16:22 -07:00
|
|
|
|
GetLifetimeOfReplicatedProps = parse_function( token_fmt( "field_lifetimes", (StrC)(field_lifetimes.to_string()), stringize(
|
2024-04-14 18:51:14 -07:00
|
|
|
|
void UGasaAttributeSet::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
|
|
|
{
|
|
|
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
2024-04-17 09:16:22 -07:00
|
|
|
|
<field_lifetimes>
|
2024-04-14 18:51:14 -07:00
|
|
|
|
}
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
body.append(GetLifetimeOfReplicatedProps);
|
|
|
|
|
|
|
|
|
|
source.print(body);
|
|
|
|
|
}
|
|
|
|
|
source.write();
|
2024-04-21 06:51:51 -07:00
|
|
|
|
format_file(path_gasa_ability_system "GasaAttributeSet.cpp");
|
2024-04-14 18:51:14 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void def_attribute_properties( CodeBody body, Array<StringCached> properties )
|
|
|
|
|
{
|
|
|
|
|
for ( StringCached property : properties )
|
|
|
|
|
{
|
|
|
|
|
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(property)) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void def_attribute_field_on_reps( CodeBody body, Array<StringCached> properties )
|
|
|
|
|
{
|
|
|
|
|
for ( StringCached property : properties )
|
|
|
|
|
{
|
|
|
|
|
Code umeta_UFUNCTION = code_str( UFUNCTION() );
|
|
|
|
|
|
|
|
|
|
body.append(fmt_newline);
|
|
|
|
|
body.append( umeta_UFUNCTION );
|
|
|
|
|
body.append(fmt_newline);
|
|
|
|
|
body.append( code_fmt( "property", (StrC)property, stringize(
|
|
|
|
|
void Client_OnRep_<property>(FGameplayAttributeData& Prev<property>);
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void def_attribute_field_property_getters( CodeBody body, StrC class_name, Array<StringCached> properties )
|
|
|
|
|
{
|
|
|
|
|
for ( String property : properties )
|
|
|
|
|
{
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 06:51:51 -07:00
|
|
|
|
#pragma push_macro("FORCEINLINE")
|
|
|
|
|
#undef FORCEINLINE
|
2024-04-14 18:51:14 -07:00
|
|
|
|
void def_attribute_field_value_getters( CodeBody body, Array<StringCached> properties )
|
|
|
|
|
{
|
|
|
|
|
for ( String property : properties )
|
|
|
|
|
{
|
|
|
|
|
body.append( code_fmt( "property", (StrC)property,
|
|
|
|
|
stringize(
|
|
|
|
|
FORCEINLINE float Get<property>() const
|
|
|
|
|
{
|
|
|
|
|
return <property>.GetCurrentValue();
|
|
|
|
|
}
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void def_attribute_field_value_setters( CodeBody body, Array<StringCached> properties )
|
|
|
|
|
{
|
|
|
|
|
for ( String property : properties )
|
|
|
|
|
{
|
|
|
|
|
body.append( code_fmt( "property", (StrC)property,
|
|
|
|
|
stringize(
|
2024-04-21 15:56:57 -07:00
|
|
|
|
FORCEINLINE void Set<property>(float NewVal);
|
2024-04-14 18:51:14 -07:00
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-21 15:56:57 -07:00
|
|
|
|
void def_attribute_field_property_setter_inlines( CodeBody body, StrC class_name, Array<StringCached> properties )
|
|
|
|
|
{
|
2024-04-22 22:10:02 -07:00
|
|
|
|
body.append(def_pragma( txt("region Attribute Setters")));
|
2024-04-21 15:56:57 -07:00
|
|
|
|
for ( String property : properties )
|
|
|
|
|
{
|
|
|
|
|
CodeFn generated_get_attribute = parse_function(
|
|
|
|
|
token_fmt( "class_name", class_name, "property", (StrC)property,
|
|
|
|
|
stringize(
|
|
|
|
|
FORCEINLINE void <class_name>::Set<property>(float NewVal)
|
|
|
|
|
{
|
|
|
|
|
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
|
|
|
|
|
if (ensure(AbilityComp))
|
|
|
|
|
{
|
|
|
|
|
AbilityComp->SetNumericAttributeBase(Get<property>Attribute(), NewVal);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)));
|
|
|
|
|
body.append( generated_get_attribute );
|
|
|
|
|
}
|
2024-04-22 22:10:02 -07:00
|
|
|
|
body.append(def_pragma( txt("endregion Attribute Setters")));
|
2024-04-21 15:56:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-14 18:51:14 -07:00
|
|
|
|
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 )
|
|
|
|
|
{
|
2024-04-22 22:10:02 -07:00
|
|
|
|
body.append(fmt_newline);
|
2024-04-22 09:01:30 -07:00
|
|
|
|
body.append(def_pragma( txt("region Rep Notifies")));
|
2024-04-14 18:51:14 -07:00
|
|
|
|
for ( String property : properties )
|
|
|
|
|
{
|
2024-04-22 09:01:30 -07:00
|
|
|
|
CodeFn field_impl = parse_function( token_fmt(
|
|
|
|
|
"class_name", class_name, "property", (StrC)property, "from_notice", txt("\n// From GAMEPLAYATTRIBUTE_REPNOTIFY\n"),
|
2024-04-14 18:51:14 -07:00
|
|
|
|
stringize(
|
|
|
|
|
void <class_name>::Client_OnRep_<property>(FGameplayAttributeData& Prev<property>)
|
|
|
|
|
{
|
2024-04-22 09:01:30 -07:00
|
|
|
|
<from_notice>
|
|
|
|
|
static FProperty* <class_name>Property = FindFieldChecked<FProperty>( StaticClass(), GET_MEMBER_NAME_CHECKED(<class_name>, <property>));
|
|
|
|
|
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(<class_name>Property), <property>, Prev<property>);
|
2024-04-14 18:51:14 -07:00
|
|
|
|
}
|
|
|
|
|
)));
|
|
|
|
|
|
|
|
|
|
body.append( field_impl );
|
|
|
|
|
}
|
2024-04-22 09:01:30 -07:00
|
|
|
|
body.append( def_pragma( txt("endregion Rep Notifies")));
|
2024-04-22 22:10:02 -07:00
|
|
|
|
body.append(fmt_newline);
|
2024-04-22 09:01:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
Code gen_GAMEPLAYATTRIBUTE_REPNOTIFY(StrC class_name, StrC property_name, StrC old_value)
|
|
|
|
|
{
|
|
|
|
|
Code rep_notify = code_fmt(
|
|
|
|
|
"class_name", class_name
|
|
|
|
|
, "property_name", property_name
|
|
|
|
|
, "old_value", old_value,
|
|
|
|
|
stringize(
|
|
|
|
|
static FProperty* <class_name>Property = FindFieldChecked<FProperty>(<class_name>::StaticClass(), GET_MEMBER_NAME_CHECKED(<class_name>, <property_name>));
|
|
|
|
|
GetOwningAbilitySystemComponentChecked()->SetBaseAttributeValueFromReplication(FGameplayAttribute(<class_name>Property), <property_name>, <old_value>);
|
|
|
|
|
));
|
2024-04-14 18:51:14 -07:00
|
|
|
|
}
|
2024-04-21 06:51:51 -07:00
|
|
|
|
#pragma pop_macro("FORCEINLINE")
|