Better errors
This commit is contained in:
@@ -123,7 +123,7 @@ class MusicBeatState extends FlxState implements IBeatReceiver
|
||||
var path = Paths.script('data/states/${scriptName}/LIB_$i');
|
||||
var script = Script.create(path);
|
||||
if (script is DummyScript) continue;
|
||||
script.fileName = '$i:$scriptName';
|
||||
script.remappedNames.set(script.fileName, '$i:${script.fileName}');
|
||||
stateScripts.add(script);
|
||||
script.load();
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class MusicBeatSubstate extends FlxSubState implements IBeatReceiver
|
||||
var path = Paths.script('data/states/${scriptName}/LIB_$i');
|
||||
var script = Script.create(path);
|
||||
if (script is DummyScript) continue;
|
||||
script.fileName = '$i:$scriptName';
|
||||
script.remappedNames.set(script.fileName, '$i:${script.fileName}');
|
||||
stateScripts.add(script);
|
||||
script.load();
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class GlobalScript {
|
||||
var path = Paths.script('data/global/LIB_$i');
|
||||
var script = Script.create(path);
|
||||
if (script is DummyScript) continue;
|
||||
script.fileName = '$i:global.hx';
|
||||
script.remappedNames.set(script.fileName, '$i:${script.fileName}');
|
||||
scripts.add(script);
|
||||
script.load();
|
||||
}
|
||||
|
||||
@@ -91,8 +91,9 @@ class HScript extends Script {
|
||||
}
|
||||
|
||||
private function _errorHandler(error:Error) {
|
||||
|
||||
// This should be ${error.file} later
|
||||
var fileName = error.origin;
|
||||
if(remappedNames.exists(fileName))
|
||||
fileName = remappedNames.get(fileName);
|
||||
var fn = '$fileName:${error.line}: ';
|
||||
var err = error.toString();
|
||||
if (err.startsWith(fn)) err = err.substr(fn.length);
|
||||
|
||||
@@ -124,6 +124,11 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
*/
|
||||
public var fileName:String;
|
||||
|
||||
/**
|
||||
* Script Extension
|
||||
*/
|
||||
public var extension:String;
|
||||
|
||||
/**
|
||||
* Path to the script.
|
||||
*/
|
||||
@@ -133,6 +138,8 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
|
||||
private var didLoad:Bool = false;
|
||||
|
||||
public var remappedNames:Map<String, String> = [];
|
||||
|
||||
/**
|
||||
* Creates a script from the specified asset path. The language is automatically determined.
|
||||
* @param path Path in assets
|
||||
@@ -183,6 +190,7 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
path = Paths.getFilenameFromLibFile(path);
|
||||
|
||||
fileName = Path.withoutDirectory(path);
|
||||
extension = Path.extension(path);
|
||||
this.path = path;
|
||||
onCreate(path);
|
||||
for(k=>e in getDefaultVariables(this)) {
|
||||
@@ -228,6 +236,9 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
* Traces something as this script.
|
||||
*/
|
||||
public function trace(v:Dynamic) {
|
||||
var fileName = this.fileName;
|
||||
if(remappedNames.exists(fileName))
|
||||
fileName = remappedNames.get(fileName);
|
||||
Logs.traceColored([
|
||||
Logs.logText('${fileName}: ', GREEN),
|
||||
Logs.logText(Std.string(v))
|
||||
@@ -285,6 +296,9 @@ class Script extends FlxBasic implements IFlxDestroyable {
|
||||
* @param additionalInfo Additional information you could provide.
|
||||
*/
|
||||
public function error(text:String, ?additionalInfo:Dynamic):Void {
|
||||
var fileName = this.fileName;
|
||||
if(remappedNames.exists(fileName))
|
||||
fileName = remappedNames.get(fileName);
|
||||
Logs.traceColored([
|
||||
Logs.logText(fileName, RED),
|
||||
Logs.logText(text)
|
||||
|
||||
Reference in New Issue
Block a user