import { LitElement, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import { EventBus } from "../../../core/EventBus"; import { AllPlayers } from "../../../core/game/Game"; import { GameView, PlayerView } from "../../../core/game/GameView"; import { TerraNulliusImpl } from "../../../core/game/TerraNulliusImpl"; import { emojiTable, flattenedEmojiTable } from "../../../core/Util"; import { CloseViewEvent, ShowEmojiMenuEvent } from "../../InputHandler"; import { SendEmojiIntentEvent } from "../../Transport"; import { TransformHandler } from "../TransformHandler"; @customElement("emoji-table") export class EmojiTable extends LitElement { @state() public isVisible = false; public transformHandler: TransformHandler; public game: GameView; initEventBus(eventBus: EventBus) { eventBus.on(ShowEmojiMenuEvent, (e) => { this.isVisible = true; const cell = this.transformHandler.screenToWorldCoordinates(e.x, e.y); if (!this.game.isValidCoord(cell.x, cell.y)) { return; } const tile = this.game.ref(cell.x, cell.y); if (!this.game.hasOwner(tile)) { return; } const targetPlayer = this.game.owner(tile); // maybe redundant due to owner check but better safe than sorry if (targetPlayer instanceof TerraNulliusImpl) { return; } this.showTable((emoji) => { const recipient = targetPlayer === this.game.myPlayer() ? AllPlayers : (targetPlayer as PlayerView); eventBus.emit( new SendEmojiIntentEvent( recipient, flattenedEmojiTable.indexOf(emoji), ), ); this.hideTable(); }); }); eventBus.on(CloseViewEvent, (e) => { if (!this.hidden) { this.hideTable(); } }); } private onEmojiClicked: (emoji: string) => void = () => {}; render() { if (!this.isVisible) { return null; } return html`