phantasmal-world/src/index.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-08-20 04:56:40 +08:00
import { ApplicationView } from "./application/gui/ApplicationView";
import { Disposable } from "./core/observable/Disposable";
import "./core/gui/index.css";
2019-08-20 04:56:40 +08:00
import { throttle } from "lodash";
import Logger from "js-logger";
import "@fortawesome/fontawesome-free/js/fontawesome";
import "@fortawesome/fontawesome-free/js/solid";
import "@fortawesome/fontawesome-free/js/regular";
2019-08-20 04:56:40 +08:00
Logger.useDefaults({
defaultLevel: (Logger as any)[process.env["LOG_LEVEL"] || "OFF"],
});
// Disable native undo/redo.
document.addEventListener("keydown", e => {
const kbe = e as KeyboardEvent;
if (kbe.ctrlKey && !kbe.altKey && kbe.key.toUpperCase() === "Z") {
kbe.preventDefault();
}
});
// This doesn't work in FireFox:
document.addEventListener("beforeinput", e => {
const ie = e as any;
if (ie.inputType === "historyUndo" || ie.inputType === "historyRedo") {
e.preventDefault();
}
});
function initialize(): Disposable {
2019-08-20 04:56:40 +08:00
const application_view = new ApplicationView();
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);
return {
dispose(): void {
window.removeEventListener("resize", resize);
application_view.dispose();
},
};
}
initialize();