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(
() => resource.amount,
(amount, oldAmount) => {
if (amount == null || oldAmount == null) {
if (amount == null || oldAmount == null || player.justLoaded) {
return;
}
const resourceGain = Decimal.sub(amount, oldAmount);

View file

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

View file

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

View file

@ -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;

View file

@ -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)))));
};
});