hot reloading (F5)

This commit is contained in:
Yoshman29
2022-11-02 02:23:45 +01:00
parent bf1e581479
commit dc03e378df
5 changed files with 32 additions and 1 deletions
+1 -1
View File
@@ -1 +1 @@
958
963
+3
View File
@@ -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);
+17
View File
@@ -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;
+7
View File
@@ -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
+4
View File
@@ -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);
}