Fixed things happening on save load

This commit is contained in:
thepaperpilot 2021-08-28 11:35:25 -05:00
parent 97fe313558
commit 72e73db048
5 changed files with 9 additions and 3 deletions

View file

@ -820,7 +820,7 @@ for (const id in resources) {
watch( watch(
() => resource.amount, () => resource.amount,
(amount, oldAmount) => { (amount, oldAmount) => {
if (amount == null || oldAmount == null) { if (amount == null || oldAmount == null || player.justLoaded) {
return; return;
} }
const resourceGain = Decimal.sub(amount, oldAmount); const resourceGain = Decimal.sub(amount, oldAmount);

View file

@ -172,6 +172,8 @@ function update() {
modUpdate(diff); modUpdate(diff);
updateOOMPS(trueDiff); updateOOMPS(trueDiff);
updateLayers(diff); updateLayers(diff);
player.justLoaded = false;
} }
export default function startGameLoop(): void { export default function startGameLoop(): void {

View file

@ -27,6 +27,7 @@ const state = reactive<PlayerData>({
minimized: {}, minimized: {},
modID: "", modID: "",
modVersion: "", modVersion: "",
justLoaded: false,
hasNaN: false, hasNaN: false,
NaNPath: [], NaNPath: [],
NaNReceiver: null, NaNReceiver: null,

View file

@ -38,6 +38,7 @@ export interface PlayerData {
minimized: Record<string, boolean>; minimized: Record<string, boolean>;
modID: string; modID: string;
modVersion: string; modVersion: string;
justLoaded: boolean;
hasNaN: boolean; hasNaN: boolean;
NaNPath?: Array<string>; NaNPath?: Array<string>;
NaNReceiver?: Record<string, unknown> | null; NaNReceiver?: Record<string, unknown> | null;

View file

@ -31,6 +31,7 @@ export function getInitialStore(playerData: Partial<PlayerData> = {}): PlayerDat
modID: modInfo.id, modID: modInfo.id,
modVersion: modInfo.versionNumber, modVersion: modInfo.versionNumber,
layers: {}, layers: {},
justLoaded: false,
...getStartingData(), ...getStartingData(),
// Values that don't get loaded/saved // Values that don't get loaded/saved
@ -148,6 +149,7 @@ export async function loadSave(playerData: Partial<PlayerData>): Promise<void> {
delete player.layers[prop]; delete player.layers[prop];
} }
} }
player.justLoaded = true;
} }
export function applyPlayerData<T extends Record<string, any>>( export function applyPlayerData<T extends Record<string, any>>(
@ -187,9 +189,9 @@ window.onbeforeunload = () => {
} }
}; };
window.save = save; window.save = save;
export const hardReset = window.hardReset = async () => { export const hardReset = (window.hardReset = async () => {
await loadSave(newSave()); await loadSave(newSave());
const modData = JSON.parse(decodeURIComponent(escape(atob(localStorage.getItem(modInfo.id)!)))); const modData = JSON.parse(decodeURIComponent(escape(atob(localStorage.getItem(modInfo.id)!))));
modData.active = player.id; modData.active = player.id;
localStorage.setItem(modInfo.id, btoa(unescape(encodeURIComponent(JSON.stringify(modData))))); localStorage.setItem(modInfo.id, btoa(unescape(encodeURIComponent(JSON.stringify(modData)))));
}; });