From 7e04b635cd39d4e35a8a917827daf7109b8c5465 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Mon, 27 Sep 2021 14:36:40 +0200 Subject: [PATCH] Remember that stores exist --- src/components/Header.svelte | 4 + src/components/Log.svelte | 28 +++--- .../ResourceTable/ResourceGroup.svelte | 48 ++++++++++ .../{ => ResourceTable}/ResourceTable.svelte | 92 +++++++------------ src/components/Wrapper.svelte | 2 +- src/shark/Log.ts | 29 ++++-- 6 files changed, 119 insertions(+), 84 deletions(-) create mode 100644 src/components/ResourceTable/ResourceGroup.svelte rename src/components/{ => ResourceTable}/ResourceTable.svelte (51%) diff --git a/src/components/Header.svelte b/src/components/Header.svelte index 1ee615f..44e0c82 100644 --- a/src/components/Header.svelte +++ b/src/components/Header.svelte @@ -81,6 +81,10 @@ pointer-events: none; + > span { + font-weight: bold; + } + > ul { text-align: center; font-weight: bold; diff --git a/src/components/Log.svelte b/src/components/Log.svelte index 9d35236..9d18853 100644 --- a/src/components/Log.svelte +++ b/src/components/Log.svelte @@ -1,45 +1,45 @@ + +
    - {#each displaymessages as message, i} + {#each displayMessages as message, i} {#if i < logLength}
  1. {message} diff --git a/src/components/ResourceTable/ResourceGroup.svelte b/src/components/ResourceTable/ResourceGroup.svelte new file mode 100644 index 0000000..b9b469d --- /dev/null +++ b/src/components/ResourceTable/ResourceGroup.svelte @@ -0,0 +1,48 @@ + + + + + + {collapsed ? "▲" : "▼"} +

    {categoryName}

    + +{#if !collapsed} + {#each resources as [resourceName, resource], index} + + {resourceName} + {resource.amount} + {Math.round(100 * resource.change) / 100}/s + + {/each} +{/if} + + diff --git a/src/components/ResourceTable.svelte b/src/components/ResourceTable/ResourceTable.svelte similarity index 51% rename from src/components/ResourceTable.svelte rename to src/components/ResourceTable/ResourceTable.svelte index 40472c5..e4bc3f3 100644 --- a/src/components/ResourceTable.svelte +++ b/src/components/ResourceTable/ResourceTable.svelte @@ -1,4 +1,7 @@ - +
    diff --git a/src/shark/Log.ts b/src/shark/Log.ts index 6c7892c..9c694b3 100644 --- a/src/shark/Log.ts +++ b/src/shark/Log.ts @@ -1,15 +1,26 @@ -import type { Message } from "./Message"; -import { SharkGame } from "./SharkGame"; +import { writable } from "svelte/store"; + +import { Message, MessageType } from "./Message"; +import { Settings } from "./Settings"; import { StaticClass } from "./StaticClass"; export class Log extends StaticClass { - static #messages: Message[] = []; - static get messages(): Message[] { - return this.#messages; - } - static set messages(messages: Message[]) { - this.#messages = messages.slice( - -Math.max(...SharkGame.Settings.logLength.options) + static messages = writable([]); + + static addMessage( + message: string, + messageType: MessageType = MessageType.message + ): void { + this.messages.update((oldMessages) => + [...oldMessages, new Message(message, messageType)].slice( + -Math.max(...Settings.logLength.options) + ) ); } + + static reset(): void { + Message.even = true; + this.messages.set([]); + this.addMessage("Log cleared"); + } }