some hscript stuff!!
This commit is contained in:
@@ -17,6 +17,8 @@ class HScript extends Script {
|
||||
var parser = new hscript.Parser();
|
||||
parser.allowJSON = parser.allowMetadata = parser.allowTypes = true;
|
||||
interp.errorHandler = _errorHandler;
|
||||
interp.staticVariables = Script.staticVariables;
|
||||
|
||||
interp.variables.set("trace", this.trace);
|
||||
try {
|
||||
expr = parser.parseString(code, fileName);
|
||||
@@ -79,4 +81,8 @@ class HScript extends Script {
|
||||
Logs.logText(Std.string(v))
|
||||
], TRACE);
|
||||
}
|
||||
|
||||
public override function setPublicMap(map:Map<String, Dynamic>) {
|
||||
this.interp.publicVariables = map;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,13 @@ import openfl.utils.Assets;
|
||||
* Class used for scripting.
|
||||
*/
|
||||
class Script extends FlxBasic implements IFlxDestroyable {
|
||||
/**
|
||||
* Use "static var thing = true;" in hscript to use those!!
|
||||
* are reset every mod switch so once youre done with them make sure to make them null!!
|
||||
*/
|
||||
public static var staticVariables:Map<String, Dynamic> = [];
|
||||
|
||||
|
||||
public static function getDefaultVariables():Map<String, Dynamic> {
|
||||
return [
|
||||
// Haxe related stuff
|
||||
@@ -128,6 +135,14 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
curScript = oldScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* HSCRIPT ONLY FOR NOW
|
||||
* Sets the "public" variables map for ScriptPack
|
||||
*/
|
||||
public function setPublicMap(map:Map<String, Dynamic>) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hot-reloads the script, if possible
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,7 @@ import funkin.scripting.events.CancellableEvent;
|
||||
class ScriptPack extends Script {
|
||||
public var scripts:Array<Script> = [];
|
||||
public var additionalDefaultVariables:Map<String, Dynamic> = [];
|
||||
public var publicVariables:Map<String, Dynamic> = [];
|
||||
public var parent:Dynamic = null;
|
||||
|
||||
public override function load() {
|
||||
@@ -94,6 +95,7 @@ class ScriptPack extends Script {
|
||||
|
||||
private function __configureNewScript(script:Script) {
|
||||
if (parent != null) script.setParent(parent);
|
||||
script.setPublicMap(publicVariables);
|
||||
for(k=>e in additionalDefaultVariables) script.set(k, e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user