Remove Log Reset message

This commit is contained in:
Tobias Berger 2021-09-30 22:22:57 +02:00
parent d7690c6eee
commit 6e93a51a8b
5 changed files with 11 additions and 14 deletions

View file

@ -6,7 +6,7 @@
import type { Writable } from "svelte/store";
import { slide } from "svelte/transition";
import type { AddMessageEvent, ResetMessagesEvent, Message } from "../shark/Message";
import type { AddMessageEvent, ResetLogEvent, Message } from "../shark/Message";
import { MessageType } from "../shark/Message";
export let messages: Writable<Message[]>;
@ -14,15 +14,14 @@
const dispatch = createEventDispatcher<{
addMessage: AddMessageEvent;
resetLog: ResetMessagesEvent;
resetLog: ResetLogEvent;
}>();
// Shorthand
function addMessage(message: string, messageType?: MessageType) {
dispatch("addMessage", { message, messageType });
}
function resetMessages(notify = true) {
dispatch("resetLog", { notify });
function resetLog() {
dispatch("resetLog");
}
$: displayMessages = $messages.slice(-logLength).reverse();
@ -44,8 +43,7 @@
addMessage("error" + $messages.length, MessageType.error);
}}>Add Error</button
>
<button on:click={() => resetMessages()}>Clear log; notify</button>
<button on:click={() => resetMessages(false)}>Clear log; no-notify</button>
<button on:click={resetLog}>Clear log</button>
<ol id="message-log">
{#each displayMessages as message, i (message)}
{#if i < logLength}

View file

@ -1,5 +1,5 @@
<script lang="ts">
import type { AddMessageEvent, ResetMessagesEvent } from "../shark/Message";
import type { AddMessageEvent } from "../shark/Message";
import type { SharkGame } from "../shark/SharkGame";
import Log from "./Log.svelte";
import ResourceTable from "./ResourceTable/ResourceTable.svelte";
@ -15,8 +15,8 @@
function handleAddMessage(event: CustomEvent<AddMessageEvent>) {
game.Log.addMessage(event.detail.message, event.detail.messageType);
}
function handleResetLog(event: CustomEvent<ResetMessagesEvent>) {
game.Log.reset(event.detail.notify);
function handleResetLog() {
game.Log.reset();
}
let logLength: number;

View file

@ -20,9 +20,8 @@ export class Log extends StaticClass {
);
}
static reset(notify = true): void {
static reset(): void {
Message.even = true;
this.messages.set([]);
if (notify) this.addMessage("Log cleared");
}
}

View file

@ -1,5 +1,5 @@
export type AddMessageEvent = { message: string; messageType?: MessageType };
export type ResetMessagesEvent = { notify?: boolean };
export type ResetLogEvent = { notify: false };
export enum MessageType {
message = "message",

View file

@ -97,7 +97,7 @@ export class SaveHandler extends StaticClass {
return settings;
});
game.Log.reset(false);
game.Log.reset();
fullSave.messages.forEach((message) => {
game.Log.addMessage(message.message, message.type);