diff --git a/src/frontend/src/GameState.ts b/src/frontend/src/GameState.ts index 646901f..fe8e2f2 100644 --- a/src/frontend/src/GameState.ts +++ b/src/frontend/src/GameState.ts @@ -5,7 +5,7 @@ import { log } from "./utils/debugUtils"; export class GameState { _errors: string[] = []; - constructor(public readonly gameStateRaw: GameStateRawReadonly, private readonly client: Client) { + constructor(public readonly gameStateRaw: GameStateRawReadonly, readonly client: Client) { this._validate(); } diff --git a/src/frontend/src/Scenes/LobbyScene.ts b/src/frontend/src/Scenes/LobbyScene.ts index 2fe18ca..8197b4a 100644 --- a/src/frontend/src/Scenes/LobbyScene.ts +++ b/src/frontend/src/Scenes/LobbyScene.ts @@ -235,8 +235,8 @@ export class LobbyScene extends GameStateScene { } public updateFromGameState(gameState: GameState): void { - this._playerList.clients = gameState.gameStateRaw.players; - this._spectatorsList.clients = gameState.gameStateRaw.spectators; + this._playerList.updateFromGameState(gameState.players, gameState.client); + this._spectatorsList.updateFromGameState(gameState.spectators, gameState.client); this._updatePositions(); this._updateVisibility(gameState); } diff --git a/src/frontend/src/ScreenElements/ClientListScreenElement.ts b/src/frontend/src/ScreenElements/ClientListScreenElement.ts index 67a6fc4..b53aa88 100644 --- a/src/frontend/src/ScreenElements/ClientListScreenElement.ts +++ b/src/frontend/src/ScreenElements/ClientListScreenElement.ts @@ -3,10 +3,14 @@ import * as ex from 'excalibur'; import { spacingS } from '../utils/formattingUtils'; import { headingFont, paragraphFont } from '../utils/fontUtil'; import { Text } from './Text'; -import { Player, Spectator } from '../GameStateRaw'; +import { Client, Player, Spectator } from '../GameStateRaw'; + +const clientColor = ex.Color.fromHex("40E0D0") export class ClientListScreenElement extends ex.ScreenElement { protected _clients: Player[] | Spectator[] = []; + protected _client: Client | null = null; + protected heading: Text = null!; protected entities: ex.Actor[] = []; @@ -29,8 +33,9 @@ export class ClientListScreenElement extends ex.ScreenElement { return this.computeChildrenHeight(this._clients.length); } - set clients(labels: Player[] | Spectator[]) { - this._clients = labels; + public updateFromGameState(clients: Player[] | Spectator[], client: Client): void { + this._clients = clients + this._client = client; if (this.isInitialized) { this.updateList(); } @@ -41,13 +46,10 @@ export class ClientListScreenElement extends ex.ScreenElement { let y = headingFont.size + spacingS; - for(const client of this._clients) { - const label = new Text({ - text: client.player.name, - font: paragraphFont, - }) - label.pos.setTo(0, y); - label.anchor.setTo(0.5, 0); + for(const currentClient of this._clients) { + const isClient = currentClient.player.id === this._client?.id; + const label = this.createLabel(currentClient, y, isClient); + y += label.font.size + spacingS; this.addChild(label); this.entities.push(label); @@ -66,6 +68,20 @@ export class ClientListScreenElement extends ex.ScreenElement { } + protected createLabel(client: Player | Spectator, y: number, isClient: boolean): Text { + const color = isClient ? clientColor : undefined; + const { name } = client.player; + const label = new Text({ + text: name, + font: paragraphFont, + color, + }) + label.pos.setTo(0, y); + label.anchor.setTo(0.5, 0); + + return label; + } + protected computeChildrenHeight(numLabels: number): number { return headingFont.size + spacingS + Math.max(1, numLabels) * (spacingS + paragraphFont.size); } diff --git a/src/frontend/src/ScreenElements/PlayerListScreenElement.ts b/src/frontend/src/ScreenElements/PlayerListScreenElement.ts index a46327f..69e6ef0 100644 --- a/src/frontend/src/ScreenElements/PlayerListScreenElement.ts +++ b/src/frontend/src/ScreenElements/PlayerListScreenElement.ts @@ -1,11 +1,12 @@ import * as ex from 'excalibur'; import { spacingS } from '../utils/formattingUtils'; -import { disabledFont, paragraphFont } from '../utils/fontUtil'; +import { disabledFont } from '../utils/fontUtil'; import { Text } from './Text'; import { Checkbox } from './Checkbox'; import { Player } from '../GameStateRaw'; import { ClientListScreenElement } from './ClientListScreenElement'; + export class PlayerListScreenElement extends ClientListScreenElement { protected override _clients: Player[] = []; constructor(headingText: string, private _maxPlayers: number) { @@ -19,22 +20,20 @@ export class PlayerListScreenElement extends ClientListScreenElement { const clients = this._clients.slice(0, this._maxPlayers); - for(const client of clients) { - const { name } = client.player; - const label = new Text({ - text: name, - font: paragraphFont, - }); - label.pos.setTo(0, y); - label.anchor.setTo(0.5, 0); - this.addChild(label); + for(const currentClient of clients) { + const { name, id } = currentClient.player; + const isClient = id === this._client?.id; + const label = this.createLabel(currentClient, y, isClient); - const ready = new Checkbox({ checked: client.ready}); + this.addChild(label); + this.entities.push(label); + + + const ready = new Checkbox({ checked: currentClient.ready}); const textWidth = label.font.measureTextWithoutCache(name ?? "").width ready.pos = ex.vec( textWidth / 2 + spacingS, y); this.addChild(ready); - this.entities.push(label); this.entities.push(ready); y += label.font.size + spacingS;