Better errors

This commit is contained in:
NeeEoo
2024-02-12 11:55:36 +01:00
parent e6ff26fd2e
commit 2da4b8a111
5 changed files with 20 additions and 5 deletions
+1 -1
View File
@@ -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();
}
+1 -1
View File
@@ -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();
}
+3 -2
View File
@@ -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);
+14
View File
@@ -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)