From 00d31df58d0ea68b11600d98ebf53150a2a0cb88 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 30 Oct 2022 14:37:38 +0100 Subject: design new BotMatch view --- web/pw-server/src/lib/api_types.ts | 20 ++++ web/pw-server/src/lib/components/PlayerLog.svelte | 3 +- web/pw-server/src/lib/components/SubmitPane.svelte | 8 +- .../src/lib/components/matches/BotMatchCard.svelte | 104 +++++++++++++++++++++ .../src/lib/components/matches/BotMatchList.svelte | 19 ++++ .../src/lib/components/navbar/UserControls.svelte | 1 + web/pw-server/src/lib/matches.ts | 55 +++++++++++ .../src/routes/bots/[bot_name]/index.svelte | 8 +- .../src/routes/bots/[bot_name]/matches.svelte | 64 +++++++++++++ web/pw-server/src/routes/docs/rules.md | 2 +- 10 files changed, 269 insertions(+), 15 deletions(-) create mode 100644 web/pw-server/src/lib/api_types.ts create mode 100644 web/pw-server/src/lib/components/matches/BotMatchCard.svelte create mode 100644 web/pw-server/src/lib/components/matches/BotMatchList.svelte create mode 100644 web/pw-server/src/lib/matches.ts create mode 100644 web/pw-server/src/routes/bots/[bot_name]/matches.svelte (limited to 'web/pw-server') diff --git a/web/pw-server/src/lib/api_types.ts b/web/pw-server/src/lib/api_types.ts new file mode 100644 index 0000000..03190cb --- /dev/null +++ b/web/pw-server/src/lib/api_types.ts @@ -0,0 +1,20 @@ +export type Match = { + id: number; + timestamp: string; + state: string; + players: MatchPlayer[]; + winner: number; + map: Map; +}; + +export type MatchPlayer = { + bot_id: number; + bot_version_id: number; + bot_name: string; + owner_id?: number; + had_errors?: boolean; +}; + +export type Map = { + name: string; +}; diff --git a/web/pw-server/src/lib/components/PlayerLog.svelte b/web/pw-server/src/lib/components/PlayerLog.svelte index 52cae8e..60097d8 100644 --- a/web/pw-server/src/lib/components/PlayerLog.svelte +++ b/web/pw-server/src/lib/components/PlayerLog.svelte @@ -3,6 +3,7 @@ export let matchLog: string; export let playerId: number; + export let showStdErr: boolean = true; let playerLog: PlayerLog; @@ -66,7 +67,7 @@
Parse error: {logTurn.action.error}
{/if} - {#if logTurn.stderr.length > 0} + {#if showStdErr && logTurn.stderr.length > 0}
stderr
{#each logTurn.stderr as stdErrMsg} diff --git a/web/pw-server/src/lib/components/SubmitPane.svelte b/web/pw-server/src/lib/components/SubmitPane.svelte index e46166c..b1aaf9e 100644 --- a/web/pw-server/src/lib/components/SubmitPane.svelte +++ b/web/pw-server/src/lib/components/SubmitPane.svelte @@ -122,13 +122,7 @@
Map
-
diff --git a/web/pw-server/src/lib/components/matches/BotMatchCard.svelte b/web/pw-server/src/lib/components/matches/BotMatchCard.svelte new file mode 100644 index 0000000..2f50173 --- /dev/null +++ b/web/pw-server/src/lib/components/matches/BotMatchCard.svelte @@ -0,0 +1,104 @@ + + + +
+
+ {botMatch.outcome} +
+
+ +
+ {botMatch.map.name} +
+
+
+
+ {dayjs(botMatch.timestamp).format("YYYY-MM-DD HH:mm")} +
+
+ {#if botMatch.hadErrors} + ! Had errors + {/if} +
+
+
+ + + diff --git a/web/pw-server/src/lib/components/matches/BotMatchList.svelte b/web/pw-server/src/lib/components/matches/BotMatchList.svelte new file mode 100644 index 0000000..959cd07 --- /dev/null +++ b/web/pw-server/src/lib/components/matches/BotMatchList.svelte @@ -0,0 +1,19 @@ + + +
+ {#each botMatches as botMatch} + + {/each} +
+ + diff --git a/web/pw-server/src/lib/components/navbar/UserControls.svelte b/web/pw-server/src/lib/components/navbar/UserControls.svelte index 334b3b4..fa920ad 100644 --- a/web/pw-server/src/lib/components/navbar/UserControls.svelte +++ b/web/pw-server/src/lib/components/navbar/UserControls.svelte @@ -39,6 +39,7 @@ {$currentUser["username"]} +
Sign out
{:else} Sign in diff --git a/web/pw-server/src/lib/matches.ts b/web/pw-server/src/lib/matches.ts new file mode 100644 index 0000000..d889a0d --- /dev/null +++ b/web/pw-server/src/lib/matches.ts @@ -0,0 +1,55 @@ +import type { Match as ApiMatch, MatchPlayer as ApiMatchPlayer, Map } from "./api_types"; + +// match from the perspective of a bot +export type BotMatch = { + id: number; + opponent: BotMatchOpponent; + outcome: BotMatchOutcome; + timestamp: string; + map: Map; + hadErrors?: boolean; +}; + +export type BotMatchOutcome = "win" | "loss" | "tie"; + +export type BotMatchOpponent = { + bot_id: number; + bot_name: string; + owner_id?: number; +}; + +export function apiMatchtoBotMatch(bot_name: string, apiMatch: ApiMatch): BotMatch { + let player: ApiMatchPlayer; + let playerIndex: number; + let opponent: ApiMatchPlayer; + apiMatch.players.forEach((matchPlayer, index) => { + if (matchPlayer.bot_name === bot_name) { + player = matchPlayer; + playerIndex = index; + } else { + opponent = matchPlayer; + } + }); + + if (player === undefined || opponent === undefined || playerIndex === undefined) { + throw "could not assign player and opponent"; + } + + let outcome: BotMatchOutcome; + if (apiMatch.winner === playerIndex) { + outcome = "win"; + } else if (apiMatch.winner) { + outcome = "loss"; + } else { + outcome = "tie"; + } + + return { + id: apiMatch.id, + opponent, + outcome, + timestamp: apiMatch.timestamp, + map: apiMatch.map, + hadErrors: player.had_errors, + }; +} diff --git a/web/pw-server/src/routes/bots/[bot_name]/index.svelte b/web/pw-server/src/routes/bots/[bot_name]/index.svelte index b046754..a5934b6 100644 --- a/web/pw-server/src/routes/bots/[bot_name]/index.svelte +++ b/web/pw-server/src/routes/bots/[bot_name]/index.svelte @@ -100,9 +100,7 @@ View all {:else} -
- Nothing here yet -
+
Nothing here yet
{/if} {/if} @@ -115,9 +113,7 @@ All matches {:else} -
- No matches played yet -
+
No matches played yet
{/if} diff --git a/web/pw-server/src/routes/bots/[bot_name]/matches.svelte b/web/pw-server/src/routes/bots/[bot_name]/matches.svelte new file mode 100644 index 0000000..a3c97cb --- /dev/null +++ b/web/pw-server/src/routes/bots/[bot_name]/matches.svelte @@ -0,0 +1,64 @@ + + + + +
+ +
+ + diff --git a/web/pw-server/src/routes/docs/rules.md b/web/pw-server/src/routes/docs/rules.md index 116e62c..5a6ee34 100644 --- a/web/pw-server/src/routes/docs/rules.md +++ b/web/pw-server/src/routes/docs/rules.md @@ -65,9 +65,9 @@ Example command: } ] } +``` You can dispatch as many expeditions as you like. -``` ## Rules -- cgit v1.2.3