Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixup! load bonuses before load #605

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down
4 changes: 0 additions & 4 deletions src/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/ImportExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export const resetGame = async (force = true) => {

export const importData = async (
e: Event,
importFunc: (save: string | null) => Promise<void> | Promise<undefined>
importFunc: typeof importSynergism
) => {
const element = e.target as HTMLInputElement
const file = element.files![0]
Expand All @@ -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'))
}
Expand Down
38 changes: 16 additions & 22 deletions src/Synergism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -6176,12 +6178,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<Blob>('Synergysave2'))
?? localStorage.getItem('Synergysave2')

Expand Down Expand Up @@ -6213,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()
Expand Down Expand Up @@ -6256,17 +6264,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)

Expand Down Expand Up @@ -6331,13 +6328,10 @@ window.addEventListener('load', async () => {
document.title = `Synergism v${version}`

generateEventHandlers()

void reloadShit()

corruptionButtonsAdd()
corruptionLoadoutTableCreate()

handleLogin().catch(console.error)
reloadShit(false)
})

window.addEventListener('unload', () => {
Expand Down
Loading