Fixed empty file crash
This commit is contained in:
@@ -6,9 +6,6 @@ import lime.utils.AssetLibrary;
|
||||
class AssetsLibraryList extends AssetLibrary {
|
||||
public var libraries:Array<AssetLibrary> = [];
|
||||
|
||||
public var rootLibs:Array<AssetLibrary> = [];
|
||||
public var assetsLibs:Array<AssetLibrary> = [];
|
||||
|
||||
@:allow(funkin.backend.system.Main)
|
||||
@:allow(funkin.backend.system.MainState)
|
||||
private var __defaultLibraries:Array<AssetLibrary> = [];
|
||||
@@ -19,7 +16,6 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
libraries.remove(lib);
|
||||
return lib;
|
||||
}
|
||||
|
||||
public function existsSpecific(id:String, type:String, source:AssetSource = BOTH) {
|
||||
if (!id.startsWith("assets/") && exists('assets/$id', type))
|
||||
return true;
|
||||
@@ -98,29 +94,23 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
return content;
|
||||
}
|
||||
|
||||
public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH, ?avoidRoot:Bool = false):Dynamic {
|
||||
public function getSpecificAsset(id:String, type:String, source:AssetSource = BOTH):Dynamic {
|
||||
try {
|
||||
if (!id.startsWith("assets/")) {
|
||||
var ass = getSpecificAsset('assets/$id', type, source);
|
||||
if (ass != null)
|
||||
if (ass != null) {
|
||||
return ass;
|
||||
} else {
|
||||
for (lib in assetsLibs) {
|
||||
if (shouldSkipLib(libraries.indexOf(lib), source)) continue;
|
||||
|
||||
var asset = lib.getAsset(id, type);
|
||||
if (asset != null)
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
for(k=>e in libraries) {
|
||||
if (shouldSkipLib(k, source)) continue;
|
||||
|
||||
if (!avoidRoot) {
|
||||
for (lib in rootLibs) {
|
||||
if (shouldSkipLib(libraries.indexOf(lib), source)) continue;
|
||||
|
||||
var asset = lib.getAsset(id, type);
|
||||
if (asset != null)
|
||||
@:privateAccess
|
||||
if (e.exists(id, e.types.get(id))) {
|
||||
var asset = e.getAsset(id, type);
|
||||
if (asset != null) {
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -140,9 +130,6 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
public override inline function getAsset(id:String, type:String):Dynamic
|
||||
return getSpecificAsset(id, type, BOTH);
|
||||
|
||||
public inline function getAssetSafe(id:String, type:String):Dynamic
|
||||
return getSpecificAsset(id, type, BOTH, true);
|
||||
|
||||
public override function isLocal(id:String, type:String) {
|
||||
return true;
|
||||
}
|
||||
@@ -171,17 +158,8 @@ class AssetsLibraryList extends AssetLibrary {
|
||||
addLibrary(d);
|
||||
}
|
||||
|
||||
public function addLibrary(lib:AssetLibrary) @:privateAccess {
|
||||
public function addLibrary(lib:AssetLibrary) {
|
||||
libraries.insert(0, lib);
|
||||
|
||||
var finalLib:AssetLibrary = lib;
|
||||
if (finalLib is openfl.utils.AssetLibrary)
|
||||
finalLib = cast(finalLib, openfl.utils.AssetLibrary).__proxy;
|
||||
|
||||
if (finalLib is IModsAssetLibrary)
|
||||
assetsLibs.insert(0, finalLib);
|
||||
else
|
||||
rootLibs.insert(0, finalLib);
|
||||
return lib;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
package funkin.backend.scripting;
|
||||
|
||||
import haxe.io.Path;
|
||||
import hscript.Expr.ClassDecl;
|
||||
import hscript.Expr.ModuleDecl;
|
||||
import hscript.Expr.Error;
|
||||
import hscript.Parser;
|
||||
import openfl.Assets;
|
||||
import lime.utils.AssetType;
|
||||
import hscript.*;
|
||||
|
||||
class HScript extends Script {
|
||||
public var interp:Interp;
|
||||
public var parser:Parser;
|
||||
public var expr:Expr;
|
||||
public var decls:Array<ModuleDecl> = null;
|
||||
public var code:String;
|
||||
public var code:String = null;
|
||||
public var folderlessPath:String;
|
||||
var __importedPaths:Array<String>;
|
||||
|
||||
@@ -30,8 +26,10 @@ class HScript extends Script {
|
||||
|
||||
interp = new Interp();
|
||||
|
||||
// We use getAssetSafe to prevent crash from empty file (null which would check root (big crash)) -lunar
|
||||
code = Assets.exists(path) ? Paths.assetsTree.getAssetSafe(path, TEXT) : null;
|
||||
try {
|
||||
if(Assets.exists(path)) code = Assets.getText(path);
|
||||
} catch(e) Logs.trace('Error while reading $path: ${Std.string(e)}', ERROR);
|
||||
|
||||
parser = initParser();
|
||||
folderlessPath = Path.directory(path);
|
||||
__importedPaths = [path];
|
||||
@@ -48,14 +46,13 @@ class HScript extends Script {
|
||||
}));
|
||||
|
||||
funkin.backend.scripting.GlobalScript.call("onScriptCreated", [this, "hscript"]);
|
||||
|
||||
if (code != null && code.trim() != "")
|
||||
loadFromString(code);
|
||||
loadFromString(code);
|
||||
}
|
||||
|
||||
public override function loadFromString(code:String) {
|
||||
try {
|
||||
expr = parser.parseString(code, fileName);
|
||||
if (code != null && code.trim() != "")
|
||||
expr = parser.parseString(code, fileName);
|
||||
} catch(e:Error) {
|
||||
_errorHandler(e);
|
||||
} catch(e) {
|
||||
|
||||
Reference in New Issue
Block a user