Funkin/source/funkin/util/macro/FlxMacro.hx

38 lines
1.3 KiB
Haxe
Raw Normal View History

package funkin.util.macro;
2022-01-26 14:19:57 -05:00
2023-12-07 14:29:45 -05:00
#if !display
2022-01-26 14:19:57 -05:00
#if macro
class FlxMacro
{
/**
* A macro to be called targeting the `FlxBasic` class.
* @return An array of fields that the class contains.
*/
public static macro function buildFlxBasic():Array<haxe.macro.Expr.Field>
{
var pos:haxe.macro.Expr.Position = haxe.macro.Context.currentPos();
// The FlxBasic class. We can add new properties to this class.
var cls:haxe.macro.Type.ClassType = haxe.macro.Context.getLocalClass().get();
// The fields of the FlxClass.
var fields:Array<haxe.macro.Expr.Field> = haxe.macro.Context.getBuildFields();
2022-01-26 14:19:57 -05:00
// haxe.macro.Context.info('[INFO] ${cls.name}: Adding zIndex attribute...', pos);
2022-01-26 14:19:57 -05:00
// Here, we add the zIndex attribute to all FlxBasic objects.
// This has no functional code tied to it, but it can be used as a target value
// for the FlxTypedGroup.sort method, to rearrange the objects in the scene.
fields = fields.concat([
{
name: "zIndex", // Field name.
access: [haxe.macro.Expr.Access.APublic], // Access level
2023-06-08 16:30:45 -04:00
kind: haxe.macro.Expr.FieldType.FVar(macro :Int, macro $v{0}), // Variable type and default value
pos: pos, // The field's position in code.
}
]);
2022-01-26 14:19:57 -05:00
return fields;
}
2022-01-26 14:19:57 -05:00
}
#end
2023-12-07 14:29:45 -05:00
#end