@ue-too/board
Version:
132 lines (131 loc) • 5.62 kB
TypeScript
import type { EventReactions, State, BaseContext } from "@ue-too/being";
import { TemplateState, TemplateStateMachine } from "@ue-too/being";
import { BoardCamera } from "../../interface";
/**
* @description The states of the pan control state machine.
*
* @category Input Flow Control
*/
export type RotateControlStates = "ACCEPTING_USER_INPUT" | "TRANSITION" | "LOCKED_ON_OBJECT";
/**
* @description The payload for the rotate by input event.
*
* @category Input Flow Control
*/
export type RotateByInputEventPayload = {
diff: number;
};
/**
* @description The payload for the rotate to input event.
*
* @category Input Flow Control
*/
export type RotateToInputEventPayload = {
target: number;
};
type EmptyPayload = {};
/**
* @description The payload mapping for the events of the rotate control state machine.
*
* @category Input Flow Control
*/
export type RotateEventPayloadMapping = {
"userRotateByInput": RotateByInputEventPayload;
"userRotateToInput": RotateToInputEventPayload;
"transitionRotateByInput": RotateByInputEventPayload;
"transitionRotateToInput": RotateToInputEventPayload;
"lockedOnObjectRotateByInput": RotateByInputEventPayload;
"lockedOnObjectRotateToInput": RotateToInputEventPayload;
"unlock": EmptyPayload;
"initateTransition": EmptyPayload;
};
/**
* @description The context for the rotate control state machine.
*
* @category Input Flow Control
*/
export interface RotateContext extends BaseContext {
camera: BoardCamera;
rotateBy: (delta: number) => void;
rotateTo: (target: number) => void;
}
/**
* @description The pan control state machine.
* It's not created directly using the TemplateStateMachine class.
* A few helper functions are in place to make it easier to use. (user don't have to memorize the event names)
*
* @category Input Flow Control
*/
export declare class RotateControlStateMachine extends TemplateStateMachine<RotateEventPayloadMapping, RotateContext, RotateControlStates> {
constructor(states: Record<RotateControlStates, State<RotateEventPayloadMapping, RotateContext, RotateControlStates>>, initialState: RotateControlStates, context: RotateContext);
/**
* @description Notify the pan input event.
*
* @category Input Flow Control
*/
notifyRotateByInput(diff: number): void;
/**
* @description Notify the rotate to animation input event.
*
* @category Input Flow Control
*/
notifyRotateToAnimationInput(target: number): void;
/**
* @description Initate the transition.
*
* @category Input Flow Control
*/
initateTransition(): void;
}
/**
* @description The accepting user input state of the rotate control state machine.
*
* @category Input Flow Control
*/
export declare class RotationAcceptingUserInputState extends TemplateState<RotateEventPayloadMapping, RotateContext, RotateControlStates> {
constructor();
eventReactions: EventReactions<RotateEventPayloadMapping, RotateContext, RotateControlStates>;
userRotateByInputHandler(context: RotateContext, payload: RotateByInputEventPayload): void;
userRotateToInputHandler(context: RotateContext, payload: RotateToInputEventPayload): void;
lockedOnObjectRotateByInputHandler(context: RotateContext, payload: RotateByInputEventPayload): void;
lockedOnObjectRotateToInputHandler(context: RotateContext, payload: RotateToInputEventPayload): void;
}
/**
* @description The transition state of the rotate control state machine.
*
* @category Input Flow Control
*/
export declare class RotationTransitionState extends TemplateState<RotateEventPayloadMapping, RotateContext, RotateControlStates> {
constructor();
eventReactions: EventReactions<RotateEventPayloadMapping, RotateContext, RotateControlStates>;
userRotateByInputHandler(context: RotateContext, payload: RotateByInputEventPayload): RotateControlStates;
userRotateToInputHandler(context: RotateContext, payload: RotateToInputEventPayload): RotateControlStates;
transitionRotateByInputHandler(context: RotateContext, payload: RotateByInputEventPayload): RotateControlStates;
transitionRotateToInputHandler(context: RotateContext, payload: RotateToInputEventPayload): RotateControlStates;
lockedOnObjectRotateByInputHandler(context: RotateContext, payload: RotateByInputEventPayload): RotateControlStates;
lockedOnObjectRotateToInputHandler(context: RotateContext, payload: RotateToInputEventPayload): RotateControlStates;
}
/**
* @description The locked on object state of the pan control state machine.
*
* @category Input Flow Control
*/
export declare class RotationLockedOnObjectState extends TemplateState<RotateEventPayloadMapping, RotateContext, RotateControlStates> {
constructor();
eventReactions: EventReactions<RotateEventPayloadMapping, RotateContext, RotateControlStates>;
lockedOnObjectRotateByInputHandler(context: RotateContext, payload: RotateByInputEventPayload): void;
lockedOnObjectRotateToInputHandler(context: RotateContext, payload: RotateToInputEventPayload): void;
}
/**
* @description Create the object containing the default pan control states.
*
* @category Input Flow Control
*/
export declare function createDefaultRotateControlStates(): Record<RotateControlStates, State<RotateEventPayloadMapping, RotateContext, RotateControlStates>>;
/**
* @description Create the default rotate control state machine.
*
* @category Input Flow Control
*/
export declare function createDefaultRotateControlStateMachine(context: RotateContext): RotateControlStateMachine;
export {};