diff --git a/src/core/observable/Disposer.ts b/src/core/observable/Disposer.ts index 763c716e..07bb09d4 100644 --- a/src/core/observable/Disposer.ts +++ b/src/core/observable/Disposer.ts @@ -43,7 +43,9 @@ export class Disposer implements Disposable { * Insert a single disposable at the given index and return the given disposable. */ insert(index: number, disposable: T): T { - if (!this._disposed) { + if (this._disposed) { + disposable.dispose(); + } else { this.disposables.splice(index, 0, disposable); } @@ -53,9 +55,13 @@ export class Disposer implements Disposable { /** * Add 0 or more disposables. */ - add_all(...disposable: Disposable[]): this { - if (!this._disposed) { - this.disposables.push(...disposable); + add_all(...disposables: Disposable[]): this { + if (this._disposed) { + for (const disposable of disposables) { + disposable.dispose(); + } + } else { + this.disposables.push(...disposables); } return this; diff --git a/src/quest_editor/controllers/QuestEditorToolBarController.ts b/src/quest_editor/controllers/QuestEditorToolBarController.ts index 1f74632a..2832cf99 100644 --- a/src/quest_editor/controllers/QuestEditorToolBarController.ts +++ b/src/quest_editor/controllers/QuestEditorToolBarController.ts @@ -22,7 +22,7 @@ import { LogManager } from "../../core/Logger"; import { basename } from "../../core/util"; import { Version } from "../../core/data_formats/parsing/quest/Version"; import { WritableProperty } from "../../core/observable/property/WritableProperty"; -import { Result, failure } from "../../core/Result"; +import { failure, Result } from "../../core/Result"; import { Severity } from "../../core/Severity"; const logger = LogManager.get("quest_editor/controllers/QuestEditorToolBarController"); @@ -151,7 +151,6 @@ export class QuestEditorToolBarController extends Controller { this.quest_editor_store.set_current_quest(create_new_quest(this.area_store, episode)); }; - // TODO: notify user of problems. parse_files = async (files: File[]): Promise => { try { if (files.length === 0) return; @@ -183,11 +182,11 @@ export class QuestEditorToolBarController extends Controller { new ArrayBufferCursor(dat_buffer, Endianness.Little), ); if (!quest) { - throw new Error("Couldn't parse bin or dat 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."); + throw new Error("Please select one .bin and one .dat file."); } } @@ -196,9 +195,7 @@ export class QuestEditorToolBarController extends Controller { ); } catch (e) { logger.error("Couldn't read file.", e); - this.set_result( - failure([{ severity: Severity.Error, ui_message: e.message }]), - ); + this.set_result(failure([{ severity: Severity.Error, ui_message: e.message }])); } };