show dispatches and timeouts in outputpane
This commit is contained in:
parent
3be0cfa0ea
commit
3138eca6d0
2 changed files with 90 additions and 31 deletions
|
@ -6,6 +6,19 @@
|
|||
|
||||
let showRawStderr = false;
|
||||
|
||||
const PLURAL_MAP = {
|
||||
dispatch: "dispatches",
|
||||
ship: "ships",
|
||||
};
|
||||
|
||||
function pluralize(num: number, word: string): string {
|
||||
if (num == 1) {
|
||||
return `1 ${word}`;
|
||||
} else {
|
||||
return `${num} ${PLURAL_MAP[word]}`;
|
||||
}
|
||||
}
|
||||
|
||||
$: if (matchLog) {
|
||||
playerLog = parsePlayerLog(1, matchLog);
|
||||
} else {
|
||||
|
@ -25,11 +38,28 @@
|
|||
<div class="turn">
|
||||
<div class="turn-header">
|
||||
<span class="turn-header-text">Turn {i}</span>
|
||||
{#if logTurn.action?.type === "bad_command"}
|
||||
{#if logTurn.action?.type === "dispatches"}
|
||||
{pluralize(logTurn.action.dispatches.length, "dispatch")}
|
||||
{:else if logTurn.action?.type === "timeout"}
|
||||
<span class="turn-error">timeout</span>
|
||||
{:else if logTurn.action?.type === "bad_command"}
|
||||
<span class="turn-error">invalid command</span>
|
||||
{/if}
|
||||
</div>
|
||||
{#if logTurn.action?.type === "bad_command"}
|
||||
{#if logTurn.action?.type === "dispatches"}
|
||||
<div class="dispatches-container">
|
||||
{#each logTurn.action.dispatches as dispatch}
|
||||
<div class="dispatch">
|
||||
<div class="dispatch-text">
|
||||
{pluralize(dispatch.ship_count, "ship")} from {dispatch.origin} to {dispatch.destination}
|
||||
</div>
|
||||
{#if dispatch.error}
|
||||
<span class="dispatch-error">{dispatch.error}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else if logTurn.action?.type === "bad_command"}
|
||||
<div class="bad-command-container">
|
||||
<div class="bad-command-text">{logTurn.action.command}</div>
|
||||
<div class="bad-command-error">Parse error: {logTurn.action.error}</div>
|
||||
|
@ -81,6 +111,15 @@
|
|||
color: red;
|
||||
}
|
||||
|
||||
.dispatch {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.dispatch-error {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.bad-command-container {
|
||||
border-left: 1px solid red;
|
||||
margin-left: 4px;
|
||||
|
|
|
@ -5,7 +5,11 @@ export type PlayerLogTurn = {
|
|||
stderr: string[];
|
||||
};
|
||||
|
||||
type PlayerAction = BadCommand;
|
||||
type PlayerAction = Timeout | BadCommand | Dispatches;
|
||||
|
||||
type Timeout = {
|
||||
type: "timeout";
|
||||
};
|
||||
|
||||
type BadCommand = {
|
||||
type: "bad_command";
|
||||
|
@ -13,6 +17,18 @@ type BadCommand = {
|
|||
error: string;
|
||||
};
|
||||
|
||||
type Dispatches = {
|
||||
type: "dispatches";
|
||||
dispatches: Dispatch[];
|
||||
};
|
||||
|
||||
type Dispatch = {
|
||||
origin: string;
|
||||
destination: string;
|
||||
ship_count: number;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
function createEmptyLogTurn(): PlayerLogTurn {
|
||||
return {
|
||||
stderr: [],
|
||||
|
@ -43,9 +59,13 @@ export function parsePlayerLog(playerId: number, logText: string): PlayerLog {
|
|||
case "stderr": {
|
||||
let msg = logMessage["message"];
|
||||
turn.stderr.push(msg);
|
||||
break;
|
||||
}
|
||||
case "bad_command": {
|
||||
case "timeout":
|
||||
case "bad_command":
|
||||
case "dispatches": {
|
||||
turn.action = logMessage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue