Profectus/src/main.ts

82 lines
2.6 KiB
TypeScript
Raw Normal View History

import "@fontsource/material-icons";
2022-06-27 00:17:22 +00:00
import App from "App.vue";
import projInfo from "data/projInfo.json";
import "game/notifications";
import { load } from "util/save";
2022-06-26 20:22:22 +00:00
import { useRegisterSW } from "virtual:pwa-register/vue";
2022-06-27 00:17:22 +00:00
import type { App as VueApp } from "vue";
import { createApp, nextTick } from "vue";
2022-06-26 20:22:22 +00:00
import { useToast } from "vue-toastification";
2022-01-14 04:25:47 +00:00
declare global {
2022-07-10 03:09:25 +00:00
/**
2022-07-10 05:43:52 +00:00
* Augment the window object so the vue app and project info can be accessed from the console.
2022-07-10 03:09:25 +00:00
*/
2022-01-14 04:25:47 +00:00
interface Window {
vue: VueApp;
projInfo: typeof projInfo;
2022-01-14 04:25:47 +00:00
}
2022-07-10 03:02:44 +00:00
2022-07-10 05:43:52 +00:00
/** Fix for typedoc treating import functions as taking AssertOptions instead of GlobOptions. */
2022-07-10 03:02:44 +00:00
interface AssertOptions {
as: string;
}
2022-01-14 04:25:47 +00:00
}
2022-07-10 03:09:25 +00:00
document.title = projInfo.title;
window.projInfo = projInfo;
if (projInfo.id === "") {
throw "Project ID is empty! Please select a unique ID for this project in /src/data/projInfo.json";
}
requestAnimationFrame(async () => {
console.log(
2022-02-27 20:24:48 +00:00
"%cMade in Profectus%c\nLearn more at www.moddingtree.com",
"font-weight: bold; font-size: 24px; color: #A3BE8C; background: #2E3440; padding: 4px 8px; border-radius: 8px;",
"padding: 4px;"
);
await load();
const { globalBus } = await import("./game/events");
const { startGameLoop } = await import("./game/gameLoop");
// Create Vue
2022-03-04 03:41:59 +00:00
const vue = (window.vue = createApp(App));
2022-01-14 04:25:47 +00:00
globalBus.emit("setupVue", vue);
vue.mount("#app");
2022-06-26 20:22:22 +00:00
// Setup PWA update prompt
nextTick(() => {
const toast = useToast();
const { updateServiceWorker } = useRegisterSW({
onNeedRefresh() {
2022-12-10 06:47:11 +00:00
toast.info("New content available, click here to update.", {
2022-06-26 20:22:22 +00:00
timeout: false,
closeOnClick: false,
draggable: false,
icon: {
iconClass: "material-icons",
iconChildren: "refresh",
iconTag: "i"
},
rtl: false,
onClick() {
updateServiceWorker();
}
});
},
onOfflineReady() {
toast.info("App ready to work offline");
},
onRegisterError: console.warn,
onRegistered(r) {
if (r) {
2022-12-09 01:31:36 +00:00
// https://stackoverflow.com/questions/65500916/typeerror-failed-to-execute-update-on-serviceworkerregistration-illegal-in
setInterval(() => r.update(), 60 * 60 * 1000);
2022-06-26 20:22:22 +00:00
}
}
});
});
2022-01-14 04:25:47 +00:00
startGameLoop();
});