From 83a5db08be6e1aadb3d2568cab25bf62fe404b0e Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Sat, 2 Oct 2021 21:20:53 +0200 Subject: [PATCH] Rename SharkGame.Log to .MessageHandler --- src/components/Header.svelte | 2 +- src/components/Wrapper.svelte | 11 ++++++++--- src/shark/{Log.ts => MessageHandler.ts} | 6 +++--- src/shark/SaveHandler.ts | 6 +++--- src/shark/SharkGame.ts | 11 ++++++----- 5 files changed, 21 insertions(+), 15 deletions(-) rename src/shark/{Log.ts => MessageHandler.ts} (79%) diff --git a/src/components/Header.svelte b/src/components/Header.svelte index 3d5de22..0e96fb9 100644 --- a/src/components/Header.svelte +++ b/src/components/Header.svelte @@ -13,7 +13,7 @@ const mainHeaderButtons = { save() { - game.SaveHandler.save(game); + return game.SaveHandler.save(game); }, settings() { openModal(SettingsModal, { settings: game.Settings.settings }, { replace: true }); diff --git a/src/components/Wrapper.svelte b/src/components/Wrapper.svelte index 50b534e..0565d9f 100644 --- a/src/components/Wrapper.svelte +++ b/src/components/Wrapper.svelte @@ -13,10 +13,10 @@ sidebarExpanded = to ?? !sidebarExpanded; } function handleAddMessage(event: CustomEvent) { - game.Log.addMessage(event.detail.message, event.detail.messageType); + game.MessageHandler.addMessage(event.detail.message, event.detail.messageType); } function handleResetLog() { - game.Log.reset(); + game.MessageHandler.reset(); } let logLength: number; @@ -30,7 +30,12 @@
- +
toggleSidebar(false)}>
diff --git a/src/shark/Log.ts b/src/shark/MessageHandler.ts similarity index 79% rename from src/shark/Log.ts rename to src/shark/MessageHandler.ts index d91314f..f9ff039 100644 --- a/src/shark/Log.ts +++ b/src/shark/MessageHandler.ts @@ -4,19 +4,19 @@ import { Message, MessageType } from "./Message"; import { Settings } from "./Settings"; import { StaticClass } from "./StaticClass"; -export class Log extends StaticClass { +export class MessageHandler extends StaticClass { static messages = writable([]); static #maxLogLength: number; static init(): void { Settings.settings.subscribe((settings) => { - Log.#maxLogLength = Math.max(...settings.layout.logLength.options); + MessageHandler.#maxLogLength = Math.max(...settings.layout.logLength.options); })(); } static addMessage(message: string, messageType: MessageType = MessageType.message): void { this.messages.update((oldMessages) => - [...oldMessages, new Message(message, messageType)].slice(-Log.#maxLogLength) + [...oldMessages, new Message(message, messageType)].slice(-MessageHandler.#maxLogLength) ); } diff --git a/src/shark/SaveHandler.ts b/src/shark/SaveHandler.ts index 59d223b..0048a00 100644 --- a/src/shark/SaveHandler.ts +++ b/src/shark/SaveHandler.ts @@ -40,7 +40,7 @@ export class SaveHandler extends StaticClass { console.debug("Saving"); console.time("Done saving"); const messages = await new Promise((resolve) => { - game.Log.messages.subscribe((messages) => { + game.MessageHandler.messages.subscribe((messages) => { resolve(messages); })(); }); @@ -119,10 +119,10 @@ export class SaveHandler extends StaticClass { return settings; }); - game.Log.reset(); + game.MessageHandler.reset(); fullSave.messages.forEach((message) => { - game.Log.addMessage(message.content, message.type); + game.MessageHandler.addMessage(message.content, message.type); }); game.TabHandler.currentTab = game.TabHandler.AllTabs[fullSave.selectedTab]; console.timeEnd("Done loading"); diff --git a/src/shark/SharkGame.ts b/src/shark/SharkGame.ts index 94cf898..ce51bf3 100644 --- a/src/shark/SharkGame.ts +++ b/src/shark/SharkGame.ts @@ -1,5 +1,5 @@ import { Resources } from "./data/Resources"; -import { Log } from "./Log"; +import { MessageHandler } from "./MessageHandler"; import { SaveHandler } from "./SaveHandler"; import { Settings } from "./Settings"; import { StaticClass } from "./StaticClass"; @@ -59,7 +59,7 @@ export class SharkGame extends StaticClass { static title: string; static readonly Settings = Settings; - static readonly Log = Log; + static readonly MessageHandler = MessageHandler; static readonly Resources = Resources; static readonly TabHandler = TabHandler; static readonly SaveHandler = SaveHandler; @@ -72,11 +72,12 @@ export class SharkGame extends StaticClass { SharkGame.title = SharkGame.#GAME_NAMES[Math.floor(Math.random() * SharkGame.#GAME_NAMES.length)]; - Log.init(); + MessageHandler.init(); SaveHandler.init(this); } - static save(): void { - SaveHandler.save(this); + + static save(): Promise { + return SaveHandler.save(this); } }