diff --git a/lib/creature-animator.tsx b/lib/creature-animator.tsx index b0fb516..366b406 100644 --- a/lib/creature-animator.tsx +++ b/lib/creature-animator.tsx @@ -75,10 +75,26 @@ const spinAnimator: CreatureAnimator = { getChildAnimator: () => spinAnimator, }; +/** + * Names of all the animators. + * + * Note that this list should never be re-ordered, as the index of + * each animator corresponds to its animator id. + */ export const CREATURE_ANIMATOR_NAMES = ["none", "breathe", "spin"] as const; export type CreatureAnimatorName = typeof CREATURE_ANIMATOR_NAMES[number]; +export function creatureAnimatorNameToId(name: CreatureAnimatorName): number { + return CREATURE_ANIMATOR_NAMES.indexOf(name); +} + +export function creatureAnimatorIdToName( + id: number +): CreatureAnimatorName | undefined { + return CREATURE_ANIMATOR_NAMES[id]; +} + export const CreatureAnimators: { [k in CreatureAnimatorName]: CreatureAnimator; } = { diff --git a/lib/pages/creature-page/core.tsx b/lib/pages/creature-page/core.tsx index 7cbce9c..76d124d 100644 --- a/lib/pages/creature-page/core.tsx +++ b/lib/pages/creature-page/core.tsx @@ -256,11 +256,13 @@ function repeatUntilSymbolIsIncluded( } export type CreatureDesign = { + animatorName: CreatureAnimatorName; compCtx: SvgCompositionContext; creature: CreatureSymbol; }; export const CREATURE_DESIGN_DEFAULTS: CreatureDesign = { + animatorName: "none", compCtx: createSvgCompositionContext(), creature: { data: ROOT_SYMBOLS[0], @@ -279,7 +281,7 @@ const AnimationWidget: React.FC = (props) => { const id = "animationName"; return (
- +