import { LitElement, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { EventBus } from "../../../core/EventBus"; import { PauseGameEvent } from "../../Transport"; import { GameType } from "../../../core/game/Game"; import { GameView } from "../../../core/game/GameView"; import { Layer } from "./Layer"; import { GameUpdateType } from "../../../core/game/GameUpdates"; import { UserSettings } from "../../../core/game/UserSettings"; import { AlternateViewEvent, RefreshGraphicsEvent } from "../../InputHandler"; const button = ({ classes = "", onClick = () => {}, title = "", children, }) => html` `; @customElement("options-menu") export class OptionsMenu extends LitElement implements Layer { public game: GameView; public eventBus: EventBus; private userSettings: UserSettings = new UserSettings(); @state() private showPauseButton: boolean = true; @state() private isPaused: boolean = false; @state() private timer: number = 0; @state() private showSettings: boolean = false; private isVisible = false; private hasWinner = false; @state() private alternateView: boolean = false; private onTerrainButtonClick() { this.alternateView = !this.alternateView; this.eventBus.emit(new AlternateViewEvent(this.alternateView)); this.requestUpdate(); } private onExitButtonClick() { const isAlive = this.game.myPlayer()?.isAlive(); if (isAlive) { const isConfirmed = confirm("Are you sure you want to exit the game?"); if (!isConfirmed) return; } // redirect to the home page window.location.href = "/"; } createRenderRoot() { return this; } private onSettingsButtonClick() { this.showSettings = !this.showSettings; this.requestUpdate(); } private onPauseButtonClick() { this.isPaused = !this.isPaused; this.eventBus.emit(new PauseGameEvent(this.isPaused)); } private onToggleEmojisButtonClick() { this.userSettings.toggleEmojis(); this.requestUpdate(); } private onToggleDarkModeButtonClick() { this.userSettings.toggleDarkMode(); this.requestUpdate(); this.eventBus.emit(new RefreshGraphicsEvent()); } init() { console.log("init called from OptionsMenu"); this.showPauseButton = this.game.config().gameConfig().gameType == GameType.Singleplayer; this.isVisible = true; this.requestUpdate(); } tick() { this.hasWinner = this.hasWinner || this.game.updatesSinceLastTick()[GameUpdateType.Win].length > 0; if (this.game.inSpawnPhase()) { this.timer = 0; } else if (!this.hasWinner && this.game.ticks() % 10 == 0) { this.timer++; } this.isVisible = true; this.requestUpdate(); } render() { if (!this.isVisible) { return html``; } return html`