58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
import { LitElement, html, css } from "lit";
|
|
import { gameStateManager } from "../core/GameStateManager.js";
|
|
import { GameLoop } from "../core/GameLoop.js";
|
|
|
|
import "./deployment-hud.js";
|
|
|
|
export class GameViewport extends LitElement {
|
|
static styles = css`
|
|
:host {
|
|
display: block;
|
|
width: 100%;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
}
|
|
#canvas-container {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
`;
|
|
|
|
static get properties() {
|
|
return {
|
|
squad: { type: Array },
|
|
deployedIds: { type: Array },
|
|
};
|
|
}
|
|
|
|
constructor() {
|
|
super();
|
|
this.squad = [];
|
|
this.deployedIds = [];
|
|
}
|
|
|
|
#handleUnitSelected(event) {
|
|
const unit = event.detail.unit;
|
|
const index = this.squad.indexOf(unit);
|
|
gameStateManager.gameLoop.selectDeploymentUnit(index);
|
|
}
|
|
|
|
async firstUpdated() {
|
|
const container = this.shadowRoot.getElementById("canvas-container");
|
|
const loop = new GameLoop();
|
|
loop.init(container);
|
|
gameStateManager.setGameLoop(loop);
|
|
this.squad = await gameStateManager.rosterLoaded;
|
|
}
|
|
|
|
render() {
|
|
return html`<div id="canvas-container"></div>
|
|
<deployment-hud
|
|
.squad=${this.squad}
|
|
.deployedIds=${this.deployedIds}
|
|
@unit-selected=${this.#handleUnitSelected}
|
|
></deployment-hud>`;
|
|
}
|
|
}
|
|
|
|
customElements.define("game-viewport", GameViewport);
|