UNPKG

duckengine

Version:
74 lines (73 loc) 3.14 kB
import { Duck } from '../..'; import Vector2 from '../math/vector2'; import Animation from './animation'; import AnimationState from './animationState'; export default class StateMachine { /** * @memberof StateMachine * @description The configuration of the StateMachine * @type Duck.Types.StateMachine.Config * @since 2.0.0 */ config: Duck.Types.StateMachine.Config; /** * @memberof StateMachine * @description All animations used by the StateMachine * @type * @since 2.0.0 */ animations: Animation[]; /** * @memberof StateMachine * @description A 2D Array of AnimationStates, one connection is represented by a nested array, ex: StateMachine.connections = [[\/* one connection here *\/]] * @type AnimationState[][] * @since 2.0.0 */ connections: AnimationState[][]; /** * @memberof StateMachine * @description The current AnimationState that is traveled to, use this to get and play the animation * @type AnimationState * @since 2.0.0 */ currentState: AnimationState; /** * @memberof StateMachine * @description Creates a StateMachine instance * @param {Duck.Types.StateMachine.Config} config StateMachine configuration * @param {Animation[]} animations All Animations needed by the StateMachine * @since 2.0.0 */ constructor(config: Duck.Types.StateMachine.Config, animations: Animation[]); /** * @memberof StateMachine * @description Creates an AnimationState for both passed and values and makes a connection between from -> to * @param {Duck.Types.StateMachine.ConnectionBaseValue} from AnimationState base config to connect from * @param {Duck.Types.StateMachine.ConnectionBaseValue} to AnimationState base config to connect to * @since 2.0.0 */ connectTo(from: Duck.Types.StateMachine.ConnectionBaseValue, to: Duck.Types.StateMachine.ConnectionBaseValue): void; /** * @memberof StateMachine * @description Creates an AnimationState for both passed and values and makes a connection between from -> to and to -> from * @param {Duck.Types.StateMachine.ConnectionBaseValue} from AnimationState base config to connect from * @param {Duck.Types.StateMachine.ConnectionBaseValue} to AnimationState base config to connect to * @since 2.0.0 */ connectLoop(from: Duck.Types.StateMachine.ConnectionBaseValue, to: Duck.Types.StateMachine.ConnectionBaseValue): void; /** * @memberof StateMachine * @description Travels along the imaginary 2D plane to find a connection based on other connections' vectors * @param {Vector2} vector Vector to match to another Connection that will set the currentState as * @since 2.0.0 */ travel(vector: Vector2): void; /** * @memberof StateMachine * @description Checks if the currentState's connections include another AnimationState connection with a passed key * @param {string} dest The destination or key to find * @returns {boolean} * @since 2.0.0 */ canTravel(dest: string): boolean; }