Removed dynamic imports

This commit is contained in:
thepaperpilot 2024-03-17 12:55:41 -05:00
parent 3e213e8db9
commit 9db8625faf
6 changed files with 64 additions and 62 deletions

View file

@ -306,6 +306,7 @@ const msDisplayOptions = Object.values(AchievementDisplay).map(option => ({
value: option value: option
})); }));
globalBus.on("setupVue", () =>
registerSettingField( registerSettingField(
jsx(() => ( jsx(() => (
<Select <Select
@ -320,4 +321,5 @@ registerSettingField(
modelValue={settings.msDisplay} modelValue={settings.msDisplay}
/> />
)) ))
)
); );

View file

@ -364,6 +364,7 @@ globalBus.on("loadSettings", settings => {
setDefault(settings, "hideChallenges", false); setDefault(settings, "hideChallenges", false);
}); });
globalBus.on("setupVue", () =>
registerSettingField( registerSettingField(
jsx(() => ( jsx(() => (
<Toggle <Toggle
@ -377,4 +378,5 @@ registerSettingField(
modelValue={settings.hideChallenges} modelValue={settings.hideChallenges}
/> />
)) ))
)
); );

View file

@ -115,6 +115,7 @@ document.onkeydown = function (e) {
} }
}; };
globalBus.on("setupVue", () =>
registerInfoComponent( registerInfoComponent(
jsx(() => { jsx(() => {
const keys = Object.values(hotkeys).filter(hotkey => unref(hotkey?.enabled)); const keys = Object.values(hotkeys).filter(hotkey => unref(hotkey?.enabled));
@ -135,4 +136,5 @@ registerInfoComponent(
</div> </div>
); );
}) })
)
); );

View file

@ -1,19 +1,15 @@
import { hasWon } from "data/projEntry";
import projInfo from "data/projInfo.json"; import projInfo from "data/projInfo.json";
import { globalBus } from "game/events"; import { globalBus } from "game/events";
import settings from "game/settings"; import settings from "game/settings";
import Decimal from "util/bignum"; import Decimal from "util/bignum";
import { loadingSave } from "util/save"; import { loadingSave } from "util/save";
import type { Ref } from "vue";
import { watch } from "vue"; import { watch } from "vue";
import player from "./player"; import player from "./player";
import state from "./state"; import state from "./state";
let intervalID: NodeJS.Timer | null = null; 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<boolean> = null;
function update() { function update() {
const now = Date.now(); const now = Date.now();
let diff = (now - player.time) / 1e3; 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. */ /** Starts the game loop for the project, which updates the game in ticks. */
export async function startGameLoop() { export async function startGameLoop() {
hasWon = (await import("data/projEntry")).hasWon;
watch(hasWon, hasWon => {
if (hasWon) {
globalBus.emit("gameWon");
}
});
if (settings.unthrottled) { if (settings.unthrottled) {
requestAnimationFrame(update); requestAnimationFrame(update);
} else { } else {
intervalID = setInterval(update, 50); intervalID = setInterval(update, 50);
} }
} }
watch(hasWon, hasWon => {
if (hasWon) {
globalBus.emit("gameWon");
}
});

View file

@ -3,12 +3,14 @@ import App from "App.vue";
import projInfo from "data/projInfo.json"; import projInfo from "data/projInfo.json";
import "game/notifications"; import "game/notifications";
import state from "game/state"; import state from "game/state";
import "util/galaxy";
import { load } from "util/save"; import { load } from "util/save";
import { useRegisterSW } from "virtual:pwa-register/vue"; import { useRegisterSW } from "virtual:pwa-register/vue";
import type { App as VueApp } from "vue"; import type { App as VueApp } from "vue";
import { createApp, nextTick } from "vue"; import { createApp, nextTick } from "vue";
import { useToast } from "vue-toastification"; import { useToast } from "vue-toastification";
import "util/galaxy"; import { globalBus } from "./game/events";
import { startGameLoop } from "./game/gameLoop";
declare global { declare global {
/** /**
@ -56,8 +58,6 @@ requestAnimationFrame(async () => {
"padding: 4px;" "padding: 4px;"
); );
await load(); await load();
const { globalBus } = await import("./game/events");
const { startGameLoop } = await import("./game/gameLoop");
// Create Vue // Create Vue
const vue = (window.vue = createApp(App)); const vue = (window.vue = createApp(App));

View file

@ -1,6 +1,8 @@
import { LoadablePlayerData } from "components/saves/SavesManager.vue"; import { LoadablePlayerData } from "components/saves/SavesManager.vue";
import { fixOldSave, getInitialLayers } from "data/projEntry";
import projInfo from "data/projInfo.json"; import projInfo from "data/projInfo.json";
import { globalBus } from "game/events"; import { globalBus } from "game/events";
import { addLayer, layers, removeLayer } from "game/layers";
import type { Player } from "game/player"; import type { Player } from "game/player";
import player, { stringifySave } from "game/player"; import player, { stringifySave } from "game/player";
import settings, { loadSettings } from "game/settings"; import settings, { loadSettings } from "game/settings";
@ -101,8 +103,6 @@ export const loadingSave = ref(false);
export async function loadSave(playerObj: Partial<Player>): Promise<void> { export async function loadSave(playerObj: Partial<Player>): Promise<void> {
console.info("Loading save", playerObj); console.info("Loading save", playerObj);
loadingSave.value = true; loadingSave.value = true;
const { layers, removeLayer, addLayer } = await import("game/layers");
const { fixOldSave, getInitialLayers } = await import("data/projEntry");
for (const layer in layers) { for (const layer in layers) {
const l = layers[layer]; const l = layers[layer];