From 3138eca6d041aafc5dbee2480b966591f84154f9 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 18 Sep 2022 13:16:57 +0200 Subject: show dispatches and timeouts in outputpane --- web/pw-server/src/lib/components/OutputPane.svelte | 95 +++++++++++++++------- 1 file changed, 67 insertions(+), 28 deletions(-) (limited to 'web/pw-server/src/lib/components/OutputPane.svelte') diff --git a/web/pw-server/src/lib/components/OutputPane.svelte b/web/pw-server/src/lib/components/OutputPane.svelte index efd0d2c..91ffadc 100644 --- a/web/pw-server/src/lib/components/OutputPane.svelte +++ b/web/pw-server/src/lib/components/OutputPane.svelte @@ -6,6 +6,19 @@ let showRawStderr = false; + const PLURAL_MAP = { + dispatch: "dispatches", + ship: "ships", + }; + + function pluralize(num: number, word: string): string { + if (num == 1) { + return `1 ${word}`; + } else { + return `${num} ${PLURAL_MAP[word]}`; + } + } + $: if (matchLog) { playerLog = parsePlayerLog(1, matchLog); } else { @@ -16,36 +29,53 @@

Player log

{#if showRawStderr} -
- {playerLog.flatMap((turn) => turn.stderr).join("\n")} -
+
+ {playerLog.flatMap((turn) => turn.stderr).join("\n")} +
{:else} -
- {#each playerLog as logTurn, i} -
-
- Turn {i} - {#if logTurn.action?.type === "bad_command"} - invalid command - {/if} -
- {#if logTurn.action?.type === "bad_command"} -
-
{logTurn.action.command}
-
Parse error: {logTurn.action.error}
-
- {/if} - {#if logTurn.stderr.length > 0} -
stderr
-
- {#each logTurn.stderr as stdErrMsg} -
{stdErrMsg}
- {/each} -
- {/if} +
+ {#each playerLog as logTurn, i} +
+
+ Turn {i} + {#if logTurn.action?.type === "dispatches"} + {pluralize(logTurn.action.dispatches.length, "dispatch")} + {:else if logTurn.action?.type === "timeout"} + timeout + {:else if logTurn.action?.type === "bad_command"} + invalid command + {/if} +
+ {#if logTurn.action?.type === "dispatches"} +
+ {#each logTurn.action.dispatches as dispatch} +
+
+ {pluralize(dispatch.ship_count, "ship")} from {dispatch.origin} to {dispatch.destination} +
+ {#if dispatch.error} + {dispatch.error} + {/if} +
+ {/each} +
+ {:else if logTurn.action?.type === "bad_command"} +
+
{logTurn.action.command}
+
Parse error: {logTurn.action.error}
+
+ {/if} + {#if logTurn.stderr.length > 0} +
stderr
+
+ {#each logTurn.stderr as stdErrMsg} +
{stdErrMsg}
+ {/each} +
+ {/if} +
+ {/each}
- {/each} -
{/if}
@@ -81,6 +111,15 @@ color: red; } + .dispatch { + display: flex; + justify-content: space-between; + } + + .dispatch-error { + color: red; + } + .bad-command-container { border-left: 1px solid red; margin-left: 4px; -- cgit v1.2.3