33 lines
2.2 KiB
TypeScript
33 lines
2.2 KiB
TypeScript
import type { FCurveInterpolation } from "./web-engine";
|
|
import type { WebEngineEditCommand } from "./web-engine";
|
|
|
|
type AnimationCommand<T extends WebEngineEditCommand["type"]> = Extract<WebEngineEditCommand, { type: T }>;
|
|
|
|
/** Typed constructors for animation, constraint and render property edits. */
|
|
export const animationRenderCommands = Object.freeze({
|
|
insertKeyframe(objectId: string, frame: number, property: AnimationCommand<"insertObjectKeyframe">["property"], interpolation: FCurveInterpolation = "BEZIER"): AnimationCommand<"insertObjectKeyframe"> {
|
|
return { type: "insertObjectKeyframe", objectId, frame, property, interpolation };
|
|
},
|
|
deleteKeyframe(objectId: string, frame: number, property?: AnimationCommand<"deleteObjectKeyframe">["property"]): AnimationCommand<"deleteObjectKeyframe"> {
|
|
return { type: "deleteObjectKeyframe", objectId, frame, ...(property ? { property } : {}) };
|
|
},
|
|
setConstraint(objectId: string, constraintName: string, enabled: boolean, influence: number): AnimationCommand<"setConstraint"> {
|
|
return { type: "setConstraint", objectId, constraintName, enabled, influence };
|
|
},
|
|
setActiveAction(objectId: string, actionId: string | null): AnimationCommand<"setActiveAction"> {
|
|
return { type: "setActiveAction", objectId, actionId };
|
|
},
|
|
setNLAStack(objectId: string, tracks: AnimationCommand<"setNLAStack">["tracks"], baseRevision?: number): AnimationCommand<"setNLAStack"> {
|
|
return { type: "setNLAStack", objectId, tracks, ...(baseRevision === undefined ? {} : { baseRevision }) };
|
|
},
|
|
setLightProperties(dataId: string, properties: AnimationCommand<"setLightProperties">["properties"]): AnimationCommand<"setLightProperties"> {
|
|
return { type: "setLightProperties", dataId, properties };
|
|
},
|
|
setCameraProperties(dataId: string, properties: AnimationCommand<"setCameraProperties">["properties"]): AnimationCommand<"setCameraProperties"> {
|
|
return { type: "setCameraProperties", dataId, properties };
|
|
},
|
|
setWorldProperties(dataId: string, properties: AnimationCommand<"setWorldProperties">["properties"]): AnimationCommand<"setWorldProperties"> {
|
|
return { type: "setWorldProperties", dataId, properties };
|
|
},
|
|
} satisfies Record<string, (...args: never[]) => WebEngineEditCommand>);
|