From 686e70994b89d69cfc2442632eb6336efb587c4e Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Sat, 24 Jan 2026 03:57:37 +0100 Subject: [PATCH] gf sad fix + AliasMacro (for backwards comp, manual impl for now) --- assets/data/characters/gf.xml | 24 ++-- .../backend/system/macros/AliasMacro.hx | 134 ++++++++++++++++++ 2 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 source/funkin/backend/system/macros/AliasMacro.hx diff --git a/assets/data/characters/gf.xml b/assets/data/characters/gf.xml index dc3953fa..ae810a73 100644 --- a/assets/data/characters/gf.xml +++ b/assets/data/characters/gf.xml @@ -1,14 +1,14 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/source/funkin/backend/system/macros/AliasMacro.hx b/source/funkin/backend/system/macros/AliasMacro.hx new file mode 100644 index 00000000..227c9f76 --- /dev/null +++ b/source/funkin/backend/system/macros/AliasMacro.hx @@ -0,0 +1,134 @@ +package funkin.backend.system.macros; + +#if macro +import sys.io.File; +import haxe.macro.ComplexTypeTools; +import haxe.macro.Printer; +import haxe.macro.Expr.Position; +import haxe.macro.Context; +import haxe.macro.Expr.Field; +import haxe.macro.Expr; + +class AliasMacro { + public static var aliasMetadata:Metadata = [{ + name: ":keep", + pos: Context.currentPos() + },{ + name: ":dox", + pos: Context.currentPos(), + params: [ + { + expr: EConst(CIdent("hide")), + pos: Context.currentPos() + } + ] + }]; + + public static function build():Array { + #if display + return Context.getBuildFields(); + #end + + var fields = Context.getBuildFields(); + var ogFieldCount = fields.length; + + for(i in 0...ogFieldCount) { + var field = fields[i]; + if (field.meta == null) continue; + + var previousAliases:Array<{name:String, pos:Position}> = []; + for(meta in field.meta) { + if (meta.name == ":alias" && meta.params != null) { + for(p in meta.params) { + switch(p.expr) { + case EConst(CString(s, kind)): + previousAliases.push({ + name: s, + pos: p.pos + }); + default: + } + } + } + } + + if (previousAliases.length == 0) continue; + + var ghostAccess = field.access.copy(); + ghostAccess.remove(AOverride); + ghostAccess.remove(APublic); + + for(alias in previousAliases) { + var ghostField:Field = { + name: alias.name, + pos: alias.pos, + kind: null, + access: ghostAccess, + meta: aliasMetadata + }; + + switch(field.kind) { + case FFun(f): + var args:Array = [for(a in f.args) { + expr: EConst(CIdent(a.name)), + pos: Context.currentPos() + }]; + + ghostField.kind = FFun({ + args: f.args, + params: f.params, + ret: f.ret, + expr: macro return $i{field.name}($a{args}) + }); + + default: + var type = null; + switch(field.kind) { + case FVar(t, e): + type = t; + case FProp(get, set, t, e): + type = t; + default: + } + ghostField.kind = FProp("get", "set", type, null); + + fields.push({ + name: 'get_${alias.name}', + kind: FFun({ + args: [], + expr: macro return $i{field.name}, + ret: type + }), + pos: alias.pos, + meta: aliasMetadata + }); + fields.push({ + name: 'set_${alias.name}', + kind: FFun({ + args: [{ + name: '_${field.name}', + type: type + }], + expr: macro return ($i{field.name} = $i{'_${field.name}'}), + ret: type + }), + pos: alias.pos, + meta: aliasMetadata + }); + } + + fields.push(ghostField); + } + + var docFooter = '_Aliases: ${[for(alias in previousAliases) '`${alias.name}`'].join(", ")}_'; + if (field.doc != null) + field.doc += '\n\n$docFooter'; + else + field.doc = docFooter; + } + trace(fields); + + return fields; + } +} +#end \ No newline at end of file