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 +++++++++++++++------- web/pw-server/src/lib/log_parser.ts | 24 +++++- 2 files changed, 89 insertions(+), 30 deletions(-) (limited to 'web/pw-server/src/lib') 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; diff --git a/web/pw-server/src/lib/log_parser.ts b/web/pw-server/src/lib/log_parser.ts index 77c459f..da1d3c0 100644 --- a/web/pw-server/src/lib/log_parser.ts +++ b/web/pw-server/src/lib/log_parser.ts @@ -5,7 +5,11 @@ export type PlayerLogTurn = { stderr: string[]; }; -type PlayerAction = BadCommand; +type PlayerAction = Timeout | BadCommand | Dispatches; + +type Timeout = { + type: "timeout"; +}; type BadCommand = { type: "bad_command"; @@ -13,6 +17,18 @@ type BadCommand = { error: string; }; +type Dispatches = { + type: "dispatches"; + dispatches: Dispatch[]; +}; + +type Dispatch = { + origin: string; + destination: string; + ship_count: number; + error?: string; +}; + function createEmptyLogTurn(): PlayerLogTurn { return { stderr: [], @@ -43,9 +59,13 @@ export function parsePlayerLog(playerId: number, logText: string): PlayerLog { case "stderr": { let msg = logMessage["message"]; turn.stderr.push(msg); + break; } - case "bad_command": { + case "timeout": + case "bad_command": + case "dispatches": { turn.action = logMessage; + break; } } } -- cgit v1.2.3