forked from profectus/Profectus
Fixed things happening on save load
This commit is contained in:
parent
97fe313558
commit
72e73db048
5 changed files with 9 additions and 3 deletions
|
@ -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);
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
1
src/typings/player.d.ts
vendored
1
src/typings/player.d.ts
vendored
|
@ -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;
|
||||||
|
|
|
@ -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)))));
|
||||||
};
|
});
|
||||||
|
|
Loading…
Reference in a new issue