Skip to content

Commit

Permalink
huh??
Browse files Browse the repository at this point in the history
  • Loading branch information
Joalor64GH authored Oct 15, 2024
1 parent f65993e commit 9b70667
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
2 changes: 1 addition & 1 deletion source/backend/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 27 additions & 11 deletions source/states/ScriptedState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,31 @@ class ScriptedState extends ExtendableState {
public function new(path:String, ?args:Array<Dynamic>) {
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() {
Expand All @@ -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<Dynamic>) {
if (script != null)
script.executeFunc(func, args);
}

function scriptSet(key:String, value:Dynamic) {
if (script != null)
script.setVariable(key, value);
}
}
40 changes: 27 additions & 13 deletions source/substates/ScriptedSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@ class ScriptedSubState extends ExtendableSubState {
public function new(path:String, ?args:Array<Dynamic>) {
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() {
Expand All @@ -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<Dynamic>) {
if (script != null)
script.executeFunc(func, args);
}

function scriptSet(key:String, value:Dynamic) {
if (script != null)
script.setVariable(key, value);
}
}

0 comments on commit 9b70667

Please sign in to comment.