diff --git a/src/client/graphics/layers/ControlPanel.ts b/src/client/graphics/layers/ControlPanel.ts index a811c7579..9d769f9b5 100644 --- a/src/client/graphics/layers/ControlPanel.ts +++ b/src/client/graphics/layers/ControlPanel.ts @@ -1,168 +1,197 @@ -import { LitElement, html } from 'lit'; -import { customElement, property, state } from 'lit/decorators.js'; -import { Layer } from './Layer'; -import { Game } from '../../../core/game/Game'; -import { ClientID } from '../../../core/Schemas'; -import { renderNumber, renderTroops } from '../../Utils'; -import { EventBus } from '../../../core/EventBus'; -import { UIState } from '../UIState'; -import { SendSetTargetTroopRatioEvent } from '../../Transport'; -import { GameView } from '../../../core/game/GameView'; +import { LitElement, html } from "lit"; +import { customElement, property, state } from "lit/decorators.js"; +import { Layer } from "./Layer"; +import { Game } from "../../../core/game/Game"; +import { ClientID } from "../../../core/Schemas"; +import { renderNumber, renderTroops } from "../../Utils"; +import { EventBus } from "../../../core/EventBus"; +import { UIState } from "../UIState"; +import { SendSetTargetTroopRatioEvent } from "../../Transport"; +import { GameView } from "../../../core/game/GameView"; -@customElement('control-panel') +@customElement("control-panel") export class ControlPanel extends LitElement implements Layer { - public game: GameView; - public clientID: ClientID; - public eventBus: EventBus; - public uiState: UIState; + public game: GameView; + public clientID: ClientID; + public eventBus: EventBus; + public uiState: UIState; - @state() - private attackRatio: number = .2; + @state() + private attackRatio: number = 0.2; - @state() - private targetTroopRatio = 1; + @state() + private targetTroopRatio = 1; - @state() - private currentTroopRatio = 1; + @state() + private currentTroopRatio = 1; - @state() - private _population: number; + @state() + private _population: number; - @state() - private _maxPopulation: number; + @state() + private _maxPopulation: number; - @state() - private popRate: number; + @state() + private popRate: number; - @state() - private _troops: number; + @state() + private _troops: number; - @state() - private _workers: number; + @state() + private _workers: number; - @state() - private _isVisible = false; + @state() + private _isVisible = false; - @state() - private _manpower: number = 0; + @state() + private _manpower: number = 0; - @state() - private _gold: number; + @state() + private _gold: number; - @state() - private _goldPerSecond: number; + @state() + private _goldPerSecond: number; - init() { - this.attackRatio = .20; - this.uiState.attackRatio = this.attackRatio; - this.currentTroopRatio = this.targetTroopRatio; + init() { + this.attackRatio = 0.2; + this.uiState.attackRatio = this.attackRatio; + this.currentTroopRatio = this.targetTroopRatio; + } + + tick() { + if (!this._isVisible && !this.game.inSpawnPhase()) { + this.setVisibile(true); } - tick() { - if (!this._isVisible && !this.game.inSpawnPhase()) { - this.setVisibile(true); - } - - const player = this.game.playerByClientID(this.clientID); - if (player == null || !player.isAlive()) { - this.setVisibile(false); - return; - } - - this._population = player.population(); - this._maxPopulation = this.game.config().maxPopulation(player); - this._gold = player.gold(); - this._troops = player.troops(); - this._workers = player.workers(); - this.popRate = this.game.config().populationIncreaseRate(player) * 10; - this._goldPerSecond = this.game.config().goldAdditionRate(player) * 10; - - this.currentTroopRatio = player.troops() / player.population(); + const player = this.game.playerByClientID(this.clientID); + if (player == null || !player.isAlive()) { + this.setVisibile(false); + return; } - onAttackRatioChange(newRatio: number) { - this.uiState.attackRatio = newRatio; - } + this._population = player.population(); + this._maxPopulation = this.game.config().maxPopulation(player); + this._gold = player.gold(); + this._troops = player.troops(); + this._workers = player.workers(); + this.popRate = this.game.config().populationIncreaseRate(player) * 10; + this._goldPerSecond = this.game.config().goldAdditionRate(player) * 10; - renderLayer(context: CanvasRenderingContext2D) { - // Render any necessary canvas elements - } + this.currentTroopRatio = player.troops() / player.population(); + } - shouldTransform(): boolean { - return false; - } + onAttackRatioChange(newRatio: number) { + this.uiState.attackRatio = newRatio; + } - setVisibile(visible: boolean) { - this._isVisible = visible; - this.requestUpdate(); - } + renderLayer(context: CanvasRenderingContext2D) { + // Render any necessary canvas elements + } - targetTroops(): number { - return this._manpower * this.targetTroopRatio; - } + shouldTransform(): boolean { + return false; + } - onTroopChange(newRatio: number) { - this.eventBus.emit(new SendSetTargetTroopRatioEvent(newRatio)); - } + setVisibile(visible: boolean) { + this._isVisible = visible; + this.requestUpdate(); + } - delta(): number { - const d = this._population - this.targetTroops(); - return d; - } + targetTroops(): number { + return this._manpower * this.targetTroopRatio; + } - render() { - return html` -