From 72e73db0484a778183a0baa46f7e9d9bdd63cf1a Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sat, 28 Aug 2021 11:35:25 -0500 Subject: [PATCH] Fixed things happening on save load --- src/data/layers/main.ts | 2 +- src/game/gameLoop.ts | 2 ++ src/game/player.ts | 1 + src/typings/player.d.ts | 1 + src/util/save.ts | 6 ++++-- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/data/layers/main.ts b/src/data/layers/main.ts index a19960f..d3a8610 100644 --- a/src/data/layers/main.ts +++ b/src/data/layers/main.ts @@ -820,7 +820,7 @@ for (const id in resources) { watch( () => resource.amount, (amount, oldAmount) => { - if (amount == null || oldAmount == null) { + if (amount == null || oldAmount == null || player.justLoaded) { return; } const resourceGain = Decimal.sub(amount, oldAmount); diff --git a/src/game/gameLoop.ts b/src/game/gameLoop.ts index d6c3f52..c1f9968 100644 --- a/src/game/gameLoop.ts +++ b/src/game/gameLoop.ts @@ -172,6 +172,8 @@ function update() { modUpdate(diff); updateOOMPS(trueDiff); updateLayers(diff); + + player.justLoaded = false; } export default function startGameLoop(): void { diff --git a/src/game/player.ts b/src/game/player.ts index bf029cd..bcee7a1 100644 --- a/src/game/player.ts +++ b/src/game/player.ts @@ -27,6 +27,7 @@ const state = reactive({ minimized: {}, modID: "", modVersion: "", + justLoaded: false, hasNaN: false, NaNPath: [], NaNReceiver: null, diff --git a/src/typings/player.d.ts b/src/typings/player.d.ts index 71d6748..deaef27 100644 --- a/src/typings/player.d.ts +++ b/src/typings/player.d.ts @@ -38,6 +38,7 @@ export interface PlayerData { minimized: Record; modID: string; modVersion: string; + justLoaded: boolean; hasNaN: boolean; NaNPath?: Array; NaNReceiver?: Record | null; diff --git a/src/util/save.ts b/src/util/save.ts index f87b334..5684a4e 100644 --- a/src/util/save.ts +++ b/src/util/save.ts @@ -31,6 +31,7 @@ export function getInitialStore(playerData: Partial = {}): PlayerDat modID: modInfo.id, modVersion: modInfo.versionNumber, layers: {}, + justLoaded: false, ...getStartingData(), // Values that don't get loaded/saved @@ -148,6 +149,7 @@ export async function loadSave(playerData: Partial): Promise { delete player.layers[prop]; } } + player.justLoaded = true; } export function applyPlayerData>( @@ -187,9 +189,9 @@ window.onbeforeunload = () => { } }; window.save = save; -export const hardReset = window.hardReset = async () => { +export const hardReset = (window.hardReset = async () => { await loadSave(newSave()); const modData = JSON.parse(decodeURIComponent(escape(atob(localStorage.getItem(modInfo.id)!)))); modData.active = player.id; localStorage.setItem(modInfo.id, btoa(unescape(encodeURIComponent(JSON.stringify(modData))))); -}; +});