Remove Log Reset message
This commit is contained in:
parent
d7690c6eee
commit
6e93a51a8b
5 changed files with 11 additions and 14 deletions
|
@ -6,7 +6,7 @@
|
||||||
import type { Writable } from "svelte/store";
|
import type { Writable } from "svelte/store";
|
||||||
import { slide } from "svelte/transition";
|
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";
|
import { MessageType } from "../shark/Message";
|
||||||
|
|
||||||
export let messages: Writable<Message[]>;
|
export let messages: Writable<Message[]>;
|
||||||
|
@ -14,15 +14,14 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{
|
const dispatch = createEventDispatcher<{
|
||||||
addMessage: AddMessageEvent;
|
addMessage: AddMessageEvent;
|
||||||
resetLog: ResetMessagesEvent;
|
resetLog: ResetLogEvent;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// Shorthand
|
|
||||||
function addMessage(message: string, messageType?: MessageType) {
|
function addMessage(message: string, messageType?: MessageType) {
|
||||||
dispatch("addMessage", { message, messageType });
|
dispatch("addMessage", { message, messageType });
|
||||||
}
|
}
|
||||||
function resetMessages(notify = true) {
|
function resetLog() {
|
||||||
dispatch("resetLog", { notify });
|
dispatch("resetLog");
|
||||||
}
|
}
|
||||||
|
|
||||||
$: displayMessages = $messages.slice(-logLength).reverse();
|
$: displayMessages = $messages.slice(-logLength).reverse();
|
||||||
|
@ -44,8 +43,7 @@
|
||||||
addMessage("error" + $messages.length, MessageType.error);
|
addMessage("error" + $messages.length, MessageType.error);
|
||||||
}}>Add Error</button
|
}}>Add Error</button
|
||||||
>
|
>
|
||||||
<button on:click={() => resetMessages()}>Clear log; notify</button>
|
<button on:click={resetLog}>Clear log</button>
|
||||||
<button on:click={() => resetMessages(false)}>Clear log; no-notify</button>
|
|
||||||
<ol id="message-log">
|
<ol id="message-log">
|
||||||
{#each displayMessages as message, i (message)}
|
{#each displayMessages as message, i (message)}
|
||||||
{#if i < logLength}
|
{#if i < logLength}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { AddMessageEvent, ResetMessagesEvent } from "../shark/Message";
|
import type { AddMessageEvent } from "../shark/Message";
|
||||||
import type { SharkGame } from "../shark/SharkGame";
|
import type { SharkGame } from "../shark/SharkGame";
|
||||||
import Log from "./Log.svelte";
|
import Log from "./Log.svelte";
|
||||||
import ResourceTable from "./ResourceTable/ResourceTable.svelte";
|
import ResourceTable from "./ResourceTable/ResourceTable.svelte";
|
||||||
|
@ -15,8 +15,8 @@
|
||||||
function handleAddMessage(event: CustomEvent<AddMessageEvent>) {
|
function handleAddMessage(event: CustomEvent<AddMessageEvent>) {
|
||||||
game.Log.addMessage(event.detail.message, event.detail.messageType);
|
game.Log.addMessage(event.detail.message, event.detail.messageType);
|
||||||
}
|
}
|
||||||
function handleResetLog(event: CustomEvent<ResetMessagesEvent>) {
|
function handleResetLog() {
|
||||||
game.Log.reset(event.detail.notify);
|
game.Log.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
let logLength: number;
|
let logLength: number;
|
||||||
|
|
|
@ -20,9 +20,8 @@ export class Log extends StaticClass {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static reset(notify = true): void {
|
static reset(): void {
|
||||||
Message.even = true;
|
Message.even = true;
|
||||||
this.messages.set([]);
|
this.messages.set([]);
|
||||||
if (notify) this.addMessage("Log cleared");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export type AddMessageEvent = { message: string; messageType?: MessageType };
|
export type AddMessageEvent = { message: string; messageType?: MessageType };
|
||||||
export type ResetMessagesEvent = { notify?: boolean };
|
export type ResetLogEvent = { notify: false };
|
||||||
|
|
||||||
export enum MessageType {
|
export enum MessageType {
|
||||||
message = "message",
|
message = "message",
|
||||||
|
|
|
@ -97,7 +97,7 @@ export class SaveHandler extends StaticClass {
|
||||||
return settings;
|
return settings;
|
||||||
});
|
});
|
||||||
|
|
||||||
game.Log.reset(false);
|
game.Log.reset();
|
||||||
|
|
||||||
fullSave.messages.forEach((message) => {
|
fullSave.messages.forEach((message) => {
|
||||||
game.Log.addMessage(message.message, message.type);
|
game.Log.addMessage(message.message, message.type);
|
||||||
|
|
Reference in a new issue