diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-09-16 23:28:32 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-09-16 23:28:32 +0200 |
commit | a70689faa93961a1e9a8c35d7e5cd90686112173 (patch) | |
tree | 5717b8039b8f4e0503e3920114f1e8d78977c7ff /web/pw-server/src/lib/components | |
parent | 36c16aa8c780e3ff9e2e08b7c98891fab59692c7 (diff) | |
download | planetwars.dev-a70689faa93961a1e9a8c35d7e5cd90686112173.tar.xz planetwars.dev-a70689faa93961a1e9a8c35d7e5cd90686112173.zip |
introduce turn-based log parser
Diffstat (limited to 'web/pw-server/src/lib/components')
-rw-r--r-- | web/pw-server/src/lib/components/OutputPane.svelte | 38 | ||||
-rw-r--r-- | web/pw-server/src/lib/components/log_viewer/LogTurn.svelte | 0 |
2 files changed, 14 insertions, 24 deletions
diff --git a/web/pw-server/src/lib/components/OutputPane.svelte b/web/pw-server/src/lib/components/OutputPane.svelte index 4123902..759fd4c 100644 --- a/web/pw-server/src/lib/components/OutputPane.svelte +++ b/web/pw-server/src/lib/components/OutputPane.svelte @@ -1,34 +1,21 @@ <script lang="ts"> - export let matchLog: string; + import { parsePlayerLog, PlayerLog } from "$lib/log_parser"; - function getStdErr(botId: number, log?: string): string { - if (!log) { - return ""; - } + export let matchLog: string; + let playerLog: PlayerLog; - let output = []; - log - .split("\n") - .slice(0, -1) - .forEach((line) => { - let message = JSON.parse(line); - if (message["type"] === "stderr" && message["player_id"] === botId) { - output.push(message["message"]); - } - }); - return output.join("\n"); + $: if (matchLog) { + playerLog = parsePlayerLog(1, matchLog); + } else { + playerLog = []; } - - $: botStdErr = getStdErr(1, matchLog); </script> <div class="output"> - {#if botStdErr.length > 0} - <h3 class="output-header">stderr:</h3> - <div class="output-text"> - {botStdErr} - </div> - {/if} + <h3 class="output-header">Player log</h3> + <div class="output-text stderr-text"> + {playerLog.flatMap((turn) => turn.stderr).join("\n")} + </div> </div> <style lang="scss"> @@ -41,6 +28,9 @@ .output-text { color: #ccc; + } + + .stderr-text { font-family: monospace; white-space: pre-wrap; } diff --git a/web/pw-server/src/lib/components/log_viewer/LogTurn.svelte b/web/pw-server/src/lib/components/log_viewer/LogTurn.svelte new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/web/pw-server/src/lib/components/log_viewer/LogTurn.svelte |