hot reloading (F5)
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
958
|
||||
963
|
||||
@@ -746,6 +746,9 @@ class PlayState extends MusicBeatState
|
||||
DiscordClient.changePresence("Chart Editor", null, null, true);
|
||||
#end
|
||||
}
|
||||
if (FlxG.keys.justPressed.F5) {
|
||||
scripts.reload();
|
||||
}
|
||||
|
||||
// FlxG.watch.addQuick('VOL', vocals.amplitudeLeft);
|
||||
// FlxG.watch.addQuick('VOLRight', vocals.amplitudeRight);
|
||||
|
||||
@@ -36,6 +36,23 @@ class HScript extends Script {
|
||||
if (expr != null) interp.execute(expr);
|
||||
}
|
||||
|
||||
public override function reload() {
|
||||
// save variables
|
||||
var savedVariables:Map<String, Dynamic> = [];
|
||||
for(k=>e in interp.variables) {
|
||||
if (!Reflect.isFunction(e)) {
|
||||
savedVariables[k] = e;
|
||||
}
|
||||
}
|
||||
var oldParent = interp.scriptObject;
|
||||
onCreate(path);
|
||||
load();
|
||||
setParent(oldParent);
|
||||
for(k=>e in savedVariables) {
|
||||
interp.variables.set(k, e);
|
||||
}
|
||||
}
|
||||
|
||||
private override function onCall(funcName:String, parameters:Array<Dynamic>):Dynamic {
|
||||
if (interp == null) return null;
|
||||
|
||||
|
||||
@@ -128,6 +128,13 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
curScript = oldScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hot-reloads the script, if possible
|
||||
*/
|
||||
public function reload() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the function `func` defined in the script.
|
||||
* @param func Name of the function
|
||||
|
||||
@@ -43,6 +43,10 @@ class ScriptPack extends Script {
|
||||
return null;
|
||||
}
|
||||
|
||||
public override function reload() {
|
||||
for(e in scripts) e.reload();
|
||||
}
|
||||
|
||||
public override function set(val:String, value:Dynamic) {
|
||||
for(e in scripts) e.set(val, value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user