From 9b7066778b32d79fe120b8a4e65f90b274d12299 Mon Sep 17 00:00:00 2001 From: Joalor64 Date: Tue, 15 Oct 2024 13:49:08 -0400 Subject: [PATCH] huh?? --- source/backend/Paths.hx | 2 +- source/states/ScriptedState.hx | 38 ++++++++++++++++++-------- source/substates/ScriptedSubState.hx | 40 +++++++++++++++++++--------- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/source/backend/Paths.hx b/source/backend/Paths.hx index 89955ec..3f6467c 100644 --- a/source/backend/Paths.hx +++ b/source/backend/Paths.hx @@ -212,7 +212,7 @@ class Paths { else tempFramesCache.remove(key); } - return tempFramesCache[key] = loadFrames(assetsPath ? key : imageAlt(key)); + return tempFramesCache[key] = loadFrames(assetsPath ? key : Paths.imageAlt(key)); } static function loadFrames(path:String, Unique:Bool = false, Key:String = null, SkipAtlasCheck:Bool = false):FlxFramesCollection { diff --git a/source/states/ScriptedState.hx b/source/states/ScriptedState.hx index 92ae0f1..a42d9af 100644 --- a/source/states/ScriptedState.hx +++ b/source/states/ScriptedState.hx @@ -6,25 +6,31 @@ class ScriptedState extends ExtendableState { public function new(path:String, ?args:Array) { super(); - script = new Hscript(Paths.script('classes/$path')); + try { + script = new Hscript(Paths.script('classes/$path')); + } catch (e:Dynamic) { + trace('Error while getting script!\n$e'); + ExtendableState.switchState(new TitleState()); + } - script.setVariable('state', this); - script.setVariable('add', function(obj:FlxBasic) { + scriptSet('state', this); + + scriptSet('add', function(obj:FlxBasic) { add(obj); }); - script.setVariable('remove', function(obj:FlxBasic) { + scriptSet('remove', function(obj:FlxBasic) { remove(obj); }); - script.setVariable('insert', function(pos:Int, obj:FlxBasic) { + scriptSet('insert', function(pos:Int, obj:FlxBasic) { insert(pos, obj); }); - script.executeFunc('new', (args != null) ? args : []); + scriptExecute('new', (args != null) ? args : []); } override function draw() { super.draw(); - script.executeFunc('draw', []); + scriptExecute('draw', []); } override function create() { @@ -36,21 +42,31 @@ class ScriptedState extends ExtendableState { override function update(elapsed:Float) { super.update(elapsed); - script.executeFunc('update', [elapsed]); + scriptExecute('update', [elapsed]); } override function beatHit() { super.beatHit(); - script.executeFunc('beatHit', [curBeat]); + scriptExecute('beatHit', [curBeat]); } override function stepHit() { super.stepHit(); - script.executeFunc('stepHit', [curStep]); + scriptExecute('stepHit', [curStep]); } override function destroy() { super.destroy(); - script.executeFunc('destroy', []); + scriptExecute('destroy', []); + } + + function scriptExecute(func:String, args:Array) { + if (script != null) + script.executeFunc(func, args); + } + + function scriptSet(key:String, value:Dynamic) { + if (script != null) + script.setVariable(key, value); } } \ No newline at end of file diff --git a/source/substates/ScriptedSubState.hx b/source/substates/ScriptedSubState.hx index 52b1a3d..4d31d67 100644 --- a/source/substates/ScriptedSubState.hx +++ b/source/substates/ScriptedSubState.hx @@ -6,27 +6,31 @@ class ScriptedSubState extends ExtendableSubState { public function new(path:String, ?args:Array) { super(); - script = new Hscript(Paths.script('classes/$path')); + try { + script = new Hscript(Paths.script('classes/$path')); + } catch (e:Dynamic) { + trace('Error while getting script!\n$e'); + ExtendableState.switchState(new TitleState()); + } - script.setVariable('substate', this); - script.setVariable('add', function(obj:FlxBasic) { + scriptSet('state', this); + + scriptSet('add', function(obj:FlxBasic) { add(obj); }); - script.setVariable('remove', function(obj:FlxBasic) { + scriptSet('remove', function(obj:FlxBasic) { remove(obj); }); - script.setVariable('insert', function(pos:Int, obj:FlxBasic) { + scriptSet('insert', function(pos:Int, obj:FlxBasic) { insert(pos, obj); }); - script.execute(Paths.script('classes/$path'), true); - - script.executeFunc('new', (args != null) ? args : []); + scriptExecute('new', (args != null) ? args : []); } override function draw() { super.draw(); - script.executeFunc('draw', []); + scriptExecute('draw', []); } override function create() { @@ -38,21 +42,31 @@ class ScriptedSubState extends ExtendableSubState { override function update(elapsed:Float) { super.update(elapsed); - script.executeFunc('update', [elapsed]); + scriptExecute('update', [elapsed]); } override function beatHit() { super.beatHit(); - script.executeFunc('beatHit', [curBeat]); + scriptExecute('beatHit', [curBeat]); } override function stepHit() { super.stepHit(); - script.executeFunc('stepHit', [curStep]); + scriptExecute('stepHit', [curStep]); } override function destroy() { super.destroy(); - script.executeFunc('destroy', []); + scriptExecute('destroy', []); + } + + function scriptExecute(func:String, args:Array) { + if (script != null) + script.executeFunc(func, args); + } + + function scriptSet(key:String, value:Dynamic) { + if (script != null) + script.setVariable(key, value); } } \ No newline at end of file