From 369000961ab65044c68d13134e168830e5890669 Mon Sep 17 00:00:00 2001 From: Arkadiusz Sygulski Date: Fri, 20 Feb 2026 23:38:23 +0100 Subject: [PATCH] View Transition --- src/client/GameModeSelector.ts | 50 +++++++++++++++++++++++----- src/client/components/PlayPage.ts | 2 +- src/client/styles/core/variables.css | 5 +++ src/core/configuration/DevConfig.ts | 2 +- src/server/MasterLobbyService.ts | 6 ++-- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/client/GameModeSelector.ts b/src/client/GameModeSelector.ts index 04f9e12d8..bf5e8e2cc 100644 --- a/src/client/GameModeSelector.ts +++ b/src/client/GameModeSelector.ts @@ -24,6 +24,7 @@ const CARD_BG = "bg-sky-950"; export class GameModeSelector extends LitElement { @state() private lobbies: PublicGames | null = null; private serverTimeOffset: number = 0; + private prevGameIds: string = ""; private lobbySocket = new PublicLobbySocket((lobbies) => this.handleLobbiesUpdate(lobbies), @@ -69,14 +70,45 @@ export class GameModeSelector extends LitElement { } private handleLobbiesUpdate(lobbies: PublicGames) { - this.lobbies = lobbies; - this.serverTimeOffset = lobbies.serverTime - Date.now(); - document.dispatchEvent( - new CustomEvent("public-lobbies-update", { - detail: { payload: lobbies }, - }), - ); - this.requestUpdate(); + const newIds = this.extractSortedGameIds(lobbies); + const gameListChanged = + this.prevGameIds !== "" && newIds !== this.prevGameIds; + this.prevGameIds = newIds; + + const applyUpdate = () => { + this.lobbies = lobbies; + this.serverTimeOffset = lobbies.serverTime - Date.now(); + document.dispatchEvent( + new CustomEvent("public-lobbies-update", { + detail: { payload: lobbies }, + }), + ); + this.requestUpdate(); + }; + + if ( + gameListChanged && + "startViewTransition" in document && + typeof (document as any).startViewTransition === "function" + ) { + (document as any).startViewTransition(async () => { + applyUpdate(); + await this.updateComplete; + }); + } else { + applyUpdate(); + } + } + + private extractSortedGameIds(lobbies: PublicGames): string { + const ffa = lobbies.games?.["ffa"]?.[0]; + const teams = lobbies.games?.["team"]?.[0]; + const special = lobbies.games?.["special"]?.[0]; + return [ffa, teams, special] + .filter((g): g is PublicGameInfo => !!g) + .sort((a, b) => a.startsAt - b.startsAt) + .map((g) => g.gameID) + .join(","); } private getSortedLobbies(): PublicGameInfo[] { @@ -214,6 +246,7 @@ export class GameModeSelector extends LitElement { return html`