Show creature animation dropdown.

pull/232/head
Atul Varma 2021-12-30 16:24:52 -05:00
rodzic 19791ac2e3
commit 2531d2a049
2 zmienionych plików z 43 dodań i 6 usunięć

Wyświetl plik

@ -67,7 +67,7 @@ const spinAnimator: CreatureAnimator = {
export const CREATURE_ANIMATOR_NAMES = ["none", "breathe", "spin"] as const; export const CREATURE_ANIMATOR_NAMES = ["none", "breathe", "spin"] as const;
type CreatureAnimatorName = typeof CREATURE_ANIMATOR_NAMES[number]; export type CreatureAnimatorName = typeof CREATURE_ANIMATOR_NAMES[number];
export const CreatureAnimators: { export const CreatureAnimators: {
[k in CreatureAnimatorName]: CreatureAnimator; [k in CreatureAnimatorName]: CreatureAnimator;

Wyświetl plik

@ -47,7 +47,11 @@ import { GalleryWidget } from "../../gallery-widget";
import { serializeCreatureDesign } from "./serialization"; import { serializeCreatureDesign } from "./serialization";
import { CreatureEditorWidget } from "./creature-editor"; import { CreatureEditorWidget } from "./creature-editor";
import { useAnimationPct } from "../../animation"; import { useAnimationPct } from "../../animation";
import { CreatureAnimators } from "../../creature-animator"; import {
CreatureAnimatorName,
CreatureAnimators,
CREATURE_ANIMATOR_NAMES,
} from "../../creature-animator";
/** /**
* The minimum number of attachment points that any symbol used as the main body * The minimum number of attachment points that any symbol used as the main body
@ -266,10 +270,40 @@ export const CREATURE_DESIGN_DEFAULTS: CreatureDesign = {
}, },
}; };
type AnimationWidgetProps = {
value: CreatureAnimatorName;
onChange: (name: CreatureAnimatorName) => void;
};
const AnimationWidget: React.FC<AnimationWidgetProps> = (props) => {
const id = "animationName";
return (
<div className="flex-widget thingy">
<label htmlFor={id}>Animation (experimental):</label>
<select
id={id}
onChange={(e) => props.onChange(e.target.value as CreatureAnimatorName)}
value={props.value}
>
{CREATURE_ANIMATOR_NAMES.map((choice) => (
<option key={choice} value={choice}>
{choice}
</option>
))}
</select>
</div>
);
};
export const CreaturePageWithDefaults: React.FC< export const CreaturePageWithDefaults: React.FC<
ComponentWithShareableStateProps<CreatureDesign> ComponentWithShareableStateProps<CreatureDesign>
> = ({ defaults, onChange }) => { > = ({ defaults, onChange }) => {
const svgRef = useRef<SVGSVGElement>(null); const svgRef = useRef<SVGSVGElement>(null);
const [animatorName, setAnimatorName] =
useRememberedState<CreatureAnimatorName>(
"creature-page:animatorName",
"none"
);
const [randomlyInvert, setRandomlyInvert] = useRememberedState( const [randomlyInvert, setRandomlyInvert] = useRememberedState(
"creature-page:randomlyInvert", "creature-page:randomlyInvert",
true true
@ -316,8 +350,9 @@ export const CreaturePageWithDefaults: React.FC<
); );
const render = useMemo( const render = useMemo(
() => createCreatureAnimationRenderer(creature, ctx), () =>
[creature, ctx] createCreatureAnimationRenderer(creature, ctx, undefined, animatorName),
[creature, ctx, animatorName]
); );
return ( return (
@ -325,6 +360,7 @@ export const CreaturePageWithDefaults: React.FC<
<div className="sidebar"> <div className="sidebar">
<CompositionContextWidget ctx={compCtx} onChange={setCompCtx} /> <CompositionContextWidget ctx={compCtx} onChange={setCompCtx} />
<CreatureEditorWidget creature={creature} onChange={setCreature} /> <CreatureEditorWidget creature={creature} onChange={setCreature} />
<AnimationWidget value={animatorName} onChange={setAnimatorName} />
<RandomizerWidget <RandomizerWidget
onColorsChange={(colors) => setCompCtx({ ...compCtx, ...colors })} onColorsChange={(colors) => setCompCtx({ ...compCtx, ...colors })}
onSymbolsChange={newRandomCreature} onSymbolsChange={newRandomCreature}
@ -375,7 +411,8 @@ export const CreaturePageWithDefaults: React.FC<
function createCreatureAnimationRenderer( function createCreatureAnimationRenderer(
creature: CreatureSymbol, creature: CreatureSymbol,
ctx: CreatureContextType, ctx: CreatureContextType,
scale = 0.5 scale = 0.5,
animatorName: CreatureAnimatorName = "none"
): AnimationRenderer { ): AnimationRenderer {
return (animPct) => { return (animPct) => {
return ( return (
@ -384,7 +421,7 @@ function createCreatureAnimationRenderer(
<CreatureSymbol <CreatureSymbol
{...creature} {...creature}
animPct={animPct} animPct={animPct}
animator={CreatureAnimators.spin} animator={CreatureAnimators[animatorName]}
/> />
</CreatureContext.Provider> </CreatureContext.Provider>
</SvgTransform> </SvgTransform>