introduce turn-based log parser

This commit is contained in:
Ilion Beyst 2022-09-16 23:28:32 +02:00
parent 36c16aa8c7
commit a70689faa9
2 changed files with 14 additions and 24 deletions

View file

@ -1,34 +1,21 @@
<script lang="ts"> <script lang="ts">
import { parsePlayerLog, PlayerLog } from "$lib/log_parser";
export let matchLog: string; export let matchLog: string;
let playerLog: PlayerLog;
function getStdErr(botId: number, log?: string): string { $: if (matchLog) {
if (!log) { playerLog = parsePlayerLog(1, matchLog);
return ""; } else {
} 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");
} }
$: botStdErr = getStdErr(1, matchLog);
</script> </script>
<div class="output"> <div class="output">
{#if botStdErr.length > 0} <h3 class="output-header">Player log</h3>
<h3 class="output-header">stderr:</h3> <div class="output-text stderr-text">
<div class="output-text"> {playerLog.flatMap((turn) => turn.stderr).join("\n")}
{botStdErr} </div>
</div>
{/if}
</div> </div>
<style lang="scss"> <style lang="scss">
@ -41,6 +28,9 @@
.output-text { .output-text {
color: #ccc; color: #ccc;
}
.stderr-text {
font-family: monospace; font-family: monospace;
white-space: pre-wrap; white-space: pre-wrap;
} }