import { LitElement, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import { EventBus } from "../../../core/EventBus"; import { GameType } from "../../../core/game/Game"; import { GameUpdateType } from "../../../core/game/GameUpdates"; import { GameView } from "../../../core/game/GameView"; import { Layer } from "./Layer"; import { PauseGameEvent } from "../../Transport"; import { ShowReplayPanelEvent } from "./ReplayPanel"; import { ShowSettingsModalEvent } from "./SettingsModal"; import exitIcon from "../../../../resources/images/ExitIconWhite.svg"; import pauseIcon from "../../../../resources/images/PauseIconWhite.svg"; import playIcon from "../../../../resources/images/PlayIconWhite.svg"; import replayRegularIcon from "../../../../resources/images/ReplayRegularIconWhite.svg"; import replaySolidIcon from "../../../../resources/images/ReplaySolidIconWhite.svg"; import settingsIcon from "../../../../resources/images/SettingIconWhite.svg"; import { translateText } from "../../Utils"; @customElement("game-right-sidebar") export class GameRightSidebar extends LitElement implements Layer { public game: GameView; public eventBus: EventBus; @state() private _isSinglePlayer = false; @state() private _isReplayVisible = false; @state() private _isVisible = true; @state() private isPaused = false; @state() private timer = 0; private hasWinner = false; createRenderRoot() { return this; } init() { this._isSinglePlayer = this.game?.config()?.gameConfig()?.gameType === GameType.Singleplayer || this.game.config().isReplay(); this._isVisible = true; this.game.inSpawnPhase(); this.requestUpdate(); } tick() { // Timer logic const updates = this.game.updatesSinceLastTick(); if (updates) { this.hasWinner = this.hasWinner || updates[GameUpdateType.Win].length > 0; } if (this.game.inSpawnPhase()) { this.timer = 0; } else if (!this.hasWinner && this.game.ticks() % 10 === 0) { this.timer++; } } private secondsToHms = (d: number): string => { const h = Math.floor(d / 3600); const m = Math.floor((d % 3600) / 60); const s = Math.floor((d % 3600) % 60); let time = d === 0 ? "-" : `${s}s`; if (m > 0) time = `${m}m` + time; if (h > 0) time = `${h}h` + time; return time; }; private toggleReplayPanel(): void { this._isReplayVisible = !this._isReplayVisible; this.eventBus.emit( new ShowReplayPanelEvent(this._isReplayVisible, this._isSinglePlayer), ); } private onPauseButtonClick() { this.isPaused = !this.isPaused; this.eventBus.emit(new PauseGameEvent(this.isPaused)); } private onExitButtonClick() { const isAlive = this.game.myPlayer()?.isAlive(); if (isAlive) { const isConfirmed = confirm( translateText("help_modal.exit_confirmation"), ); if (!isConfirmed) return; } // redirect to the home page window.location.href = "/"; } private onSettingsButtonClick() { this.eventBus.emit( new ShowSettingsModalEvent(true, this._isSinglePlayer, this.isPaused), ); } render() { if (this.game === undefined) return html``; return html` `; } maybeRenderReplayButtons() { if (this._isSinglePlayer || this.game?.config()?.isReplay()) { return html`