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(
|
||||
() => resource.amount,
|
||||
(amount, oldAmount) => {
|
||||
if (amount == null || oldAmount == null) {
|
||||
if (amount == null || oldAmount == null || player.justLoaded) {
|
||||
return;
|
||||
}
|
||||
const resourceGain = Decimal.sub(amount, oldAmount);
|
||||
|
|
|
@ -172,6 +172,8 @@ function update() {
|
|||
modUpdate(diff);
|
||||
updateOOMPS(trueDiff);
|
||||
updateLayers(diff);
|
||||
|
||||
player.justLoaded = false;
|
||||
}
|
||||
|
||||
export default function startGameLoop(): void {
|
||||
|
|
|
@ -27,6 +27,7 @@ const state = reactive<PlayerData>({
|
|||
minimized: {},
|
||||
modID: "",
|
||||
modVersion: "",
|
||||
justLoaded: false,
|
||||
hasNaN: false,
|
||||
NaNPath: [],
|
||||
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>;
|
||||
modID: string;
|
||||
modVersion: string;
|
||||
justLoaded: boolean;
|
||||
hasNaN: boolean;
|
||||
NaNPath?: Array<string>;
|
||||
NaNReceiver?: Record<string, unknown> | null;
|
||||
|
|
|
@ -31,6 +31,7 @@ export function getInitialStore(playerData: Partial<PlayerData> = {}): 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<PlayerData>): Promise<void> {
|
|||
delete player.layers[prop];
|
||||
}
|
||||
}
|
||||
player.justLoaded = true;
|
||||
}
|
||||
|
||||
export function applyPlayerData<T extends Record<string, any>>(
|
||||
|
@ -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)))));
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue