GASATHON/Project/Source/GasaGen/GasaGen_HostWidgetController.cpp

308 lines
8.8 KiB
C++
Raw Permalink Normal View History

2024-04-21 22:54:33 -07:00
#if GASA_INTELLISENSE_DIRECTIVES
#pragma once
#define GEN_EXPOSE_BACKEND
#include "gen.hpp"
#include "gen.builder.hpp"
#include "GasaGenCommon.cpp"
2024-04-24 15:18:26 -07:00
#include "GasaGen_UGasaAttributeSet.cpp"
2024-04-21 22:54:33 -07:00
#endif
void gen_UHostWidgetController()
{
Array<GAS_AttributeEntry> attribute_fields = get_gasa_vital_attribute_fields();
2024-04-21 22:54:33 -07:00
CodeBody ori_HostWidgetController_header = parse_file(path_gasa_ui "HostWidgetController.h");
{
CodeBody header_body = def_body(ECode::Global_Body);
StrC str_UHostWidgetController = txt("UHostWidgetController");
CodeClass ori_UHostWidgetController = NoCode;
Code file_code = ori_HostWidgetController_header.begin();
for ( ; file_code != ori_HostWidgetController_header.end(); ++ file_code )
{
if (s32 never_enter = 0; never_enter)
found: break;
switch (file_code->Type)
{
default:
header_body.append(file_code);
continue;
case ECode::Class:
if ( ! file_code->Name.starts_with(str_UHostWidgetController))
continue;
ori_UHostWidgetController = file_code.cast<CodeClass>();
++ file_code;
goto found;
case ECode::Preprocess_Include:
header_body.append(file_code);
if ( file_code->Content.starts_with(txt("HostWidgetController.generated.h")))
{
header_body.append(fmt_newline);
header_body.append(fmt_newline);
}
continue;
case ECode::Untyped:
header_body.append(file_code);
if (file_code->Content.starts_with( txt("DECLARE_"))
|| file_code->Content.starts_with( txt("UCLASS"))
)
header_body.append(fmt_newline);
continue;
}
}
CodeBody attribute_events = def_body(ECode::Class_Body);
{
attribute_events.append( def_comment( txt("Attribute Events are generated by GasaGen/GasaGen_HostWidgetController.cpp")));
attribute_events.append(fmt_newline);
for ( s32 id = 0; id < attribute_fields.num(); ++id )
{
2024-04-24 15:18:26 -07:00
GAS_AttributeEntry attribute_field = attribute_fields[id];
2024-04-21 22:54:33 -07:00
attribute_events.append( code_str(
UPROPERTY(BlueprintAssignable, Category = "Attributes")
));
attribute_events.append(fmt_newline);
attribute_events.append( parse_variable(
token_fmt( "field", (StrC) attribute_field.Name, stringize( FAttributeChangedSig Event_On<field>Changed; ))
2024-04-21 22:54:33 -07:00
));
attribute_events.append(fmt_newline);
}
for ( s32 id = 0; id < attribute_fields.num(); ++id )
{
2024-04-24 15:18:26 -07:00
StringCached attribute_field = attribute_fields[id].Name;
2024-04-21 22:54:33 -07:00
attribute_events.append( parse_function(
token_fmt( "field", (StrC) attribute_field, stringize( void <field>Changed(FOnAttributeChangeData const& Data); ))
));
}
}
CodeClass new_UHostWidgetController = ori_UHostWidgetController.duplicate().cast<CodeClass>();
CodeBody new_body = def_body(ECode::Class_Body);
for (Code code = ori_UHostWidgetController->Body.begin();
code != ori_UHostWidgetController->Body.end();
++ code )
{
switch (code->Type)
{
default:
new_body.append(code);
continue;
case ECode::Preprocess_Pragma:
{
local_persist bool found = false;
if (found)
{
new_body.append(code);
continue;
}
CodePragma pragma = code.cast<CodePragma>();
if ( pragma->Content.starts_with(txt("region Attribute Events")) )
{
new_body.append(pragma);
++ code;
new_body.append(attribute_events);
while (code->Type != ECode::Preprocess_Pragma
|| ! code->Content.starts_with(txt("endregion Attribute Events")))
++ code;
new_body.append( code );
found = true;
}
}
break;
case ECode::Untyped:
new_body.append(code);
if (code->Content.starts_with( txt("GENERATED_BODY")))
new_body.append(fmt_newline);
}
}
new_body.append(fmt_newline);
new_UHostWidgetController->Body = new_body;
header_body.append(new_UHostWidgetController);
for (; file_code != ori_HostWidgetController_header.end(); ++ file_code)
{
header_body.append(file_code);
}
Builder header = Builder::open(path_gasa_ui "HostWidgetController.h");
header.print(header_body);
header.write();
format_file(path_gasa_ui "HostWidgetController.h");
}
CodeBody ori_HostWidgetController_source = parse_file(path_gasa_ui "HostWidgetController.cpp");
{
CodeBody source_body = def_body(ECode::Global_Body);
CodeFn BroadcastInitialValues = NoCode;
{
CodeBody broadcast_calls = def_body(ECode::Function_Body);
2024-04-24 15:18:26 -07:00
for (GAS_AttributeEntry field : attribute_fields)
2024-04-21 22:54:33 -07:00
{
2024-04-24 15:18:26 -07:00
broadcast_calls.append( code_fmt( "field", (StrC)field.Name,
2024-04-21 22:54:33 -07:00
stringize( Event_On<field>Changed.Broadcast( GasaAttribs->Get<field>() ); )
));
}
BroadcastInitialValues = parse_function( token_fmt(
"broadcast_calls", (StrC)broadcast_calls.to_string(),
"generation_notice", txt("\n// This function is managed by: GenGasa/GenGasa_HostWidgetController.cpp\n\n"),
stringize(
void UHostWidgetController::BroadcastInitialValues()
{
<generation_notice>
UGasaAttributeSet* GasaAttribs = Cast<UGasaAttributeSet>(Data.Attributes);
if (GasaAttribs)
{
<broadcast_calls>
}
BindCallbacksToDependencies();
})
));
}
CodeFn BindCallbacksToDependencies = NoCode;
{
CodeBody bindings = def_body(ECode::Function_Body);
bindings.append(fmt_newline);
bindings.append(fmt_newline);
2024-04-24 15:18:26 -07:00
for (GAS_AttributeEntry field : attribute_fields)
2024-04-21 22:54:33 -07:00
{
2024-04-24 15:18:26 -07:00
bindings.append( code_fmt( "field", (StrC)field.Name,
2024-04-21 22:54:33 -07:00
stringize(
FOnGameplayAttributeValueChange& <field>AttributeChangedDelegate = AbilitySystem->GetGameplayAttributeValueChangeDelegate(GasaAttribs->Get<field>Attribute());
<field>AttributeChangedDelegate.AddUObject(this, &ThisClass::<field>Changed);
)));
bindings.append(fmt_newline);
bindings.append(fmt_newline);
}
BindCallbacksToDependencies = parse_function( token_fmt(
"generation_notice", txt("\n// This function is managed by: GenGasa/GenGasa_HostWidgetController.cpp\n\n"),
"bindings", (StrC)bindings.to_string(),
stringize(
void UHostWidgetController::BindCallbacksToDependencies()
{
<generation_notice>
UGasaAbilitySystemComp* AbilitySystem = Cast<UGasaAbilitySystemComp>(Data.AbilitySystem);
UGasaAttributeSet* GasaAttribs = Cast<UGasaAttributeSet>( Data.Attributes );
<bindings>
2024-04-26 17:08:08 -07:00
AbilitySystem->Event_OnEffectAppliedAssetTags.AddUObject(this, & UHostWidgetController::OnEffectAppliedAssetTags);
2024-04-21 22:54:33 -07:00
})
));
}
CodeBody attribute_callbacks = def_body(ECode::Global_Body);
{
attribute_callbacks.append( def_comment(txt("Attribute Changed Callbacks are generated by GasaGen/GasaGen_HostWidgetController.cpp")));
attribute_callbacks.append(fmt_newline);
for ( s32 id = 0; id < attribute_fields.num(); )
{
2024-04-24 15:18:26 -07:00
StringCached attribute_field = attribute_fields[id].Name;
2024-04-21 22:54:33 -07:00
attribute_callbacks.append( parse_function( token_fmt(
"field", (StrC) attribute_field,
stringize(
void UHostWidgetController::<field>Changed(FOnAttributeChangeData const& Attribute)
{
Event_On<field>Changed.Broadcast(Attribute.NewValue);
})
)));
++ id;
if ( id < attribute_fields.num() )
{
attribute_callbacks.append(fmt_newline);
}
}
}
for ( Code code = ori_HostWidgetController_source.begin();
code != ori_HostWidgetController_source.end();
++ code
)
{
switch (code->Type)
{
case ECode::Preprocess_Pragma:
{
local_persist bool found = false;
if (found)
{
source_body.append(code);
++ code;
continue;
}
CodePragma pragma = code.cast<CodePragma>();
if ( pragma->Content.starts_with(txt("region Attribute Changed Callbacks")) )
{
source_body.append(fmt_newline);
source_body.append(pragma);
++ code;
source_body.append(attribute_callbacks);
while (code->Type != ECode::Preprocess_Pragma
|| ! code->Content.starts_with(txt("endregion Attribute Changed Callbacks")))
++ code;
found = true;
}
}
break;
case ECode::Function:
CodeFn function_def = code.cast<CodeFn>();
if ( String::are_equal(function_def->Name, BroadcastInitialValues->Name)
&& function_def->Params.is_equal(BroadcastInitialValues->Params))
{
source_body.append(BroadcastInitialValues);
log_fmt("Swapped: %S\n", BroadcastInitialValues->Name);
continue;
}
else if (String::are_equal(function_def->Name, BindCallbacksToDependencies->Name)
&& function_def->Params.is_equal(BindCallbacksToDependencies->Params))
{
source_body.append(BindCallbacksToDependencies);
log_fmt("Swapped: %S\n", BindCallbacksToDependencies->Name);
continue;
}
break;
}
source_body.append(code);
}
Builder source = Builder::open(path_gasa_ui "HostWidgetController.cpp");
source.print(source_body);
source.write();
format_file(path_gasa_ui "HostWidgetController.cpp");
}
2024-04-22 09:01:30 -07:00
}