MCPcopy Create free account
hub / github.com/melonjs/melonJS / parseAnimationOptions

Function parseAnimationOptions

packages/melonjs/src/renderable/animation.ts:36–66  ·  view source on GitHub ↗
(
	arg?:
		| string
		| (() => unknown)
		| {
				onComplete?: () => unknown;
				next?: string;
				loop?: boolean;
				speed?: number;
		  }
		// `null` is passed by the internal animation-chain call
		// (`setCurrentAnimation(next, null, true)`), so it must be accepted.
		| null,
)

Source from the content-addressed store, hash-verified

34 * @category Animation
35 */
36export function parseAnimationOptions(
37 arg?:
38 | string
39 | (() => unknown)
40 | {
41 onComplete?: () => unknown;
42 next?: string;
43 loop?: boolean;
44 speed?: number;
45 }
46 // `null` is passed by the internal animation-chain call
47 // (`setCurrentAnimation(next, null, true)`), so it must be accepted.
48 | null,
49): AnimationOptions {
50 if (typeof arg === "string") {
51 return { next: arg, loop: true, speed: 1 };
52 }
53 if (typeof arg === "function") {
54 return { onComplete: arg, loop: true, speed: 1, legacyFn: true };
55 }
56 if (arg !== null && typeof arg === "object") {
57 return {
58 onComplete: arg.onComplete,
59 next: arg.next,
60 // only an explicit `false` disables looping
61 loop: arg.loop !== false,
62 speed: typeof arg.speed === "number" ? arg.speed : 1,
63 };
64 }
65 return { loop: true, speed: 1 };
66}

Callers 3

setCurrentAnimationMethod · 0.90
setCurrentAnimationMethod · 0.90
animation.spec.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected