mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-05 15:28:29 +08:00
Fixed bug in Disposer. Fixed linting issue in QuestEditorToolBarController and improved error message.
This commit is contained in:
parent
1ea0d0f1db
commit
44ae05cf90
@ -43,7 +43,9 @@ export class Disposer implements Disposable {
|
|||||||
* Insert a single disposable at the given index and return the given disposable.
|
* Insert a single disposable at the given index and return the given disposable.
|
||||||
*/
|
*/
|
||||||
insert<T extends Disposable>(index: number, disposable: T): T {
|
insert<T extends Disposable>(index: number, disposable: T): T {
|
||||||
if (!this._disposed) {
|
if (this._disposed) {
|
||||||
|
disposable.dispose();
|
||||||
|
} else {
|
||||||
this.disposables.splice(index, 0, disposable);
|
this.disposables.splice(index, 0, disposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,9 +55,13 @@ export class Disposer implements Disposable {
|
|||||||
/**
|
/**
|
||||||
* Add 0 or more disposables.
|
* Add 0 or more disposables.
|
||||||
*/
|
*/
|
||||||
add_all(...disposable: Disposable[]): this {
|
add_all(...disposables: Disposable[]): this {
|
||||||
if (!this._disposed) {
|
if (this._disposed) {
|
||||||
this.disposables.push(...disposable);
|
for (const disposable of disposables) {
|
||||||
|
disposable.dispose();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.disposables.push(...disposables);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -22,7 +22,7 @@ import { LogManager } from "../../core/Logger";
|
|||||||
import { basename } from "../../core/util";
|
import { basename } from "../../core/util";
|
||||||
import { Version } from "../../core/data_formats/parsing/quest/Version";
|
import { Version } from "../../core/data_formats/parsing/quest/Version";
|
||||||
import { WritableProperty } from "../../core/observable/property/WritableProperty";
|
import { WritableProperty } from "../../core/observable/property/WritableProperty";
|
||||||
import { Result, failure } from "../../core/Result";
|
import { failure, Result } from "../../core/Result";
|
||||||
import { Severity } from "../../core/Severity";
|
import { Severity } from "../../core/Severity";
|
||||||
|
|
||||||
const logger = LogManager.get("quest_editor/controllers/QuestEditorToolBarController");
|
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));
|
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<void> => {
|
parse_files = async (files: File[]): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
if (files.length === 0) return;
|
if (files.length === 0) return;
|
||||||
@ -183,11 +182,11 @@ export class QuestEditorToolBarController extends Controller {
|
|||||||
new ArrayBufferCursor(dat_buffer, Endianness.Little),
|
new ArrayBufferCursor(dat_buffer, Endianness.Little),
|
||||||
);
|
);
|
||||||
if (!quest) {
|
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));
|
this.set_filename(basename(bin.name || dat.name));
|
||||||
} else {
|
} 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) {
|
} catch (e) {
|
||||||
logger.error("Couldn't read file.", e);
|
logger.error("Couldn't read file.", e);
|
||||||
this.set_result(
|
this.set_result(failure([{ severity: Severity.Error, ui_message: e.message }]));
|
||||||
failure([{ severity: Severity.Error, ui_message: e.message }]),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user