1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-29 02:04:28 +00:00

Added zIndex via macro.

This commit is contained in:
Eric Myllyoja 2022-01-26 14:19:57 -05:00
parent eda3a2b809
commit 71ca1f8d3a
6 changed files with 82 additions and 1 deletions

View file

@ -193,6 +193,11 @@
<icon path="art/icon64.png" size='64'/> <icon path="art/icon64.png" size='64'/>
<icon path="art/iconOG.png" /> <icon path="art/iconOG.png" />
<!--
aww yeah hackerman time, run a macro on the class rather than edit it
took me a while to get this working but turns out the classname comes SECOND
-->
<haxeflag name="--macro" value="addMetadata('@:build(util.macro.FlxMacro.buildFlxBasic())', 'flixel.FlxBasic')" />
<!-- <haxedef name="SKIP_TO_PLAYSTATE" if="debug" /> --> <!-- <haxedef name="SKIP_TO_PLAYSTATE" if="debug" /> -->

View file

@ -188,6 +188,8 @@ class TitleState extends MusicBeatState
gfDance.antialiasing = true; gfDance.antialiasing = true;
add(gfDance); add(gfDance);
trace('MACRO TEST: ${gfDance.zIndex}');
// alphaShader.shader.funnyShit.input = gfDance.pixels; // old shit // alphaShader.shader.funnyShit.input = gfDance.pixels; // old shit
logoBl.shader = alphaShader.shader; logoBl.shader = alphaShader.shader;

View file

@ -1,2 +1,6 @@
#if !macro
// Only import these when we aren't in a macro.
import Paths; import Paths;
import flixel.FlxG; import flixel.FlxG; // This one in particular causes a compile error if you're using macros.
#end

View file

@ -0,0 +1,9 @@
package play.stage;
import flixel.FlxObject;
import flixel.group.FlxGroup.FlxTypedGroup;
/**
* A Stage is a group of objects.
*/
class Stage extends FlxTypedGroup<FlxObject> {}

26
source/util/SortUtil.hx Normal file
View file

@ -0,0 +1,26 @@
package util;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.util.FlxSort;
import flixel.FlxObject;
class SortUtil
{
/**
* You can use this function in FlxTypedGroup.sort() to sort FlxObjects by their z-index values.
* The value defaults to 0, but by assigning it you can easily rearrange objects as desired.
*/
public static inline function byZIndex(Order:Int, Obj1:FlxObject, Obj2:FlxObject):Int
{
return FlxSort.byValues(Order, Obj1.zIndex, Obj2.zIndex);
}
/**
* Sorts the element in an FlxTypedGroup by their z-index values.
* @param group The group to sort.
*/
public static inline function sortByZIndex(group:FlxTypedGroup<FlxObject>)
{
group.sort(byZIndex, FlxSort.ASCENDING);
}
}

View file

@ -0,0 +1,35 @@
package util.macro;
#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();
haxe.macro.Context.info('[INFO] ${cls.name}: Adding zIndex attribute...', pos);
// 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
kind: haxe.macro.Expr.FieldType.FVar(macro:Int, macro $v{0}), // Variable type and default value
pos: pos, // The field's position in code.
}
]);
return fields;
}
}
#end