From 84478336291e33b634ba7c06c7a9ff5237ef6598 Mon Sep 17 00:00:00 2001 From: Khafra Date: Wed, 3 Jul 2024 00:42:16 -0400 Subject: [PATCH 1/3] fixup! load bonuses before load --- src/Synergism.ts | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Synergism.ts b/src/Synergism.ts index 3e7733a51..7c8335b1a 100644 --- a/src/Synergism.ts +++ b/src/Synergism.ts @@ -6176,12 +6176,6 @@ export const reloadShit = async (reset = false) => { disableHotkeys() - // Wait a tick to continue. This is a (likely futile) attempt to see if this solves save corrupting. - // This ensures all queued tasks are executed before continuing on. - await new Promise((res) => { - setTimeout(res, 0) - }) - const save = (await localforage.getItem('Synergysave2')) ?? localStorage.getItem('Synergysave2') @@ -6256,17 +6250,6 @@ export const reloadShit = async (reset = false) => { constantIntervals() changeTabColor() - eventCheck() - .catch(() => {}) - .finally(() => { - setInterval( - () => - eventCheck().catch((error: Error) => { - console.error(error) - }), - 15_000 - ) - }) showExitOffline() clearTimeout(preloadDeleteGame) @@ -6331,13 +6314,20 @@ window.addEventListener('load', async () => { document.title = `Synergism v${version}` generateEventHandlers() - - void reloadShit() - corruptionButtonsAdd() corruptionLoadoutTableCreate() - handleLogin().catch(console.error) + await Promise.allSettled([ + handleLogin(), + eventCheck() + .catch(() => {}) + .finally(() => { + setInterval( + () => eventCheck().catch(() => {}), + 15_000 + ) + }) + ]).finally(() => reloadShit()) }) window.addEventListener('unload', () => { From ad05dc734bf23fb4bfb31a997a67d08e008a8139 Mon Sep 17 00:00:00 2001 From: Khafra Date: Wed, 3 Jul 2024 01:15:53 -0400 Subject: [PATCH 2/3] fixup --- src/Event.ts | 4 ---- src/Synergism.ts | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Event.ts b/src/Event.ts index 6177c5c61..6b2b0a3ab 100644 --- a/src/Event.ts +++ b/src/Event.ts @@ -75,10 +75,6 @@ let nowEvent: EventData | null = null export const getEvent = () => nowEvent export const eventCheck = async () => { - if (!player.dayCheck) { - return - } - const response = await fetch('https://synergism.cc/api/v1/events/get') if (!response.ok) { diff --git a/src/Synergism.ts b/src/Synergism.ts index 7c8335b1a..26272f57a 100644 --- a/src/Synergism.ts +++ b/src/Synergism.ts @@ -6320,10 +6320,10 @@ window.addEventListener('load', async () => { await Promise.allSettled([ handleLogin(), eventCheck() - .catch(() => {}) + .catch(console.error) .finally(() => { setInterval( - () => eventCheck().catch(() => {}), + () => eventCheck().catch(console.error), 15_000 ) }) From b8d4e60ab7d9a3d48a23fbdd01e2a21deabee1f3 Mon Sep 17 00:00:00 2001 From: Khafra Date: Wed, 3 Jul 2024 13:00:39 -0400 Subject: [PATCH 3/3] fixup --- package.json | 2 +- src/ImportExport.ts | 6 +++--- src/Synergism.ts | 28 ++++++++++++++++------------ 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 919689051..988bd9373 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "husky": "^8.0.3", "stylelint": "^14.8.2", "stylelint-config-standard": "^25.0.0", - "typescript": "^5.0.3" + "typescript": "^5.5.3" }, "scripts": { "lint": "npx @biomejs/biome lint .", diff --git a/src/ImportExport.ts b/src/ImportExport.ts index 27b8bd7ff..4318e68a9 100644 --- a/src/ImportExport.ts +++ b/src/ImportExport.ts @@ -311,7 +311,7 @@ export const resetGame = async (force = true) => { export const importData = async ( e: Event, - importFunc: (save: string | null) => Promise | Promise + importFunc: typeof importSynergism ) => { const element = e.target as HTMLInputElement const file = element.files![0] @@ -333,10 +333,10 @@ export const importData = async ( element.value = '' handleLastModified(file.lastModified) - return importFunc(save) + return importFunc(save, false) } -export const importSynergism = async (input: string | null, reset = false) => { +export const importSynergism = async (input: string | null, reset: boolean) => { if (typeof input !== 'string') { return Alert(i18next.t('importexport.unableImport')) } diff --git a/src/Synergism.ts b/src/Synergism.ts index 26272f57a..1ffc90314 100644 --- a/src/Synergism.ts +++ b/src/Synergism.ts @@ -6161,11 +6161,13 @@ export const showExitOffline = () => { setTimeout(() => el.focus(), 100) } +let loggedIn = false + /** * Reloads shit. * @param reset if this param is passed, offline progression will not be calculated. */ -export const reloadShit = async (reset = false) => { +export const reloadShit = async (reset: boolean) => { clearTimers() // Shows a reset button when page loading seems to stop or cause an error @@ -6207,6 +6209,18 @@ export const reloadShit = async (reset = false) => { } if (!reset) { + loggedIn ||= !!await Promise.allSettled([ + handleLogin(), + eventCheck() + .catch(console.error) + .finally(() => { + setInterval( + () => eventCheck().catch(console.error), + 15_000 + ) + }) + ]) + await calculateOffline() } else { player.worlds.reset() @@ -6317,17 +6331,7 @@ window.addEventListener('load', async () => { corruptionButtonsAdd() corruptionLoadoutTableCreate() - await Promise.allSettled([ - handleLogin(), - eventCheck() - .catch(console.error) - .finally(() => { - setInterval( - () => eventCheck().catch(console.error), - 15_000 - ) - }) - ]).finally(() => reloadShit()) + reloadShit(false) }) window.addEventListener('unload', () => {