2019-08-20 04:56:40 +08:00
|
|
|
import { ApplicationView } from "./application/gui/ApplicationView";
|
2019-08-21 21:19:44 +08:00
|
|
|
import { Disposable } from "./core/observable/Disposable";
|
2019-08-23 23:00:39 +08:00
|
|
|
import "./core/gui/index.css";
|
2019-08-20 04:56:40 +08:00
|
|
|
import { throttle } from "lodash";
|
2019-08-21 23:56:46 +08:00
|
|
|
import Logger from "js-logger";
|
2019-08-30 00:24:03 +08:00
|
|
|
import "@fortawesome/fontawesome-free/js/fontawesome";
|
|
|
|
import "@fortawesome/fontawesome-free/js/solid";
|
|
|
|
import "@fortawesome/fontawesome-free/js/regular";
|
2019-09-14 03:20:26 +08:00
|
|
|
import "@fortawesome/fontawesome-free/js/brands";
|
2019-12-22 02:40:42 +08:00
|
|
|
import { GuiStore, GuiTool } from "./core/stores/GuiStore";
|
|
|
|
import { load_item_type_stores } from "./core/stores/ItemTypeStore";
|
|
|
|
import { load_item_drop_stores } from "./hunt_optimizer/stores/ItemDropStore";
|
2019-08-20 04:56:40 +08:00
|
|
|
|
2019-08-21 23:56:46 +08:00
|
|
|
Logger.useDefaults({
|
2019-12-22 02:40:42 +08:00
|
|
|
defaultLevel: (Logger as any)[process.env["LOG_LEVEL"] ?? "OFF"],
|
2019-08-21 23:56:46 +08:00
|
|
|
});
|
|
|
|
|
2019-09-15 03:14:38 +08:00
|
|
|
function initialize(): Disposable {
|
|
|
|
// Disable native undo/redo.
|
|
|
|
document.addEventListener("beforeinput", before_input);
|
|
|
|
// Work-around for FireFox:
|
|
|
|
document.addEventListener("keydown", keydown);
|
2019-08-21 23:56:46 +08:00
|
|
|
|
2019-09-15 03:14:38 +08:00
|
|
|
// Disable native drag-and-drop.
|
|
|
|
document.addEventListener("dragenter", dragenter);
|
|
|
|
document.addEventListener("dragover", dragover);
|
|
|
|
document.addEventListener("drop", drop);
|
2019-08-21 23:56:46 +08:00
|
|
|
|
2019-12-22 02:40:42 +08:00
|
|
|
// Initialize core stores shared by several submodules.
|
|
|
|
const gui_store = new GuiStore();
|
|
|
|
const item_type_stores = load_item_type_stores(gui_store);
|
|
|
|
const item_drop_stores = load_item_drop_stores(gui_store, item_type_stores);
|
|
|
|
|
|
|
|
// Initialize application view.
|
|
|
|
const application_view = new ApplicationView(gui_store, [
|
|
|
|
[
|
|
|
|
GuiTool.Viewer,
|
|
|
|
async () => {
|
|
|
|
return (await import("./viewer/index")).initialize_viewer(gui_store);
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
GuiTool.QuestEditor,
|
|
|
|
async () => {
|
|
|
|
return (await import("./quest_editor/index")).initialize_quest_editor(gui_store);
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
GuiTool.HuntOptimizer,
|
|
|
|
async () => {
|
|
|
|
return (await import("./hunt_optimizer/index")).initialize_hunt_optimizer(
|
|
|
|
gui_store,
|
|
|
|
item_type_stores,
|
|
|
|
item_drop_stores,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
],
|
|
|
|
]);
|
2019-08-20 04:56:40 +08:00
|
|
|
|
2019-09-15 03:14:38 +08:00
|
|
|
// Resize the view on window resize.
|
2019-08-20 04:56:40 +08:00
|
|
|
const resize = throttle(
|
|
|
|
() => {
|
|
|
|
application_view.resize(window.innerWidth, window.innerHeight);
|
|
|
|
},
|
|
|
|
100,
|
|
|
|
{ leading: true, trailing: true },
|
|
|
|
);
|
|
|
|
|
|
|
|
resize();
|
|
|
|
document.body.append(application_view.element);
|
|
|
|
window.addEventListener("resize", resize);
|
|
|
|
|
2019-09-15 03:14:38 +08:00
|
|
|
// Dispose view and global event listeners when necessary.
|
2019-08-20 04:56:40 +08:00
|
|
|
return {
|
|
|
|
dispose(): void {
|
2019-09-15 03:14:38 +08:00
|
|
|
window.removeEventListener("beforeinput", before_input);
|
|
|
|
window.removeEventListener("keydown", keydown);
|
2019-08-20 04:56:40 +08:00
|
|
|
window.removeEventListener("resize", resize);
|
2019-09-15 03:14:38 +08:00
|
|
|
window.removeEventListener("dragenter", dragenter);
|
|
|
|
window.removeEventListener("dragover", dragover);
|
|
|
|
window.removeEventListener("drop", drop);
|
2019-08-20 04:56:40 +08:00
|
|
|
application_view.dispose();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2019-08-21 23:56:46 +08:00
|
|
|
|
2019-09-15 03:14:38 +08:00
|
|
|
function before_input(e: Event): void {
|
|
|
|
const ie = e as any;
|
|
|
|
|
|
|
|
if (ie.inputType === "historyUndo" || ie.inputType === "historyRedo") {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function keydown(e: Event): void {
|
|
|
|
const kbe = e as KeyboardEvent;
|
|
|
|
|
|
|
|
if (kbe.ctrlKey && !kbe.altKey && kbe.key.toUpperCase() === "Z") {
|
|
|
|
kbe.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragenter(e: DragEvent): void {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (e.dataTransfer) {
|
|
|
|
e.dataTransfer.dropEffect = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dragover(e: DragEvent): void {
|
|
|
|
dragenter(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
function drop(e: DragEvent): void {
|
|
|
|
dragenter(e);
|
|
|
|
}
|
|
|
|
|
2019-08-21 23:56:46 +08:00
|
|
|
initialize();
|