Skip to content

Commit eef0ce9

Browse files
committed
⏪ Fix prettier mishap
1 parent e8f1576 commit eef0ce9

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

apps/web/src/components/Game/GameSidebar.svelte

+36-11
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
11
<script lang="ts">
22
import { browser } from "$app/env";
3+
import { keyBy } from "lodash";
4+
import { elapsedSeconds } from "@bgs/utils";
5+
import { timerTime, oneLineMarked, handleError, confirm, duration, shortDuration } from "@/utils";
6+
import type { PlayerInfo } from "@bgs/types";
7+
import Portal from "@/modules/portal";
8+
import clockHistory from "@iconify/icons-bi/clock-history.js";
9+
import { Button, Icon, Badge } from "@/modules/cdk";
10+
import { getContext, onDestroy } from "svelte";
11+
import { GameLog, ReplayControls, GameNotes, GamePreferences, GameSettings } from "./GameSidebar";
12+
import type { GameContext } from "@/routes/game/[gameId].svelte";
13+
import PlayerGameAvatar from "./PlayerGameAvatar.svelte";
14+
import { useRest } from "@/composition/useRest";
315
import { useAccount } from "@/composition/useAccount";
4-
import { useActiveGames } from "@/composition/useActiveGames";
516
import { useCurrentGame } from "@/composition/useCurrentGame";
17+
import { useActiveGames } from "@/composition/useActiveGames";
618
import { useDeveloperSettings } from "@/composition/useDeveloperSettings";
7-
import { useRest } from "@/composition/useRest";
8-
import type { GameContext } from "@/pages/Game.svelte";
9-
import { confirm, handleError } from "@/utils";
10-
import type { PlayerInfo } from "@bgs/types";
11-
import { elapsedSeconds } from "@bgs/utils";
12-
import { keyBy } from "lodash";
13-
import { getContext, onDestroy } from "svelte";
19+
1420
const { game, players, gameInfo }: GameContext = getContext("game");
1521
const { post } = useRest();
22+
1623
const { account } = useAccount();
1724
const { playerStatus } = useCurrentGame();
1825
const { addActiveGame, removeActiveGame } = useActiveGames();
1926
const { devGameSettings } = useDeveloperSettings();
27+
2028
let secondsCounter = 0;
29+
2130
const interval = setInterval(() => {
2231
if (browser && !document.hidden) {
2332
secondsCounter += 1;
2433
}
2534
}, 1000);
2635
onDestroy(() => clearInterval(interval));
36+
2737
let requestedDrop: Record<string, boolean> = {};
38+
2839
$: userId = $account?._id;
2940
$: playerUser = $game?.players.find((pl) => pl._id === userId);
3041
$: gameId = $game?._id;
42+
3143
function status(playerId: string) {
3244
return $playerStatus?.find((pl) => pl._id === playerId)?.status ?? "offline";
3345
}
46+
3447
function playerElo(playerId: string) {
3548
return $players.find((pl) => pl._id === playerId)?.elo ?? 0;
3649
}
50+
3751
$: alwaysActive = $game?.options.timing.timer?.start === $game?.options.timing.timer?.end;
52+
3853
$: currentPlayersById = keyBy($game?.currentPlayers ?? [], "_id");
54+
3955
function isCurrentPlayer(id: string) {
4056
return $game?.status !== "ended" && !!currentPlayersById[id];
4157
}
58+
4259
const onGameChanged = () => {
4360
if (userId) {
4461
if (isCurrentPlayer(userId)) {
@@ -48,36 +65,44 @@
4865
}
4966
}
5067
};
68+
5169
$: onGameChanged(), [userId, $game];
70+
5271
let remainingTimes: Record<string, number> = {};
72+
5373
function updateRemainingTimes() {
5474
const ret: Record<string, number> = {};
5575
for (const player of $game.players) {
5676
ret[player._id] = remainingTime(player);
5777
}
78+
5879
remainingTimes = ret;
5980
}
81+
6082
$: updateRemainingTimes(), [secondsCounter];
83+
6184
function remainingTime(player: PlayerInfo) {
6285
const currentPlayer = currentPlayersById[player._id];
6386
if (currentPlayer) {
6487
const spent = elapsedSeconds(new Date(currentPlayer.timerStart as any), $game.options.timing.timer);
65-
of $game.players) {
66-
ret[
88+
// Trick to update every second
6789
return Math.max(player.remainingTime - spent, 0) + (secondsCounter % 1);
6890
}
6991
return Math.max(player.remainingTime, 0);
7092
}
93+
7194
async function voteCancel() {
7295
if (
7396
await confirm("This vote cannot be taken back. If all active players vote to cancel, the game will be cancelled.")
7497
) {
7598
await post(`/game/${gameId}/cancel`).catch(handleError);
7699
}
77100
}
101+
78102
async function quit() {
79103
await post(`/game/${gameId}/quit`).catch(handleError);
80104
}
105+
81106
async function requestDrop(playerId: string) {
82107
await post(`/game/${gameId}/drop/${playerId}`).then(
83108
() => (requestedDrop = { ...requestedDrop, [playerId]: true }),
@@ -86,7 +111,7 @@
86111
}
87112
</script>
88113

89-
<div id="floating-controls" />
114+
<div id="floating-controls"></div>
90115
<Portal target="#sidebar">
91116
<h3 class="mt-75">Players</h3>
92117
{#each $game.players as player}

0 commit comments

Comments
 (0)