import { Colord } from "colord"; import { html, LitElement } from "lit"; import { customElement, state } from "lit/decorators.js"; import { EventBus } from "../../../core/EventBus"; import { GameMode } from "../../../core/game/Game"; import { GameView } from "../../../core/game/GameView"; import { translateText } from "../../Utils"; import { ImmunityBarVisibleEvent } from "./ImmunityTimer"; import { Layer } from "./Layer"; import { SpawnBarVisibleEvent } from "./SpawnTimer"; import leaderboardRegularIcon from "/images/LeaderboardIconRegularWhite.svg?url"; import leaderboardSolidIcon from "/images/LeaderboardIconSolidWhite.svg?url"; import teamRegularIcon from "/images/TeamIconRegularWhite.svg?url"; import teamSolidIcon from "/images/TeamIconSolidWhite.svg?url"; @customElement("game-left-sidebar") export class GameLeftSidebar extends LitElement implements Layer { @state() private isLeaderboardShow = false; @state() private isTeamLeaderboardShow = false; @state() private isVisible = false; @state() private isPlayerTeamLabelVisible = false; @state() private playerTeam: string | null = null; @state() private spawnBarVisible = false; @state() private immunityBarVisible = false; private playerColor: Colord = new Colord("#FFFFFF"); public game: GameView; public eventBus: EventBus; private _shownOnInit = false; createRenderRoot() { return this; } init() { this.isVisible = true; this.eventBus.on(SpawnBarVisibleEvent, (e) => { this.spawnBarVisible = e.visible; }); this.eventBus.on(ImmunityBarVisibleEvent, (e) => { this.immunityBarVisible = e.visible; }); if (this.isTeamGame) { this.isPlayerTeamLabelVisible = true; } // Make it visible by default on large screens if (window.innerWidth >= 1024) { // lg breakpoint this._shownOnInit = true; } this.requestUpdate(); } tick() { if (!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._shownOnInit && !this.game.inSpawnPhase()) { this._shownOnInit = false; this.isLeaderboardShow = true; this.requestUpdate(); } if (!this.game.inSpawnPhase() && this.isPlayerTeamLabelVisible) { this.isPlayerTeamLabelVisible = false; this.requestUpdate(); } } private get barOffset(): number { return (this.spawnBarVisible ? 7 : 0) + (this.immunityBarVisible ? 7 : 0); } private toggleLeaderboard(): void { this.isLeaderboardShow = !this.isLeaderboardShow; } private toggleTeamLeaderboard(): void { this.isTeamLeaderboardShow = !this.isTeamLeaderboardShow; } private get isTeamGame(): boolean { return this.game?.config().gameConfig().gameMode === GameMode.Team; } private getTranslatedPlayerTeamLabel(): string { if (!this.playerTeam) return ""; const translationKey = `team_colors.${this.playerTeam.toLowerCase()}`; const translated = translateText(translationKey); return translated === translationKey ? this.playerTeam : translated; } render() { return html` `; } }