Skip to content

Commit

Permalink
Added "group" for (set/get)ObjectOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowMario committed Oct 2, 2024
1 parent 9569db6 commit 3d03026
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
70 changes: 51 additions & 19 deletions source/psychlua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import openfl.utils.Assets;
import openfl.display.BitmapData;
import flixel.FlxBasic;
import flixel.FlxObject;
import flixel.FlxState;

#if (!flash && sys)
import flixel.addons.display.FlxRuntimeShader;
Expand Down Expand Up @@ -421,33 +422,64 @@ class FunkinLua {
});

//shitass stuff for epic coders like me B) *image of obama giving himself a medal*
Lua_helper.add_callback(lua, "getObjectOrder", function(obj:String) {
var split:Array<String> = obj.split('.');
var leObj:FlxBasic = LuaUtils.getObjectDirectly(split[0]);
if(split.length > 1) {
leObj = LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split), split[split.length-1]);
}

Lua_helper.add_callback(lua, "getObjectOrder", function(obj:String, ?group:String = null) {
var leObj:FlxSprite = LuaUtils.getObjectDirectly(obj);
if(leObj != null)
{
if(group != null)
{
var groupOrArray:Dynamic = Reflect.getProperty(LuaUtils.getTargetInstance(), group);
if(groupOrArray != null)
{
switch(Type.typeof(groupOrArray))
{
case TClass(Array): //Is Array
return groupOrArray.indexOf(leObj);
default: //Is Group
return Reflect.getProperty(groupOrArray, 'members').indexOf(leObj); //Has to use a Reflect here because of FlxTypedSpriteGroup
}
}
else
{
luaTrace('getObjectOrder: Group $group doesn\'t exist!', false, false, FlxColor.RED);
return -1;
}
}
return LuaUtils.getTargetInstance().members.indexOf(leObj);
}
luaTrace("getObjectOrder: Object " + obj + " doesn't exist!", false, false, FlxColor.RED);
luaTrace('getObjectOrder: Object $obj doesn\'t exist!', false, false, FlxColor.RED);
return -1;
});
Lua_helper.add_callback(lua, "setObjectOrder", function(obj:String, position:Int) {
var split:Array<String> = obj.split('.');
var leObj:FlxBasic = LuaUtils.getObjectDirectly(split[0]);
if(split.length > 1) {
leObj = LuaUtils.getVarInArray(LuaUtils.getPropertyLoop(split), split[split.length-1]);
}

if(leObj != null) {
LuaUtils.getTargetInstance().remove(leObj, true);
LuaUtils.getTargetInstance().insert(position, leObj);
Lua_helper.add_callback(lua, "setObjectOrder", function(obj:String, position:Int, ?group:String = null) {
var leObj:FlxSprite = LuaUtils.getObjectDirectly(obj);
if(leObj != null)
{
if(group != null)
{
var groupOrArray:Dynamic = Reflect.getProperty(LuaUtils.getTargetInstance(), group);
if(groupOrArray != null)
{
switch(Type.typeof(groupOrArray))
{
case TClass(Array): //Is Array
groupOrArray.remove(leObj);
groupOrArray.insert(position, leObj);
default: //Is Group
groupOrArray.remove(leObj, true);
groupOrArray.insert(position, leObj);
}
}
else luaTrace('setObjectOrder: Group $group doesn\'t exist!', false, false, FlxColor.RED);
}
else
{
var groupOrArray:FlxState = LuaUtils.getTargetInstance();
groupOrArray.remove(leObj, true);
groupOrArray.insert(position, leObj);
}
return;
}
luaTrace("setObjectOrder: Object " + obj + " doesn't exist!", false, false, FlxColor.RED);
luaTrace('setObjectOrder: Object $obj doesn\'t exist!', false, false, FlxColor.RED);
});

// gay ass tweens
Expand Down
6 changes: 3 additions & 3 deletions source/psychlua/HScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ class HScript extends Iris
try
{
final callValue:IrisCall = call(funcToRun, funcArgs);
return callValue.signature;
return callValue.returnValue;
}
catch(e:Dynamic)
{
Expand All @@ -361,7 +361,7 @@ class HScript extends Iris
final retVal:IrisCall = funk.hscript.executeCode(funcToRun, funcArgs);
if (retVal != null)
{
return (retVal.signature == null || LuaUtils.isOfTypes(retVal.signature, [Bool, Int, Float, String, Array])) ? retVal.signature : null;
return (retVal.returnValue == null || LuaUtils.isOfTypes(retVal.returnValue, [Bool, Int, Float, String, Array])) ? retVal.returnValue : null;
}
}
catch(e:Dynamic)
Expand All @@ -382,7 +382,7 @@ class HScript extends Iris
final retVal:IrisCall = funk.hscript.executeFunction(funcToRun, funcArgs);
if (retVal != null)
{
return (retVal.signature == null || LuaUtils.isOfTypes(retVal.signature, [Bool, Int, Float, String, Array])) ? retVal.signature : null;
return (retVal.returnValue == null || LuaUtils.isOfTypes(retVal.returnValue, [Bool, Int, Float, String, Array])) ? retVal.returnValue : null;
}
}
catch(e:Dynamic)
Expand Down
2 changes: 1 addition & 1 deletion source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3360,7 +3360,7 @@ class PlayState extends MusicBeatState
try
{
var callValue = script.call(funcToCall, args);
var myValue:Dynamic = callValue.signature;
var myValue:Dynamic = callValue.returnValue;

if((myValue == LuaUtils.Function_StopHScript || myValue == LuaUtils.Function_StopAll) && !excludeValues.contains(myValue) && !ignoreStops)
{
Expand Down

0 comments on commit 3d03026

Please sign in to comment.