From 968ec3003c2a0e32c84d26dd010ac43ba5444a39 Mon Sep 17 00:00:00 2001 From: LarryFrosty Date: Sun, 8 Sep 2024 16:14:07 +0800 Subject: [PATCH] someone kill me --- source/Main.hx | 24 ------------- source/psychlua/HScript.hx | 74 +++++++++----------------------------- source/states/PlayState.hx | 2 +- 3 files changed, 18 insertions(+), 82 deletions(-) diff --git a/source/Main.hx b/source/Main.hx index 96dab699..7f7f569b 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -139,30 +139,6 @@ class Main extends Sprite fpsVar.visible = ClientPrefs.data.showFPS; } - #if HSCRIPT_ALLOWED - crowplexus.iris.Iris.logLevel = function(level:crowplexus.iris.ErrorSeverity, x, ?pos:haxe.PosInfos):Void { - if (pos == null) { - pos = { - fileName: "hscript-iris", - lineNumber: -1, - className: "UnknownClass", - methodName: "unknownFunction", - customParams: null - } - } - - var errorMsg = 'ERROR (${pos.fileName})'; - if (pos.lineNumber != -1) - errorMsg += ':${pos.lineNumber}'; - errorMsg += ' - ${x}'; - - if (PlayState.instance != null) { - PlayState.instance.addTextToDebug(errorMsg, FlxColor.RED); - } - trace(errorMsg); - } - #end - #if linux var icon = Image.fromFile("icon.png"); Lib.current.stage.window.setIcon(icon); diff --git a/source/psychlua/HScript.hx b/source/psychlua/HScript.hx index b81a9189..10f0cdda 100644 --- a/source/psychlua/HScript.hx +++ b/source/psychlua/HScript.hx @@ -41,13 +41,13 @@ class HScript extends Iris } else { - try - { - hs.executeScript(code, varsToBring); + hs.varsToBring = varsToBring; + try { + hs.scriptCode = code; + hs.execute(); } - catch(e:Dynamic) - { - Iris.error(e, hs.interp.posInfos()); + catch(e:Dynamic) { + PlayState.instance.addTextToDebug('ERROR ON LOADING (${hs.origin}):${hs.interp.posInfos().lineNumber} - ${e}', FlxColor.RED); } } } @@ -90,9 +90,11 @@ class HScript extends Iris scriptThing = File.getContent(f); } } + scriptCode = scriptThing; + this.varsToBring = varsToBring; preset(); - executeScript(scriptThing, varsToBring); + execute(); } var varsToBring(default, set):Any = null; @@ -113,8 +115,6 @@ class HScript extends Iris set('Countdown', backend.BaseStage.Countdown); set('PlayState', PlayState); set('Paths', Paths); - set('StorageUtil', StorageUtil); - set('MobileControls', mobile.objects.MobileControls); set('Conductor', Conductor); set('ClientPrefs', ClientPrefs); #if ACHIEVEMENTS_ALLOWED @@ -265,7 +265,7 @@ class HScript extends Iris { if(funk == null) funk = parentLua; - if(parentLua != null) funk.addLocalCallback(name, func); + if(funk != null) funk.addLocalCallback(name, func); else FunkinLua.luaTrace('createCallback ($name): 3rd argument is null', false, false, FlxColor.RED); }); #end @@ -321,48 +321,6 @@ class HScript extends Iris set('addBehindDad', PlayState.instance.addBehindDad); set('addBehindBF', PlayState.instance.addBehindBF); } - #if LUA_ALLOWED - set("addTouchPad", (DPadMode:String, ActionMode:String) -> { - PlayState.instance.makeLuaTouchPad(DPadMode, ActionMode); - PlayState.instance.addLuaTouchPad(); - }); - - set("removeTouchPad", () -> { - PlayState.instance.removeLuaTouchPad(); - }); - - set("addTouchPadCamera", () -> { - if(PlayState.instance.luaTouchPad == null){ - FunkinLua.luaTrace('addTouchPadCamera: VPAD does not exist.'); - return; - } - PlayState.instance.addLuaTouchPadCamera(); - }); - - set("touchPadJustPressed", function(button:Dynamic):Bool { - if(PlayState.instance.luaTouchPad == null){ - //FunkinLua.luaTrace('touchPadJustPressed: VPAD does not exist.'); - return false; - } - return PlayState.instance.luaTouchPadJustPressed(button); - }); - - set("touchPadPressed", function(button:Dynamic):Bool { - if(PlayState.instance.luaTouchPad == null){ - //FunkinLua.luaTrace('touchPadPressed: VPAD does not exist.'); - return false; - } - return PlayState.instance.luaTouchPadPressed(button); - }); - - set("touchPadJustReleased", function(button:Dynamic):Bool { - if(PlayState.instance.luaTouchPad == null){ - //FunkinLua.luaTrace('touchPadJustReleased: VPAD does not exist.'); - return false; - } - return PlayState.instance.luaTouchPadJustReleased(button); - }); - #end } public function executeCode(?funcToRun:String = null, ?funcArgs:Array = null):IrisCall { @@ -473,12 +431,14 @@ class HScript extends Iris } #end - public function executeScript(code:String, ?varsToBring:Any = null):Dynamic - { - this.varsToBring = varsToBring; - scriptCode = code; + override function execute():Dynamic { + if (interp == null) + throw "Attempt to run script failed, script is probably destroyed."; + parse(true); - return returnValue = execute(); + Iris.instances.set(this.name, this); + var value = interp.execute(expr); + return returnValue = value; } /*override function irisPrint(v):Void diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index 269bc1f4..0daf71f2 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -3284,7 +3284,7 @@ class PlayState extends MusicBeatState { var newScript:HScript = cast (Iris.instances.get(file), HScript); @:privateAccess - Iris.error(e, (newScript.interp != null ? newScript.interp.posInfos() : Iris.getDefaultPos())); + addTextToDebug('ERROR ON LOADING (${file}):${newScript.interp.posInfos().lineNumber} - ${e}', FlxColor.RED); if(newScript != null) newScript.destroy();