From 415f90215023525c601fb5a32f512b0198778280 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Fri, 31 Dec 2021 09:27:00 -0500 Subject: [PATCH] Serialize creature animator. (#233) In #232, cluster animations were added, but they weren't serialized as part of the cluster design, which meant that sharing them wouldn't copy over the animation. This fixes that. This also removes "(experimental)" from the animation widget label. --- lib/creature-animator.tsx | 16 +++++ lib/pages/creature-page/core.tsx | 13 ++-- .../creature-page/creature-design.avsc.json | 5 ++ .../creature-design.v2.avsc.json | 60 +++++++++++++++++++ lib/pages/creature-page/serialization.test.ts | 23 +++++++ lib/pages/creature-page/serialization.ts | 35 ++++++++--- 6 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 lib/pages/creature-page/creature-design.v2.avsc.json create mode 100644 lib/pages/creature-page/serialization.test.ts 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 (
- +