Scene commands
Pass the piece slot and coordinates to a command.
CommandBus looks up the command by the name in the FSM and gives it access to the current scene.
Placement needs a slot and coordinates. The command uses BaseTypedCommand. PlaceBlockCommand.ts
import { BaseTypedCommand } from '@gamedevland/engine/commands';
import { BlockPuzzleServices } from '../BlockPuzzleServices';
import { BlockPuzzleEventSchemas } from '../configs/event.schemas';
import type { InferDecoded } from '@gamedevland/engine/validation';
type PlaceBlockCommandPayload = InferDecoded<
typeof BlockPuzzleEventSchemas.PlacementRequest
>;
export class PlaceBlockCommand extends BaseTypedCommand<PlaceBlockCommandPayload> {
protected override readonly inputDecoder =
BlockPuzzleEventSchemas.PlacementRequest;
protected override execute(payload: PlaceBlockCommandPayload): void {
this.getSceneService(BlockPuzzleServices.Gameplay).place(payload);
}
}
01
FSMRuns PlaceBlockCommand with the event
02
inputDecoderChecks slotId and anchor
03
executeReceives the validated payload
04
Gameplay.placeChecks the piece and empty cells, then applies the move
Use the same command name in CommandsGroup and the FSM configuration.
BaseTypedCommand validates the data with inputDecoder before calling execute.
If the command returns a Promise, the FSM waits for it to finish before processing the next event.