From a70689faa93961a1e9a8c35d7e5cd90686112173 Mon Sep 17 00:00:00 2001
From: Ilion Beyst <ilion.beyst@gmail.com>
Date: Fri, 16 Sep 2022 23:28:32 +0200
Subject: introduce turn-based log parser

---
 web/pw-server/src/lib/components/OutputPane.svelte | 38 ++++++++--------------
 1 file changed, 14 insertions(+), 24 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 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;
   }
-- 
cgit v1.2.3

