diff --git a/src/core/Logger.ts b/src/core/Logger.ts index 28787057..dc53d018 100644 --- a/src/core/Logger.ts +++ b/src/core/Logger.ts @@ -104,6 +104,32 @@ export class Logger { this.handler({ time: new Date(), message, severity, logger: this, cause }, this.name); } } + + showTrace = (message: string, cause?: any): void => { + this.showLog(Severity.Trace, message, cause); + }; + + showDebug = (message: string, cause?: any): void => { + this.showLog(Severity.Debug, message, cause); + }; + + showInfo = (message: string, cause?: any): void => { + this.showLog(Severity.Info, message, cause); + }; + + showWarn = (message: string, cause?: any): void => { + this.showLog(Severity.Warning, message, cause); + }; + + showError = (message: string, cause?: any): void => { + this.showLog(Severity.Error, message, cause); + }; + + //for graphically showing errors and other messages, assume we always want this to show, otherwise we wouldn't call it. + //Instead of doing an alert, we should have some better styled area, like a dismissable bar at the top of the screen with the error. + showLog(severity: Severity, message: string, cause?: any): void { + alert('Message: ' + message + '\r\n\r\nCause: ' + cause.message); + } } export class LogManager { diff --git a/src/quest_editor/controllers/QuestEditorToolBarController.ts b/src/quest_editor/controllers/QuestEditorToolBarController.ts index 716b5ecf..195de434 100644 --- a/src/quest_editor/controllers/QuestEditorToolBarController.ts +++ b/src/quest_editor/controllers/QuestEditorToolBarController.ts @@ -152,17 +152,12 @@ export class QuestEditorToolBarController extends Controller { const parse_result = parse_qst_to_quest( new ArrayBufferCursor(buffer, Endianness.Little), ); - - if (parse_result) { - quest = parse_result.quest; - this.set_version(parse_result.version); + if (!parse_result || !parse_result.quest) { + throw new Error("Couldn't parse quest file."); } - + quest = parse_result.quest; + this.set_version(parse_result.version); this.set_filename(basename(qst.name)); - - if (!quest) { - logger.error("Couldn't parse quest file."); - } } else { const bin = files.find(f => f.name.toLowerCase().endsWith(".bin")); const dat = files.find(f => f.name.toLowerCase().endsWith(".dat")); @@ -174,11 +169,12 @@ export class QuestEditorToolBarController extends Controller { new ArrayBufferCursor(bin_buffer, Endianness.Little), new ArrayBufferCursor(dat_buffer, Endianness.Little), ); - this.set_filename(basename(bin.name || dat.name)); - if (!quest) { - logger.error("Couldn't parse quest file."); + throw new Error("Couldn't parse bin or dat file."); } + this.set_filename(basename(bin.name || dat.name)); + } else { + throw new Error("Invalid File Type."); } } @@ -186,7 +182,7 @@ export class QuestEditorToolBarController extends Controller { quest && convert_quest_to_model(this.area_store, quest), ); } catch (e) { - logger.error("Couldn't read file.", e); + logger.showError("Couldn't read file.", e); } };