import { defineComponent } from "../../src/component"; import type { Entity, World } from "../../src/index"; import type { CommandQueue } from "../../src/commands/index"; import type { ActionKind } from "./components"; import { selectAction } from "./rules"; export interface SelectionNotifier { notifySelectionChanged(): void; } export const SelectActionCard = defineComponent("threeMonks.selectActionCard", { player: 0 as Entity, kind: "rest" as ActionKind, }); export function registerCommands( world: World, commands: CommandQueue, flow?: SelectionNotifier, ): void { commands.handle(SelectActionCard, (command) => { selectAction(world, command.player, command.kind); flow?.notifySelectionChanged(); }); } export function issueSelectAction( world: World, player: Entity, kind: ActionKind, ): Entity { const command = world.spawn(); world.add(command, SelectActionCard, { player, kind }); return command; }