import { LitElement, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { GameView } from "../../../core/game/GameView"; import { Layer } from "./Layer"; import { renderNumber, renderTroops } from "../../Utils"; @customElement("top-bar") export class TopBar extends LitElement implements Layer { public game: GameView; private isVisible = false; private _population = 0; private _lastPopulationIncreaseRate = 0; private _popRateIsIncreasing = false; createRenderRoot() { return this; } init() { this.isVisible = true; this.requestUpdate(); } tick() { if (this.game?.myPlayer() !== null) { const popIncreaseRate = this.game.myPlayer().population() - this._population; if (this.game.ticks() % 5 == 0) { this._popRateIsIncreasing = popIncreaseRate >= this._lastPopulationIncreaseRate; this._lastPopulationIncreaseRate = popIncreaseRate; } } this.requestUpdate(); } render() { if (!this.isVisible) { return html``; } const myPlayer = this.game?.myPlayer(); if (!myPlayer?.isAlive() || this.game?.inSpawnPhase()) { return html``; } const popRate = this.game.config().populationIncreaseRate(myPlayer) * 10; const maxPop = this.game.config().maxPopulation(myPlayer); const goldPerSecond = this.game.config().goldAdditionRate(myPlayer) * 10; return html`
Pop: ${renderTroops(myPlayer.population())} / ${renderTroops(maxPop)} (+${renderTroops(popRate)})
Gold: ${renderNumber(myPlayer.gold())} (+${renderNumber(goldPerSecond)})
`; } }