only show playerlog to bot owner

This commit is contained in:
Ilion Beyst 2022-10-16 12:42:20 +02:00
parent 79479ba8ba
commit 03cdbbc003

View file

@ -35,46 +35,61 @@
matchLog = await apiClient.getText(`/api/matches/${matchData["id"]}/log`); matchLog = await apiClient.getText(`/api/matches/${matchData["id"]}/log`);
}); });
let selectedPlayer; $: playersWithVisibleLog = matchData["players"]
.map((player: any, index: number) => ({
$: matchPlayerSelectItems = matchData["players"].map((player: any, index: number) => ({
color: PLAYER_COLORS[index], color: PLAYER_COLORS[index],
value: index, value: index,
playerId: index + 1, // stoopid player number + 1 playerId: index + 1, // stoopid player number + 1
label: player["bot_name"], displayName: player["bot_name"] || "player",
})); matchPlayer: player,
}))
.filter((item) => canSeePlayerLog($currentUser, item.matchPlayer));
// TODO: refactor match logs so that users can no longer get match logs for other players. // TODO: refactor match logs so that users can no longer get match logs for other players.
function currentUserCanSeeStdErr(matchPlayer: object): boolean { function canSeePlayerLog(user: object | null, matchPlayer: object): boolean {
if (!matchPlayer["owner_id"]) { if (!matchPlayer["owner_id"]) {
return true; return true;
} }
console.log(matchPlayer, $currentUser); return matchPlayer["owner_id"] === user?.["user_id"];
return matchPlayer["owner_id"] === $currentUser?.["user_id"];
} }
$: showStdErr = // using the same value here causes svelte to freeze
!!selectedPlayer && currentUserCanSeeStdErr(matchData["players"][selectedPlayer["value"]]); let dropdownSelectedPlayer: any;
let selectedPlayer: any;
$: if (playersWithVisibleLog.length == 1) {
selectedPlayer = playersWithVisibleLog[0];
} else {
selectedPlayer = dropdownSelectedPlayer;
}
</script> </script>
<div class="container"> <div class="container">
<Visualizer {matchLog} {matchData} /> <Visualizer {matchLog} {matchData} />
<div class="output-pane"> <div class="output-pane">
<div class="player-select"> <div class="player-select">
{#if playersWithVisibleLog.length == 1}
<h3 class="player-log-header">
player log for
<span style:color={selectedPlayer["color"]}>{selectedPlayer.displayName}</span>
</h3>
{:else}
<Select <Select
items={matchPlayerSelectItems} items={playersWithVisibleLog}
label="displayName"
clearable={false} clearable={false}
searchable={false} searchable={false}
bind:value={selectedPlayer} bind:value={dropdownSelectedPlayer}
placeholder="Select player to see logs"
> >
<div slot="item" let:item> <div slot="item" let:item>
<span style:color={item.color}>{item.label}</span> <span style:color={item.color}>{item.displayName}</span>
</div> </div>
</Select> </Select>
{/if}
</div> </div>
<div class="player-log"> <div class="player-log">
<PlayerLog {matchLog} playerId={selectedPlayer?.playerId} {showStdErr} /> <PlayerLog {matchLog} playerId={selectedPlayer?.["playerId"]} />
</div> </div>
</div> </div>
</div> </div>
@ -90,7 +105,11 @@
} }
.player-select { .player-select {
padding: 20px; padding: 0 20px;
}
.player-log-header {
color: #eee;
} }
.player-log { .player-log {