import { GameEntityBehavior } from "../classes/entity.d.ts"; import { GameEvent } from "../classes/eventBus.d.ts"; import { StateMachine } from "../utils/stateMachine.d.ts"; /** * A single transition definition for the state machine behavior configuration. */ export interface TransitionConfig { from: States; to: States; guard?: () => boolean; } /** * A wildcard transition definition (from any state). */ export interface WildcardTransitionConfig { to: States; guard?: () => boolean; } /** * Configuration for creating a StateMachineBehavior subclass. */ export interface StateMachineBehaviorConfig { /** The initial state of the state machine. */ initialState: States; /** The key in the entity's state object to update when state changes. */ stateKey: keyof EntityState & string; /** Valid transitions between states. */ transitions: TransitionConfig[]; /** Wildcard transitions (from any state). */ wildcardTransitions?: WildcardTransitionConfig[]; } /** * A behavior that wraps a {@link StateMachine} and ties it to entity state. * * Since behaviors are instantiated with `new BehaviorClass()` (no constructor args), * use the static factory `StateMachineBehavior.create(config)` to produce a configured subclass. * * @example * ```typescript * const EnemyAI = StateMachineBehavior.create({ * initialState: 'idle', * stateKey: 'aiState', * transitions: [ * { from: 'idle', to: 'patrol' }, * { from: 'patrol', to: 'chase' }, * { from: 'chase', to: 'attack' }, * ], * wildcardTransitions: [ * { to: 'dead' }, * ], * }); * ``` */ export declare class StateMachineBehavior extends GameEntityBehavior { name: string; eventSubscriptions: string[]; protected stateMachine: StateMachine; protected stateKey: keyof EntityState & string; protected constructor(); /** * The current state of the state machine. */ get currentState(): States; /** * Transition to a new state. Updates the entity's state and emits a state changed event. * * @throws If the transition is not defined or a guard rejects it. */ transition(to: States): void; processEvent(_event: GameEvent, _state: EntityState): boolean; /** * Creates a configured StateMachineBehavior subclass with the given state machine configuration baked in. * The returned class can be used directly as a behavior constructor. */ static create(config: StateMachineBehaviorConfig): new () => StateMachineBehavior; }