Change initialization
This commit is contained in:
parent
619d5bbae1
commit
066ed07316
4 changed files with 17 additions and 14 deletions
|
@ -8,8 +8,6 @@
|
||||||
import { onDestroy, onMount } from "svelte";
|
import { onDestroy, onMount } from "svelte";
|
||||||
import type { Unsubscriber } from "svelte/store";
|
import type { Unsubscriber } from "svelte/store";
|
||||||
|
|
||||||
SharkGame.init();
|
|
||||||
|
|
||||||
let root: HTMLElement;
|
let root: HTMLElement;
|
||||||
let unsubscribeSettings: Unsubscriber;
|
let unsubscribeSettings: Unsubscriber;
|
||||||
|
|
||||||
|
@ -40,6 +38,10 @@
|
||||||
<Modals>
|
<Modals>
|
||||||
<div slot="backdrop" id="modal-backdrop" on:click={closeModal} />
|
<div slot="backdrop" id="modal-backdrop" on:click={closeModal} />
|
||||||
</Modals>
|
</Modals>
|
||||||
|
{#await SharkGame.initialize()}
|
||||||
|
Loading...
|
||||||
|
{:then}
|
||||||
<Header game={SharkGame} title={SharkGame.title} />
|
<Header game={SharkGame} title={SharkGame.title} />
|
||||||
<Wrapper game={SharkGame} />
|
<Wrapper game={SharkGame} />
|
||||||
<Footer />
|
<Footer />
|
||||||
|
{/await}
|
||||||
|
|
|
@ -84,12 +84,14 @@ export class SaveHandler extends StaticClass {
|
||||||
Math.round((encodedSave.length / stringifiedSave.length) * 100 * 100) / 100
|
Math.round((encodedSave.length / stringifiedSave.length) * 100 * 100) / 100
|
||||||
}% size`
|
}% size`
|
||||||
);
|
);
|
||||||
console.timeEnd("Done saving");
|
|
||||||
|
|
||||||
localStorage.setItem(SaveHandler.saveName, encodedSave);
|
localStorage.setItem(SaveHandler.saveName, encodedSave);
|
||||||
|
console.timeEnd("Done saving");
|
||||||
}
|
}
|
||||||
|
|
||||||
static async load(game: typeof SharkGame): Promise<unknown> {
|
static async load(game: typeof SharkGame): Promise<void> {
|
||||||
|
console.debug("Loading");
|
||||||
|
console.time("Done loading");
|
||||||
const localSave = LZString.decompressFromBase64(localStorage.getItem(SaveHandler.saveName));
|
const localSave = LZString.decompressFromBase64(localStorage.getItem(SaveHandler.saveName));
|
||||||
const loadedSave = JSON.parse(localSave ?? "{}");
|
const loadedSave = JSON.parse(localSave ?? "{}");
|
||||||
const saveVersion = loadedSave.version ?? 0;
|
const saveVersion = loadedSave.version ?? 0;
|
||||||
|
@ -123,8 +125,7 @@ export class SaveHandler extends StaticClass {
|
||||||
game.Log.addMessage(message.content, message.type);
|
game.Log.addMessage(message.content, message.type);
|
||||||
});
|
});
|
||||||
game.TabHandler.currentTab = game.TabHandler.AllTabs[fullSave.selectedTab];
|
game.TabHandler.currentTab = game.TabHandler.AllTabs[fullSave.selectedTab];
|
||||||
|
console.timeEnd("Done loading");
|
||||||
return game;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static migrators: ((save: Save) => Save)[] = [
|
static migrators: ((save: Save) => Save)[] = [
|
||||||
|
|
|
@ -44,7 +44,7 @@ export class Settings extends StaticClass {
|
||||||
default: 1 as const,
|
default: 1 as const,
|
||||||
name: "Autosave" as const,
|
name: "Autosave" as const,
|
||||||
description: "How many seconds to wait between each autosave" as const,
|
description: "How many seconds to wait between each autosave" as const,
|
||||||
options: ["Off", 1, 5, 15, 60] as const,
|
options: ["Off", 1, 5, 10, 15, 60] as const,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,13 +67,13 @@ export class SharkGame extends StaticClass {
|
||||||
HomeActions,
|
HomeActions,
|
||||||
});
|
});
|
||||||
|
|
||||||
static init(): void {
|
static async initialize(): Promise<void> {
|
||||||
SaveHandler.load(this);
|
await SaveHandler.load(this);
|
||||||
|
|
||||||
|
SharkGame.title = SharkGame.#GAME_NAMES[Math.floor(Math.random() * SharkGame.#GAME_NAMES.length)];
|
||||||
|
|
||||||
Log.init();
|
Log.init();
|
||||||
SaveHandler.init(this);
|
SaveHandler.init(this);
|
||||||
|
|
||||||
SharkGame.title = SharkGame.#GAME_NAMES[Math.floor(Math.random() * SharkGame.#GAME_NAMES.length)];
|
|
||||||
}
|
}
|
||||||
static save(): void {
|
static save(): void {
|
||||||
SaveHandler.save(this);
|
SaveHandler.save(this);
|
||||||
|
|
Reference in a new issue