Change initialization

This commit is contained in:
Tobias Berger 2021-10-02 20:12:21 +02:00
parent 619d5bbae1
commit 066ed07316
4 changed files with 17 additions and 14 deletions

View file

@ -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>
<Header game={SharkGame} title={SharkGame.title} /> {#await SharkGame.initialize()}
<Wrapper game={SharkGame} /> Loading...
<Footer /> {:then}
<Header game={SharkGame} title={SharkGame.title} />
<Wrapper game={SharkGame} />
<Footer />
{/await}

View file

@ -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)[] = [

View file

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

View file

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