From 9db8625fafc9a572a1e8f1f2feb1e093f85a2799 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 17 Mar 2024 12:55:41 -0500 Subject: [PATCH] Removed dynamic imports --- src/features/achievements/achievement.tsx | 30 +++++++++-------- src/features/challenges/challenge.tsx | 28 ++++++++-------- src/features/hotkey.tsx | 40 ++++++++++++----------- src/game/gameLoop.ts | 18 ++++------ src/main.ts | 6 ++-- src/util/save.ts | 4 +-- 6 files changed, 64 insertions(+), 62 deletions(-) diff --git a/src/features/achievements/achievement.tsx b/src/features/achievements/achievement.tsx index 9bf454f..d9965ee 100644 --- a/src/features/achievements/achievement.tsx +++ b/src/features/achievements/achievement.tsx @@ -306,18 +306,20 @@ const msDisplayOptions = Object.values(AchievementDisplay).map(option => ({ value: option })); -registerSettingField( - jsx(() => ( - ( + + Show achievements + Select which achievements to display based on criterias. + + ))} + options={msDisplayOptions} + onUpdate:modelValue={value => (settings.msDisplay = value as AchievementDisplay)} + modelValue={settings.msDisplay} + /> + )) + ) ); diff --git a/src/features/challenges/challenge.tsx b/src/features/challenges/challenge.tsx index bba005b..8d4d881 100644 --- a/src/features/challenges/challenge.tsx +++ b/src/features/challenges/challenge.tsx @@ -364,17 +364,19 @@ globalBus.on("loadSettings", settings => { setDefault(settings, "hideChallenges", false); }); -registerSettingField( - jsx(() => ( - ( - - Hide maxed challenges - Hide challenges that have been fully completed. - - ))} - onUpdate:modelValue={value => (settings.hideChallenges = value)} - modelValue={settings.hideChallenges} - /> - )) +globalBus.on("setupVue", () => + registerSettingField( + jsx(() => ( + ( + + Hide maxed challenges + Hide challenges that have been fully completed. + + ))} + onUpdate:modelValue={value => (settings.hideChallenges = value)} + modelValue={settings.hideChallenges} + /> + )) + ) ); diff --git a/src/features/hotkey.tsx b/src/features/hotkey.tsx index 80eebbd..1af6275 100644 --- a/src/features/hotkey.tsx +++ b/src/features/hotkey.tsx @@ -115,24 +115,26 @@ document.onkeydown = function (e) { } }; -registerInfoComponent( - jsx(() => { - const keys = Object.values(hotkeys).filter(hotkey => unref(hotkey?.enabled)); - if (keys.length === 0) { - return ""; - } - return ( -
-
-

Hotkeys

-
- {keys.map(hotkey => ( -
- {hotkey?.description} -
- ))} +globalBus.on("setupVue", () => + registerInfoComponent( + jsx(() => { + const keys = Object.values(hotkeys).filter(hotkey => unref(hotkey?.enabled)); + if (keys.length === 0) { + return ""; + } + return ( +
+
+

Hotkeys

+
+ {keys.map(hotkey => ( +
+ {hotkey?.description} +
+ ))} +
-
- ); - }) + ); + }) + ) ); diff --git a/src/game/gameLoop.ts b/src/game/gameLoop.ts index b001dd6..5418f20 100644 --- a/src/game/gameLoop.ts +++ b/src/game/gameLoop.ts @@ -1,19 +1,15 @@ +import { hasWon } from "data/projEntry"; import projInfo from "data/projInfo.json"; import { globalBus } from "game/events"; import settings from "game/settings"; import Decimal from "util/bignum"; import { loadingSave } from "util/save"; -import type { Ref } from "vue"; import { watch } from "vue"; import player from "./player"; import state from "./state"; let intervalID: NodeJS.Timer | null = null; -// Not imported immediately due to dependency cycles -// This gets set during startGameLoop(), and will only be used in the update function -let hasWon: null | Ref = null; - function update() { const now = Date.now(); let diff = (now - player.time) / 1e3; @@ -95,15 +91,15 @@ function update() { /** Starts the game loop for the project, which updates the game in ticks. */ export async function startGameLoop() { - hasWon = (await import("data/projEntry")).hasWon; - watch(hasWon, hasWon => { - if (hasWon) { - globalBus.emit("gameWon"); - } - }); if (settings.unthrottled) { requestAnimationFrame(update); } else { intervalID = setInterval(update, 50); } } + +watch(hasWon, hasWon => { + if (hasWon) { + globalBus.emit("gameWon"); + } +}); diff --git a/src/main.ts b/src/main.ts index 1aad800..bb5b2cc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,12 +3,14 @@ import App from "App.vue"; import projInfo from "data/projInfo.json"; import "game/notifications"; import state from "game/state"; +import "util/galaxy"; import { load } from "util/save"; import { useRegisterSW } from "virtual:pwa-register/vue"; import type { App as VueApp } from "vue"; import { createApp, nextTick } from "vue"; import { useToast } from "vue-toastification"; -import "util/galaxy"; +import { globalBus } from "./game/events"; +import { startGameLoop } from "./game/gameLoop"; declare global { /** @@ -56,8 +58,6 @@ requestAnimationFrame(async () => { "padding: 4px;" ); await load(); - const { globalBus } = await import("./game/events"); - const { startGameLoop } = await import("./game/gameLoop"); // Create Vue const vue = (window.vue = createApp(App)); diff --git a/src/util/save.ts b/src/util/save.ts index a7830cd..8444ed2 100644 --- a/src/util/save.ts +++ b/src/util/save.ts @@ -1,6 +1,8 @@ import { LoadablePlayerData } from "components/saves/SavesManager.vue"; +import { fixOldSave, getInitialLayers } from "data/projEntry"; import projInfo from "data/projInfo.json"; import { globalBus } from "game/events"; +import { addLayer, layers, removeLayer } from "game/layers"; import type { Player } from "game/player"; import player, { stringifySave } from "game/player"; import settings, { loadSettings } from "game/settings"; @@ -101,8 +103,6 @@ export const loadingSave = ref(false); export async function loadSave(playerObj: Partial): Promise { console.info("Loading save", playerObj); loadingSave.value = true; - const { layers, removeLayer, addLayer } = await import("game/layers"); - const { fixOldSave, getInitialLayers } = await import("data/projEntry"); for (const layer in layers) { const l = layers[layer];