mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-05 15:28:29 +08:00
Merge pull request #5 from LunarFuror/lf-display-errors-to-user
error cleanup, alert the error
This commit is contained in:
commit
1ea0d0f1db
@ -21,16 +21,29 @@ import { convert_quest_from_model, convert_quest_to_model } from "../stores/mode
|
|||||||
import { LogManager } from "../../core/Logger";
|
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 { Result, failure } from "../../core/Result";
|
||||||
|
import { Severity } from "../../core/Severity";
|
||||||
|
|
||||||
const logger = LogManager.get("quest_editor/controllers/QuestEditorToolBarController");
|
const logger = LogManager.get("quest_editor/controllers/QuestEditorToolBarController");
|
||||||
|
|
||||||
export type AreaAndLabel = { readonly area: AreaModel; readonly label: string };
|
export type AreaAndLabel = { readonly area: AreaModel; readonly label: string };
|
||||||
|
|
||||||
export class QuestEditorToolBarController extends Controller {
|
export class QuestEditorToolBarController extends Controller {
|
||||||
|
private readonly _result_dialog_visible = property(false);
|
||||||
|
private readonly _result: WritableProperty<Result<unknown> | undefined> = property(undefined);
|
||||||
|
private readonly _result_problems_message = property("");
|
||||||
|
private readonly _result_error_message = property("");
|
||||||
|
|
||||||
private _save_as_dialog_visible = property(false);
|
private _save_as_dialog_visible = property(false);
|
||||||
private _filename = property("");
|
private _filename = property("");
|
||||||
private _version = property(Version.BB);
|
private _version = property(Version.BB);
|
||||||
|
|
||||||
|
readonly result_dialog_visible: Property<boolean> = this._result_dialog_visible;
|
||||||
|
readonly result: Property<Result<unknown> | undefined> = this._result;
|
||||||
|
readonly result_problems_message: Property<string> = this._result_problems_message;
|
||||||
|
readonly result_error_message: Property<string> = this._result_error_message;
|
||||||
|
|
||||||
readonly vm_feature_active: boolean;
|
readonly vm_feature_active: boolean;
|
||||||
readonly areas: Property<readonly AreaAndLabel[]>;
|
readonly areas: Property<readonly AreaAndLabel[]>;
|
||||||
readonly current_area: Property<AreaAndLabel>;
|
readonly current_area: Property<AreaAndLabel>;
|
||||||
@ -152,17 +165,12 @@ export class QuestEditorToolBarController extends Controller {
|
|||||||
const parse_result = parse_qst_to_quest(
|
const parse_result = parse_qst_to_quest(
|
||||||
new ArrayBufferCursor(buffer, Endianness.Little),
|
new ArrayBufferCursor(buffer, Endianness.Little),
|
||||||
);
|
);
|
||||||
|
if (!parse_result || !parse_result.quest) {
|
||||||
if (parse_result) {
|
throw new Error("Couldn't parse quest file.");
|
||||||
|
}
|
||||||
quest = parse_result.quest;
|
quest = parse_result.quest;
|
||||||
this.set_version(parse_result.version);
|
this.set_version(parse_result.version);
|
||||||
}
|
|
||||||
|
|
||||||
this.set_filename(basename(qst.name));
|
this.set_filename(basename(qst.name));
|
||||||
|
|
||||||
if (!quest) {
|
|
||||||
logger.error("Couldn't parse quest file.");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const bin = files.find(f => f.name.toLowerCase().endsWith(".bin"));
|
const bin = files.find(f => f.name.toLowerCase().endsWith(".bin"));
|
||||||
const dat = files.find(f => f.name.toLowerCase().endsWith(".dat"));
|
const dat = files.find(f => f.name.toLowerCase().endsWith(".dat"));
|
||||||
@ -174,11 +182,12 @@ export class QuestEditorToolBarController extends Controller {
|
|||||||
new ArrayBufferCursor(bin_buffer, Endianness.Little),
|
new ArrayBufferCursor(bin_buffer, Endianness.Little),
|
||||||
new ArrayBufferCursor(dat_buffer, Endianness.Little),
|
new ArrayBufferCursor(dat_buffer, Endianness.Little),
|
||||||
);
|
);
|
||||||
this.set_filename(basename(bin.name || dat.name));
|
|
||||||
|
|
||||||
if (!quest) {
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +196,9 @@ 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(
|
||||||
|
failure([{ severity: Severity.Error, ui_message: e.message }]),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -274,4 +286,16 @@ export class QuestEditorToolBarController extends Controller {
|
|||||||
stop = (): void => {
|
stop = (): void => {
|
||||||
this.quest_editor_store.quest_runner.stop();
|
this.quest_editor_store.quest_runner.stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dismiss_result_dialog = (): void => {
|
||||||
|
this._result_dialog_visible.val = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
private set_result(result: Result<unknown>): void {
|
||||||
|
this._result.val = result;
|
||||||
|
|
||||||
|
if (result.problems.length) {
|
||||||
|
this._result_dialog_visible.val = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import { Dialog } from "../../core/gui/Dialog";
|
|||||||
import { TextInput } from "../../core/gui/TextInput";
|
import { TextInput } from "../../core/gui/TextInput";
|
||||||
import "./QuestEditorToolBarView.css";
|
import "./QuestEditorToolBarView.css";
|
||||||
import { Version } from "../../core/data_formats/parsing/quest/Version";
|
import { Version } from "../../core/data_formats/parsing/quest/Version";
|
||||||
|
import { ResultDialog } from "../../core/gui/ResultDialog";
|
||||||
|
|
||||||
export class QuestEditorToolBarView extends View {
|
export class QuestEditorToolBarView extends View {
|
||||||
private readonly toolbar: ToolBar;
|
private readonly toolbar: ToolBar;
|
||||||
@ -100,6 +101,14 @@ export class QuestEditorToolBarView extends View {
|
|||||||
icon_left: Icon.Stop,
|
icon_left: Icon.Stop,
|
||||||
tooltip: "Stop execution (Shift-F5)",
|
tooltip: "Stop execution (Shift-F5)",
|
||||||
});
|
});
|
||||||
|
const dialog = this.disposable(
|
||||||
|
new ResultDialog({
|
||||||
|
visible: ctrl.result_dialog_visible,
|
||||||
|
result: ctrl.result,
|
||||||
|
problems_message: ctrl.result_problems_message,
|
||||||
|
error_message: ctrl.result_error_message,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const children = [
|
const children = [
|
||||||
new_quest_button,
|
new_quest_button,
|
||||||
@ -219,6 +228,8 @@ export class QuestEditorToolBarView extends View {
|
|||||||
|
|
||||||
stop_button.onclick.observe(ctrl.stop),
|
stop_button.onclick.observe(ctrl.stop),
|
||||||
stop_button.enabled.bind_to(ctrl.can_stop),
|
stop_button.enabled.bind_to(ctrl.can_stop),
|
||||||
|
|
||||||
|
dialog.ondismiss.observe(ctrl.dismiss_result_dialog),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.finalize_construction();
|
this.finalize_construction();
|
||||||
|
Loading…
Reference in New Issue
Block a user