From 8feccfeb234b69b1069d6b972f13b77ee2c0459f Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 15 Oct 2022 20:23:20 +0200 Subject: show player logs on view match page --- web/pw-server/package.json | 4 +- web/pw-server/src/lib/components/OutputPane.svelte | 143 +------------------ web/pw-server/src/lib/components/PlayerLog.svelte | 152 +++++++++++++++++++++ web/pw-server/src/lib/components/Visualizer.svelte | 13 +- web/pw-server/src/lib/constants.ts | 11 ++ web/pw-server/src/routes/editor.svelte | 1 - web/pw-server/src/routes/matches/[match_id].svelte | 42 ++++++ web/pw-server/svelte.config.js | 8 +- 8 files changed, 216 insertions(+), 158 deletions(-) create mode 100644 web/pw-server/src/lib/components/PlayerLog.svelte create mode 100644 web/pw-server/src/lib/constants.ts diff --git a/web/pw-server/package.json b/web/pw-server/package.json index 474f38c..604a820 100644 --- a/web/pw-server/package.json +++ b/web/pw-server/package.json @@ -26,7 +26,7 @@ "prettier": "^2.4.1", "prettier-plugin-svelte": "^2.4.0", "sass": "^1.49.7", - "svelte": "^3.44.0", + "svelte": "^3.52.0", "svelte-check": "^2.2.6", "svelte-preprocess": "^4.9.4", "tslib": "^2.3.1", @@ -41,7 +41,7 @@ "dayjs": "^1.10.7", "planetwars-rs": "file:../planetwars-rs/pkg", "pw-visualizer": "file:../pw-visualizer", - "svelte-select": "^4.4.7" + "svelte-select": "^5.0.0-beta.31" }, "type": "module" } diff --git a/web/pw-server/src/lib/components/OutputPane.svelte b/web/pw-server/src/lib/components/OutputPane.svelte index 91ffadc..68c5c3b 100644 --- a/web/pw-server/src/lib/components/OutputPane.svelte +++ b/web/pw-server/src/lib/components/OutputPane.svelte @@ -1,157 +1,22 @@ -
+

Player log

- {#if showRawStderr} -
- {playerLog.flatMap((turn) => turn.stderr).join("\n")} -
- {:else} -
- {#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} -
- {/if} +
diff --git a/web/pw-server/src/lib/components/Visualizer.svelte b/web/pw-server/src/lib/components/Visualizer.svelte index 8517a39..4fe8ab4 100644 --- a/web/pw-server/src/lib/components/Visualizer.svelte +++ b/web/pw-server/src/lib/components/Visualizer.svelte @@ -2,24 +2,13 @@ import { onDestroy, onMount } from "svelte"; import * as visualizer from "pw-visualizer"; import init_wasm_module from "planetwars-rs"; + import { PLAYER_COLORS } from "$lib/constants"; export let matchLog = null; export let matchData: object; // match object as returned by api let initialized = false; - const PLAYER_COLORS = [ - "#ff8000", - "#0080ff", - "#ff6693", - "#3fcb55", - "#cbc33f", - "#cf40e9", - "#ff3f0d", - "#1beef0", - "#0dc5ff", - ]; - onMount(async () => { await init_wasm_module(); diff --git a/web/pw-server/src/lib/constants.ts b/web/pw-server/src/lib/constants.ts new file mode 100644 index 0000000..208bf09 --- /dev/null +++ b/web/pw-server/src/lib/constants.ts @@ -0,0 +1,11 @@ +export const PLAYER_COLORS = [ + "#ff8000", + "#0080ff", + "#ff6693", + "#3fcb55", + "#cbc33f", + "#cf40e9", + "#ff3f0d", + "#1beef0", + "#0dc5ff", +]; diff --git a/web/pw-server/src/routes/editor.svelte b/web/pw-server/src/routes/editor.svelte index ff8232c..ee4eef9 100644 --- a/web/pw-server/src/routes/editor.svelte +++ b/web/pw-server/src/routes/editor.svelte @@ -12,7 +12,6 @@ import { debounce } from "$lib/utils"; import SubmitPane from "$lib/components/SubmitPane.svelte"; import OutputPane from "$lib/components/OutputPane.svelte"; - import BotName from "./bots/[bot_name].svelte"; enum ViewMode { Editor, diff --git a/web/pw-server/src/routes/matches/[match_id].svelte b/web/pw-server/src/routes/matches/[match_id].svelte index 11d6ee3..25438ad 100644 --- a/web/pw-server/src/routes/matches/[match_id].svelte +++ b/web/pw-server/src/routes/matches/[match_id].svelte @@ -22,6 +22,9 @@
+
+
+ +
+
+ +
+
diff --git a/web/pw-server/svelte.config.js b/web/pw-server/svelte.config.js index fe396f9..02b4db9 100644 --- a/web/pw-server/svelte.config.js +++ b/web/pw-server/svelte.config.js @@ -12,13 +12,13 @@ const config = { preprocess: [ sveltePreprocess(), mdsvex({ - extensions: ['.md'], + extensions: [".md"], layout: { - docs: 'src/routes/docs/doc.svelte', - } + docs: "src/routes/docs/doc.svelte", + }, }), ], - extensions: ['.svelte', '.md'], + extensions: [".svelte", ".md"], kit: { adapter: adapter(), -- cgit v1.2.3