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 type { Unsubscriber } from "svelte/store";
|
||||
|
||||
SharkGame.init();
|
||||
|
||||
let root: HTMLElement;
|
||||
let unsubscribeSettings: Unsubscriber;
|
||||
|
||||
|
@ -40,6 +38,10 @@
|
|||
<Modals>
|
||||
<div slot="backdrop" id="modal-backdrop" on:click={closeModal} />
|
||||
</Modals>
|
||||
<Header game={SharkGame} title={SharkGame.title} />
|
||||
<Wrapper game={SharkGame} />
|
||||
<Footer />
|
||||
{#await SharkGame.initialize()}
|
||||
Loading...
|
||||
{:then}
|
||||
<Header game={SharkGame} title={SharkGame.title} />
|
||||
<Wrapper game={SharkGame} />
|
||||
<Footer />
|
||||
{/await}
|
||||
|
|
|
@ -84,12 +84,14 @@ export class SaveHandler extends StaticClass {
|
|||
Math.round((encodedSave.length / stringifiedSave.length) * 100 * 100) / 100
|
||||
}% size`
|
||||
);
|
||||
console.timeEnd("Done saving");
|
||||
|
||||
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 loadedSave = JSON.parse(localSave ?? "{}");
|
||||
const saveVersion = loadedSave.version ?? 0;
|
||||
|
@ -123,8 +125,7 @@ export class SaveHandler extends StaticClass {
|
|||
game.Log.addMessage(message.content, message.type);
|
||||
});
|
||||
game.TabHandler.currentTab = game.TabHandler.AllTabs[fullSave.selectedTab];
|
||||
|
||||
return game;
|
||||
console.timeEnd("Done loading");
|
||||
}
|
||||
|
||||
static migrators: ((save: Save) => Save)[] = [
|
||||
|
|
|
@ -44,7 +44,7 @@ export class Settings extends StaticClass {
|
|||
default: 1 as const,
|
||||
name: "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,
|
||||
});
|
||||
|
||||
static init(): void {
|
||||
SaveHandler.load(this);
|
||||
static async initialize(): Promise<void> {
|
||||
await SaveHandler.load(this);
|
||||
|
||||
SharkGame.title = SharkGame.#GAME_NAMES[Math.floor(Math.random() * SharkGame.#GAME_NAMES.length)];
|
||||
|
||||
Log.init();
|
||||
SaveHandler.init(this);
|
||||
|
||||
SharkGame.title = SharkGame.#GAME_NAMES[Math.floor(Math.random() * SharkGame.#GAME_NAMES.length)];
|
||||
}
|
||||
static save(): void {
|
||||
SaveHandler.save(this);
|
||||
|
|
Reference in a new issue