diff --git a/src/client/graphics/GameRenderer.ts b/src/client/graphics/GameRenderer.ts index 0af4e9113..ffe5d2ccd 100644 --- a/src/client/graphics/GameRenderer.ts +++ b/src/client/graphics/GameRenderer.ts @@ -15,7 +15,6 @@ import { EventsDisplay } from "./layers/EventsDisplay"; import { FxLayer } from "./layers/FxLayer"; import { GameLeftSidebar } from "./layers/GameLeftSidebar"; import { GameRightSidebar } from "./layers/GameRightSidebar"; -import { GameTopBar } from "./layers/GameTopBar"; import { GutterAdModal } from "./layers/GutterAdModal"; import { HeadsUpMessage } from "./layers/HeadsUpMessage"; import { Layer } from "./layers/Layer"; @@ -162,13 +161,6 @@ export function createRenderer( settingsModal.userSettings = userSettings; settingsModal.eventBus = eventBus; - const gameTopBar = document.querySelector("game-top-bar") as GameTopBar; - if (!(gameTopBar instanceof GameTopBar)) { - console.error("top bar not found"); - } - gameTopBar.game = game; - gameTopBar.eventBus = eventBus; - const unitDisplay = document.querySelector("unit-display") as UnitDisplay; if (!(unitDisplay instanceof UnitDisplay)) { console.error("unit display not found"); @@ -255,7 +247,6 @@ export function createRenderer( new SpawnTimer(game, transformHandler), leaderboard, gameLeftSidebar, - gameTopBar, unitDisplay, gameRightSidebar, controlPanel, diff --git a/src/client/graphics/layers/ControlPanel.ts b/src/client/graphics/layers/ControlPanel.ts index 8929ede8e..a9d83dc1e 100644 --- a/src/client/graphics/layers/ControlPanel.ts +++ b/src/client/graphics/layers/ControlPanel.ts @@ -2,16 +2,19 @@ import { LitElement, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import { translateText } from "../../../client/Utils"; import { EventBus } from "../../../core/EventBus"; +import { Gold } from "../../../core/game/Game"; import { GameView } from "../../../core/game/GameView"; +import { ClientID } from "../../../core/Schemas"; import { AttackRatioEvent } from "../../InputHandler"; import { SendSetTargetTroopRatioEvent } from "../../Transport"; -import { renderTroops } from "../../Utils"; +import { renderNumber, renderTroops } from "../../Utils"; import { UIState } from "../UIState"; import { Layer } from "./Layer"; @customElement("control-panel") export class ControlPanel extends LitElement implements Layer { public game: GameView; + public clientID: ClientID; public eventBus: EventBus; public uiState: UIState; @@ -27,13 +30,34 @@ export class ControlPanel extends LitElement implements Layer { @state() private _population: number; + @state() + private _maxPopulation: number; + + @state() + private popRate: number; + + @state() + private _troops: number; + + @state() + private _workers: number; + @state() private _isVisible = false; @state() private _manpower: number = 0; + @state() + private _gold: Gold; + + @state() + private _goldPerSecond: Gold; + + private _popRateIsIncreasing: boolean = true; + private _lastPopulationIncreaseRate: number; + private init_: boolean = false; init() { @@ -90,17 +114,31 @@ export class ControlPanel extends LitElement implements Layer { return; } - const popIncreaseRate = player.population() - this._population; if (this.game.ticks() % 5 === 0) { - this._lastPopulationIncreaseRate = popIncreaseRate; + this.updatePopulationIncrease(); } 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) * 10n; this.currentTroopRatio = player.troops() / player.population(); this.requestUpdate(); } + private updatePopulationIncrease() { + const player = this.game?.myPlayer(); + if (player === null) return; + const popIncreaseRate = this.game.config().populationIncreaseRate(player); + this._popRateIsIncreasing = + popIncreaseRate >= this._lastPopulationIncreaseRate; + this._lastPopulationIncreaseRate = popIncreaseRate; + } + onAttackRatioChange(newRatio: number) { this.uiState.attackRatio = newRatio; } @@ -174,21 +212,45 @@ export class ControlPanel extends LitElement implements Layer {
e.preventDefault()} > + +
- +
0; - } - this.requestUpdate(); - } - - private updatePopulationIncrease() { - const player = this.game?.myPlayer(); - if (player === null) return; - const popIncreaseRate = this.game.config().populationIncreaseRate(player); - this._popRateIsIncreasing = - popIncreaseRate >= this._lastPopulationIncreaseRate; - this._lastPopulationIncreaseRate = popIncreaseRate; - } - - render() { - const myPlayer = this.game?.myPlayer(); - if (!this.game || !myPlayer || this.game.inSpawnPhase()) { - return null; - } - - const isAlt = this.game.config().isReplay(); - if (isAlt) { - return html` -
- `; - } - const popRate = myPlayer - ? this.game.config().populationIncreaseRate(myPlayer) * 10 - : 0; - const maxPop = myPlayer ? this.game.config().maxPopulation(myPlayer) : 0; - const goldPerSecond = myPlayer - ? this.game.config().goldAdditionRate(myPlayer) * 10n - : 0n; - - return html` -
-
- ${myPlayer?.isAlive() && !this.game.inSpawnPhase() - ? html` -
-
-
-
- gold - +${renderNumber(goldPerSecond)} -
-
- ${renderNumber(myPlayer.gold())} -
-
-
-
- population - - +${renderTroops(popRate)} - -
-
- ${renderTroops(myPlayer.population())} / - ${renderTroops(maxPop)} -
-
-
-
-
- troops - ${renderTroops(this._troops)} -
-
- gold - ${renderTroops(this._workers)} -
-
-
-
-
- ` - : html`
`} -
-
- `; - } -}