diff --git a/source/funkin/backend/assets/Paths.hx b/source/funkin/backend/assets/Paths.hx index 6a6efc08..00aae99d 100644 --- a/source/funkin/backend/assets/Paths.hx +++ b/source/funkin/backend/assets/Paths.hx @@ -302,6 +302,23 @@ class Paths return content; */ } + + // Used in Script.hx + @:noCompletion public static function getFilenameFromLibFile(path:String) { + var file = new haxe.io.Path(path); + if(file.file.startsWith("LIB_")) { + return file.dir + "." + file.ext; + } + return path; + } + + @:noCompletion public static function getLibFromLibFile(path:String) { + var file = new haxe.io.Path(path); + if(file.file.startsWith("LIB_")) { + return file.file.substr(4); + } + return ""; + } } class ScriptPathInfo { diff --git a/source/funkin/backend/scripting/HScript.hx b/source/funkin/backend/scripting/HScript.hx index 1fe05dc2..0830313d 100644 --- a/source/funkin/backend/scripting/HScript.hx +++ b/source/funkin/backend/scripting/HScript.hx @@ -11,7 +11,7 @@ class HScript extends Script { public var parser:Parser; public var expr:Expr; public var code:String = null; - public var folderlessPath:String; + //public var folderlessPath:String; var __importedPaths:Array; public static function initParser() { @@ -27,11 +27,11 @@ class HScript extends Script { interp = new Interp(); try { - if(Assets.exists(path)) code = Assets.getText(path); + if(Assets.exists(rawPath)) code = Assets.getText(rawPath); } catch(e) Logs.trace('Error while reading $path: ${Std.string(e)}', ERROR); parser = initParser(); - folderlessPath = Path.directory(path); + //folderlessPath = Path.directory(path); __importedPaths = [path]; interp.errorHandler = _errorHandler; @@ -92,6 +92,7 @@ class HScript extends Script { private function _errorHandler(error:Error) { + // This should be ${error.file} later var fn = '$fileName:${error.line}: '; var err = error.toString(); if (err.startsWith(fn)) err = err.substr(fn.length); diff --git a/source/funkin/backend/scripting/Script.hx b/source/funkin/backend/scripting/Script.hx index 49c79a00..8b2af29c 100644 --- a/source/funkin/backend/scripting/Script.hx +++ b/source/funkin/backend/scripting/Script.hx @@ -129,6 +129,8 @@ class Script extends FlxBasic implements IFlxDestroyable { */ public var path:String = null; + private var rawPath:String = null; + private var didLoad:Bool = false; /** @@ -177,6 +179,9 @@ class Script extends FlxBasic implements IFlxDestroyable { public function new(path:String) { super(); + rawPath = path; + path = Paths.getFilenameFromLibFile(path); + fileName = Path.withoutDirectory(path); this.path = path; onCreate(path);