diff --git a/src/client/graphics/GameRenderer.ts b/src/client/graphics/GameRenderer.ts index 9b2240732..58b298c13 100644 --- a/src/client/graphics/GameRenderer.ts +++ b/src/client/graphics/GameRenderer.ts @@ -20,6 +20,7 @@ import { NameLayer } from "./layers/NameLayer"; import { OptionsMenu } from "./layers/OptionsMenu"; import { PlayerInfoOverlay } from "./layers/PlayerInfoOverlay"; import { PlayerPanel } from "./layers/PlayerPanel"; +import { PlayerTeamLabel } from "./layers/PlayerTeamLabel"; import { RadialMenu } from "./layers/RadialMenu"; import { SpawnTimer } from "./layers/SpawnTimer"; import { StructureLayer } from "./layers/StructureLayer"; @@ -162,6 +163,14 @@ export function createRenderer( } multiTabModal.game = game; + const playerTeamLabel = document.querySelector( + "player-team-label", + ) as PlayerTeamLabel; + if (!(playerTeamLabel instanceof PlayerTeamLabel)) { + console.error("player team label not found"); + } + playerTeamLabel.game = game; + const layers: Layer[] = [ new TerrainLayer(game, transformHandler), new TerritoryLayer(game, eventBus), @@ -193,6 +202,7 @@ export function createRenderer( teamStats, topBar, playerPanel, + playerTeamLabel, multiTabModal, ]; diff --git a/src/client/graphics/layers/OptionsMenu.ts b/src/client/graphics/layers/OptionsMenu.ts index 7e85e38f4..56e71605a 100644 --- a/src/client/graphics/layers/OptionsMenu.ts +++ b/src/client/graphics/layers/OptionsMenu.ts @@ -167,7 +167,7 @@ export class OptionsMenu extends LitElement implements Layer { children: this.isPaused ? "▶️" : "⏸", })}
diff --git a/src/client/graphics/layers/PlayerTeamLabel.ts b/src/client/graphics/layers/PlayerTeamLabel.ts new file mode 100644 index 000000000..444fd8c7d --- /dev/null +++ b/src/client/graphics/layers/PlayerTeamLabel.ts @@ -0,0 +1,74 @@ +import { Colord } from "colord"; +import { LitElement, html } from "lit"; +import { customElement, state } from "lit/decorators.js"; +import { GameMode } from "../../../core/game/Game"; +import { GameView } from "../../../core/game/GameView"; +import { Layer } from "./Layer"; + +@customElement("player-team-label") +export class PlayerTeamLabel extends LitElement implements Layer { + public game: GameView; + + @state() + private isTeamsGameMode: boolean = false; + + private isVisible = false; + + private playerTeam: string | null = null; + + private playerColor: Colord = new Colord("#FFFFFF"); + + createRenderRoot() { + return this; + } + + init() { + this.isTeamsGameMode = + this.game.config().gameConfig().gameMode === GameMode.Team; + + if (this.isTeamsGameMode) { + this.isVisible = true; + this.requestUpdate(); + } + } + + tick() { + if ( + this.isTeamsGameMode && + !this.playerTeam && + this.game.myPlayer()?.team() + ) { + this.playerTeam = this.game.myPlayer()!.team(); + if (this.playerTeam) { + this.playerColor = this.game + .config() + .theme() + .teamColor(this.playerTeam); + this.requestUpdate(); + } + } + + if (!this.game.inSpawnPhase() && this.isVisible) { + this.isVisible = false; + this.requestUpdate(); + } + } + + render() { + if (!this.isVisible) { + return html``; + } + + return html` +
e.preventDefault()} + > + Your team: + ${this.playerTeam} ⦿ +
+ `; + } +} diff --git a/src/client/index.html b/src/client/index.html index 957c1f08d..6869f4f62 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -338,6 +338,9 @@
+
+ +