diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx index 4894b6d8..70dd9b67 100644 --- a/source/funkin/game/PlayState.hx +++ b/source/funkin/game/PlayState.hx @@ -677,7 +677,7 @@ class PlayState extends MusicBeatState startingSong = true; super.create(); - + for(s in introSprites) if (s != null) graphicCache.cache(Paths.image(s)); diff --git a/source/funkin/scripting/HScript.hx b/source/funkin/scripting/HScript.hx index be6f6761..9930a51e 100644 --- a/source/funkin/scripting/HScript.hx +++ b/source/funkin/scripting/HScript.hx @@ -1,7 +1,6 @@ package funkin.scripting; import haxe.io.Path; -import funkin.scripting.Script.ScriptClass; import hscript.Expr.ClassDecl; import hscript.Expr.ModuleDecl; import hscript.Expr.Error; @@ -16,6 +15,7 @@ class HScript extends Script { public var decls:Array = null; public var code:String; public var folderlessPath:String; + var __importedPaths:Array; public static function initParser() { var parser = new Parser(); @@ -32,6 +32,7 @@ class HScript extends Script { code = Assets.getText(path); parser = initParser(); folderlessPath = Path.directory(path); + __importedPaths = [path]; interp.errorHandler = _errorHandler; interp.importFailedCallback = importFailedCallback; @@ -55,21 +56,30 @@ class HScript extends Script { } private function importFailedCallback(cl:Array):Bool { - var path = cl.join("/"); - - var scr = Script.create(Paths.script('classes/$path', null, false)); - if (!(scr is DummyScript)) { - // script is valid - var cla = scr.getClass(cl.last()); - if (cla != null) { - interp.variables.set(cl.last(), Script.createCustomClass(cla)); - } else { - interp.variables.set(cl.last(), scr); + var assetsPath = 'assets/data/classes/${cl.join("/")}'; + for(hxExt in ["hx", "hscript", "hsc", "hxs"]) { + var p = '$assetsPath.$hxExt'; + if (__importedPaths.contains(p)) + return true; // no need to reimport again + if (Assets.exists(p)) { + var code = Assets.getText(p); + var expr:Expr = null; + try { + if (code != null && code.trim() != "") + expr = parser.parseString(code); + } catch(e:Error) { + _errorHandler(e); + } catch(e) { + _errorHandler(new Error(ECustom(e.toString()), 0, 0, fileName, 0)); + } + if (expr != null) { + @:privateAccess + interp.exprReturn(expr); + __importedPaths.push(p); + } + return true; } - - return true; } - return false; } @@ -90,6 +100,8 @@ class HScript extends Script { } public override function onLoad() { + @:privateAccess + interp.execute(parser.mk(EBlock([]), 0, 0)); if (expr != null) { interp.execute(expr); call("new", []); @@ -98,7 +110,7 @@ class HScript extends Script { public override function reload() { // save variables - + interp.allowStaticVariables = interp.allowPublicVariables = false; var savedVariables:Map = []; for(k=>e in interp.variables) { @@ -151,29 +163,6 @@ class HScript extends Script { this.interp.publicVariables = map; } - public override function getClass(name:String) { - if (decls == null) { - decls = parser.parseModule(code, fileName); - } - var imports:Array> = []; - for(d in decls) { - switch(d) { - case DPackage(path): - // ignore - case DImport(path, everything): - imports.push(path); - case DClass(c): - trace(c.name); - trace(name); - if (c.name == name) - return new HScriptClass(c, interp, imports, folderlessPath); - case DTypedef(c): - // ignore - } - } - return null; - } - public override function onDestroy() { @:privateAccess { // INTERP @@ -240,60 +229,3 @@ class HScript extends Script { } } } - -class HScriptClass extends ScriptClass { - var decl:ClassDecl; - var name:String; - - var interp:Interp; - - public function new(decl:ClassDecl, sInterp:Interp, classesToImport:Array>, forderlessPath:String) { - super(); - this.name = decl.name; - switch(decl.extend) { - case CTPath(p, params): - this.classPath = p.join("."); - default: - - } - - - - interp = new Interp(); - interp.errorHandler = sInterp.errorHandler; - interp.staticVariables = sInterp.staticVariables; - interp.allowStaticVariables = interp.allowPublicVariables = true; - interp.importFailedCallback = importFailedCallback; - - var parser = HScript.initParser(); - - for(f in decl.fields) { - switch(f.kind) { - case KVar(v): - interp.variables[f.name] = interp.execute(v.expr); - case KFunction(fun): - @:privateAccess - interp.variables[f.name] = interp.execute(parser.mk(EFunction(fun.args, fun.expr, f.name, fun.ret, false, false))); - } - } - } - - public override function hasField(field:String) { - return interp.variables.exists(field); - } - public override function get(field:String) { - return interp.variables[field]; - } - - public override function set(field:String, v:Dynamic) { - interp.variables[field] = v; - } - - public override function onCall(field:String, parameters:Array, parent:Dynamic) { - interp.scriptObject = parent; - var v = interp.variables[field]; - if (v != null && Reflect.isFunction(v)) - return (parameters != null && parameters.length > 0) ? Reflect.callMethod(null, v, parameters) : v(); - return null; - } -} \ No newline at end of file diff --git a/source/funkin/scripting/Script.hx b/source/funkin/scripting/Script.hx index 6ac422a1..b9b3cb17 100644 --- a/source/funkin/scripting/Script.hx +++ b/source/funkin/scripting/Script.hx @@ -142,15 +142,6 @@ class Script extends FlxBasic implements IFlxDestroyable { return new DummyScript(path); } - public static function createCustomClass(s:ScriptClass) { - var t:Class = cast Type.resolveClass('${s.classPath}__Softcoded'); - if (t == null) { - Logs.trace('Class at ${s.classPath} was not found.', ERROR); - return null; - } - return new ScriptCustomClass(s, t); - } - /** * Creates a new instance of the script class. * @param path @@ -263,75 +254,8 @@ class Script extends FlxBasic implements IFlxDestroyable { public function onDestroy() {}; - public function getClass(name:String):ScriptClass { - return null; - } - public override function destroy() { super.destroy(); onDestroy(); } -} - -class ScriptClass { - public var classPath:String = null; - public var folderlessPath:String = null; - - public function new() {} - - public function get(field:String):Dynamic {return null;} - - public function set(field:String, v:Dynamic) {} - - public function hasField(field:String):Bool {return false;} - - /** - * Calls the function `func` defined in the class. - * @param func Name of the function - * @param parameters (Optional) Parameters of the function. - * @return Result (if void, then null) - */ - public function call(func:String, parameters:Array, parent:Dynamic):Dynamic { - var result = onCall(func, parameters == null ? [] : parameters, parent); - return result; - } - - public function onCall(func:String, parameters:Array, parent:Dynamic):Dynamic {return null;} - - private function importFailedCallback(cl:Array):Bool { - var path = cl.join("/"); - - var scr = Script.create(Paths.script('$folderlessPath$path', null, true)); - if (!(scr is DummyScript)) { - // script is valid - var cla = scr.getClass(cl.last()); - if (cla != null) { - set(cl.last(), Script.createCustomClass(cla)); - } else { - set(cl.last(), scr); - } - - return true; - } - - return false; - } -} - -class ScriptCustomClass implements IHScriptCustomConstructor { - var scrClass:ScriptClass; - var scrType:Class; - public function new(scrClass:ScriptClass, scrType:Class) { - this.scrClass = scrClass; - this.scrType = scrType; - } - public function hnew(args:Array):Dynamic { - var a = [for(arg in args) arg]; - a.insert(0, scrClass); - return Type.createInstance(scrType, a); - } -} - -interface IScriptClassInstance { - } \ No newline at end of file diff --git a/source/funkin/system/Controls.hx b/source/funkin/system/Controls.hx index a435bd67..2e5a16e3 100644 --- a/source/funkin/system/Controls.hx +++ b/source/funkin/system/Controls.hx @@ -24,7 +24,7 @@ enum abstract Action(String) to String from String { var RIGHT_R = "right-release"; var DOWN_R = "down-release"; - + var NOTE_UP = "note-up"; var NOTE_LEFT = "note-left"; var NOTE_RIGHT = "note-right"; @@ -575,7 +575,7 @@ class Controls extends FlxActionSet removeKeyboard(); keyboardScheme = scheme; - + switch (scheme) { case Solo: @@ -642,7 +642,7 @@ class Controls extends FlxActionSet public function addGamepad(id:Int, ?buttonMap:Map>):Void { gamepadsAdded.push(id); - + #if (haxe >= "4.0.0") for (control => buttons in buttonMap) inline bindButtons(control, id, buttons);