Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(agents): show the toy figure in the creator and the appearance editor

rubenluetke10-beepce9550386c57
diff --git a/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.test.tsx b/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.test.tsx
index 657802ac13..be42e7e1f6 100644
--- a/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.test.tsx
@@ -62,10 +62,16 @@ it("keeps shape customization without size or following-distance sliders", () =>
expect(screen.getByRole("button", { name: "society.companion.shapes.cloud" })).toBeTruthy();
});
-it("finds the character's actual style for older recipes without style metadata", async () => {
- setup(false, true);
+it("saves a chosen hairstyle on the recipe without dropping its colours", async () => {
+ const { agent, fetcher } = setup();
fireEvent.click(screen.getByRole("tab", { name: "society.companion.character" }));
await screen.findByTestId("character-preview");
- expect((screen.getByLabelText("society.create.style") as HTMLSelectElement).value).toBe("fantasy");
- expect((screen.getByLabelText("society.create.base") as HTMLSelectElement).value).toBe("rogue");
+ fireEvent.click(screen.getByRole("button", { name: "society.office.hair_beanie" }));
+ expect(screen.getByRole("button", { name: "society.office.hair_beanie" }).getAttribute("aria-pressed")).toBe("true");
+ fireEvent.click(screen.getByRole("button", { name: "society.card.save" }));
+ await waitFor(() => expect(fetcher).toHaveBeenCalledOnce());
+ const [, init] = fetcher.mock.calls[0] as unknown as [string, RequestInit];
+ const body = JSON.parse(init.body as string);
+ expect(body.avatar.hairStyle).toBe("beanie");
+ expect(body.avatar.palette).toEqual(agent.figure?.palette);
});
diff --git a/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.tsx b/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.tsx
index 07a434ac61..445e351d78 100644
--- a/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/companion/AgentAppearanceDialog.tsx
@@ -9,42 +9,30 @@ import { Button } from "@/components/ui/button";
import type { SocietyAgent } from "../data";
import { AgentSwatch } from "../AgentSwatch";
import { defaultRecipe, EDITABLE_CELLS, resolvePalette, type FigureRecipe } from "../figures/figureRecipe";
-import { basesForStyle, CATALOG, catalogBaseFor, isReservedStyle, keepablePartsFor, partsForSlot, slotsWithParts, stylesWithBases } from "../figures/figureRegistry";
+import { HAIR_STYLES } from "../office/playerProfile";
+import { toyLookFor } from "../office/toyFigureModel";
import { CompanionEditor } from "./CompanionEditor";
import { resolveCompanion } from "./appearance";
const AgentFigureViewer = lazy(() => import("../figures/AgentFigureViewer").then(m => ({ default: m.AgentFigureViewer })));
-const selectClass = "min-w-0 rounded-md border border-border bg-background p-2 text-sm text-foreground";
-function CharacterEditor({ value, onChange, disabled, lead }: { value: FigureRecipe; onChange: (r: FigureRecipe) => void; disabled: boolean; lead: boolean }) {
+/** The toy figure's look: hair or hat, and the six colours it wears. */
+function CharacterEditor({ value, onChange, disabled }: { value: FigureRecipe; onChange: (r: FigureRecipe) => void; disabled: boolean }) {
const t = useT();
- const base = catalogBaseFor(value);
- const style = value.model ? "custom" : value.style && base?.styles.includes(value.style) ? value.style : base?.styles[0] ?? "modern";
- const availableStyles = [...stylesWithBases(), ...(lead || isReservedStyle(style) ? ["spirit"] : [])];
const colors = resolvePalette(value);
- const selectBase = (id: string, nextStyle: string) => {
- const entry = CATALOG.bases.find(b => b.base === id);
- if (!entry) return;
- const { model: _model, ...rest } = value;
- onChange({ ...rest, base: entry.base, archetype: entry.archetype, style: nextStyle,
- heightM: entry.heightM, parts: keepablePartsFor(value.parts, entry.archetype, nextStyle, entry.family ?? null, entry.fitSize ?? null) });
- };
- const slots = value.model ? [] : slotsWithParts(value.archetype, style, base?.family ?? null, base?.fitSize ?? null);
+ const hair = toyLookFor(value, "").hairStyle;
return <fieldset disabled={disabled} className="grid gap-4 p-4" data-testid="character-editor">
<div className="h-60"><Suspense fallback={null}><AgentFigureViewer recipe={value} quiet /></Suspense></div>
- <label className="grid grid-cols-[6rem_1fr] items-center gap-3 text-sm">{t("society.create.style")}<select aria-label={t("society.create.style")} className={selectClass} value={style} onChange={e => {
- const first = basesForStyle(e.target.value)[0]; if (first) selectBase(first.base, e.target.value);
- }}>{availableStyles.map(s => <option key={s} value={s}>{t(`society.style.${s}`)}</option>)}{value.model && <option value={style}>{t("society.style.custom")}</option>}</select></label>
- {!value.model && <label className="grid grid-cols-[6rem_1fr] items-center gap-3 text-sm">{t("society.create.base")}<select aria-label={t("society.create.base")} className={selectClass} value={value.base} onChange={e => selectBase(e.target.value, style)}>
- {basesForStyle(style).map(b => <option key={b.id} value={b.base}>{b.label}</option>)}
- </select></label>}
- {slots.map(slot => <label key={slot} className="grid grid-cols-[6rem_1fr] items-center gap-3 text-sm">{t(`society.slot.${slot}`)}<select className={selectClass} value={value.parts[slot] ?? ""} onChange={e => {
- const parts = { ...value.parts }; if (e.target.value) parts[slot] = e.target.value; else delete parts[slot]; onChange({ ...value, parts });
- }}><option value="">{t("society.create.none")}</option>{partsForSlot(slot, value.archetype, style, base?.family ?? null, base?.fitSize ?? null).map(p => <option key={p.id} value={p.id}>{p.label}</option>)}</select></label>)}
+ <div className="grid gap-2 text-sm">
+ <span>{t("society.office.hair_label")}</span>
+ <div className="flex flex-wrap gap-1.5" role="group" aria-label={t("society.office.hair_label")}>
+ {HAIR_STYLES.map(style => <button key={style} type="button" aria-pressed={hair === style} onClick={() => onChange({ ...value, hairStyle: style })}
+ className={`rounded-full border px-2.5 py-1 text-xs ${hair === style ? "border-transparent bg-primary text-primary-foreground" : "border-border bg-background text-foreground hover:bg-secondary"}`}>
+ {t(`society.office.hair_${style}`)}
+ </button>)}
+ </div>
+ </div>
<div className="grid grid-cols-2 gap-3">{EDITABLE_CELLS.map(cell => <label key={cell} className="flex items-center justify-between gap-2 text-sm">{t(`society.cell.${cell}`)}<input type="color" value={colors[cell]} onChange={e => onChange({ ...value, palette: { ...value.palette, [cell]: e.target.value } })} className="h-8 w-10 rounded border border-border bg-background" /></label>)}</div>
- <label className="text-sm">{t("society.create.height")} <span className="float-right">{(value.heightM ?? base?.heightM ?? 1.75).toFixed(2)} m</span>
- <input className="mt-2 w-full" type="range" min={0.6} max={2.4} step={0.05} value={value.heightM ?? base?.heightM ?? 1.75} onChange={e => onChange({ ...value, heightM: Number(e.target.value) })} />
- </label>
</fieldset>;
}
@@ -77,7 +65,7 @@ export function AgentAppearanceDialog({ agent, sample, onClose }: { agent: Socie
<Dialog.Content data-testid="agent-appearance-dialog" onCloseAutoFocus={e => { e.preventDefault(); opener.current?.focus(); }} className="fixed left-1/2 top-1/2 z-50 flex max-h-[90dvh] w-[min(640px,calc(100vw-24px))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-border bg-popover text-foreground shadow-float">
<header className="flex items-center gap-3 border-b border-border p-4"><AgentSwatch agent={{ ...agent, figure: recipe }} size={48} /><div className="flex-1"><Dialog.Title className="font-semibold">{displayName}</Dialog.Title><Dialog.Description className="text-sm text-muted-foreground">{t("society.companion.appearance")}</Dialog.Description></div><button aria-label={t("society.card.close")} onClick={close} className="rounded p-2 hover:bg-secondary"><X size={18} /></button></header>
<div className="flex shrink-0 gap-2 border-b border-border p-3" role="tablist" aria-label={t("society.companion.appearance")}>{(["character", "companion"] as const).map(value => <button key={value} type="button" role="tab" aria-selected={tab === value} onClick={() => setTab(value)} className={`rounded-md px-3 py-2 text-sm ${tab === value ? "bg-secondary text-foreground" : "text-muted-foreground"}`}>{t(`society.companion.${value}`)}</button>)}</div>
- <div className="min-h-0 overflow-y-auto">{tab === "character" ? <CharacterEditor value={recipe} onChange={setRecipe} disabled={saving || sample} lead={agent.tier === "lead"} /> : <CompanionEditor value={resolveCompanion(agent.agentId, recipe.companion)} onChange={companion => setRecipe(r => ({ ...r, companion }))} disabled={saving || sample} lead={agent.tier === "lead"} />}</div>
+ <div className="min-h-0 overflow-y-auto">{tab === "character" ? <CharacterEditor value={recipe} onChange={setRecipe} disabled={saving || sample} /> : <CompanionEditor value={resolveCompanion(agent.agentId, recipe.companion)} onChange={companion => setRecipe(r => ({ ...r, companion }))} disabled={saving || sample} lead={agent.tier === "lead"} />}</div>
<footer className="flex shrink-0 flex-wrap justify-end gap-2 border-t border-border p-4">
{error && <p role="alert" className="w-full text-sm text-destructive">{t("society.profile_card.save_error")}</p>}
{discard ? <><span className="mr-auto text-sm" role="alert">{t("society.profile_card.unsaved")}</span><Button variant="ghost" onClick={() => setDiscard(false)}>{t("society.profile_card.keep_editing")}</Button><Button variant="secondary" onClick={onClose}>{t("society.profile_card.discard")}</Button></> : <><Button variant="ghost" onClick={close} disabled={saving}>{t("society.card.close")}</Button><Button onClick={() => void save()} disabled={!dirty || saving || sample}>{t(saving ? "society.card.saving" : "society.card.save")}</Button></>}
diff --git a/jarvis/ui/web/frontend/src/components/society/figures/AgentFigureViewer.tsx b/jarvis/ui/web/frontend/src/components/society/figures/AgentFigureViewer.tsx
index 4ca993f429..abf29f5c38 100644
--- a/jarvis/ui/web/frontend/src/components/society/figures/AgentFigureViewer.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/figures/AgentFigureViewer.tsx
@@ -1,6 +1,6 @@
/**
- * The model card's centre column: one agent's figure, rendered through the
- * same pixelated pass the island uses, turned by hand.
+ * The model card's centre column: one agent's figure — the toy character the
+ * office draws (office/ToyFigure) — turned by hand.
*
* Drag turns the figure and tilts the camera — all the way to a view from
* above and one from below — the wheel zooms, a double-click resets. The
@@ -15,27 +15,26 @@
*/
import { Component, Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
import type { ErrorInfo, PointerEvent as ReactPointerEvent, ReactNode, WheelEvent } from "react";
-import { Canvas, useFrame, useThree } from "@react-three/fiber";
+import { Canvas, useThree } from "@react-three/fiber";
import { useReducedMotion } from "framer-motion";
import * as THREE from "three";
-import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
-import { OutputPass } from "three/examples/jsm/postprocessing/OutputPass.js";
-import { RenderPixelatedPass } from "three/examples/jsm/postprocessing/RenderPixelatedPass.js";
import { useCanvasAwake } from "@/hooks/useCanvasAwake";
import { useWebglSurface } from "@/hooks/useWebglSurface";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
-import { assembleFigure, playClip, type AssembledFigure } from "./assembleFigure";
import { frameDistance } from "./figureFraming";
-import { recipeKey, resolvePalette, type FigureRecipe } from "./figureRecipe";
-import { figureAssetFor } from "./figureRegistry";
+import { resolvePalette, type FigureRecipe } from "./figureRecipe";
+import type { FigureDrive, FigureMode } from "./FigureRig";
import { LobbyStage } from "./LobbyStage";
-import { useFigureAssets } from "./useFigureAssets";
+import { ToyFigure } from "../office/ToyFigure";
+import { toyLookFor, TOY_HEIGHT, type ToyLook } from "../office/toyFigureModel";
-/** Target resolution the pixel pass renders the column at (docs §9.3). */
-const PIXEL_TARGET_WIDTH = 240;
+/** How tall the preview figure is drawn, hair included, for framing. */
+const FRAMED_HEIGHT_M = TOY_HEIGHT * 1.04;
+/** How long the opening wave lasts before the figure settles into its clip. */
+const WAVE_MS = 1800;
/** Camera pitch limit upwards: straight down is +90°; stop short of the pole. */
const PITCH_LIMIT = (80 * Math.PI) / 180;
@@ -79,10 +78,9 @@ export function AgentFigureViewer({ recipe, clip = "idle", quiet = false, classN
const [orbitTick, setOrbitTick] = useState(0);
const drag = useRef<{ x: number; y: number; id: number } | null>(null);
- const asset = recipe ? figureAssetFor(recipe) : null;
const palette = useMemo(() => resolvePalette(recipe), [recipe]);
- const heightM = recipe?.heightM ?? asset?.defaultHeightM ?? 1.75;
- const look = recipe ? recipeKey(recipe) : "";
+ const heightM = TOY_HEIGHT;
+ const look = useMemo(() => (recipe ? toyLookFor(recipe, "") : null), [recipe]);
const onPointerDown = useCallback((e: ReactPointerEvent<HTMLDivElement>) => {
if (e.button !== 0) return;
@@ -139,13 +137,13 @@ export function AgentFigureViewer({ recipe, clip = "idle", quiet = false, classN
onWheel={onWheel}
onDoubleClick={onDoubleClick}
>
- {asset && recipe ? (
+ {look ? (
<FigureErrorBoundary fallback={<PaletteTile palette={palette} label={t("society.figure.unavailable")} />}>
<Canvas
key={generation}
dpr={1}
frameloop={frameloop}
- gl={{ antialias: false, alpha: true, powerPreference: "low-power" }}
+ gl={{ antialias: true, alpha: true, powerPreference: "low-power" }}
camera={{ fov: 26, near: 0.1, far: 40, position: [0, heightM * 0.55, heightM * 2.5] }}
onCreated={({ gl }) => {
gl.setClearColor(0x000000, 0);
@@ -153,9 +151,7 @@ export function AgentFigureViewer({ recipe, clip = "idle", quiet = false, classN
>
<Suspense fallback={null}>
<FigureScene
- recipe={recipe}
look={look}
- palette={palette}
heightM={heightM}
clip={clip}
quiet={quiet}
@@ -165,7 +161,6 @@ export function AgentFigureViewer({ recipe, clip = "idle", quiet = false, classN
/>
</Suspense>
<HostSizeSync />
- <PixelPass />
</Canvas>
</FigureErrorBoundary>
) : (
@@ -183,9 +178,7 @@ export function AgentFigureViewer({ recipe, clip = "idle", quiet = false, classN
// ---------------------------------------------------------------------------
interface SceneProps {
- recipe: FigureRecipe;
- look: string;
- palette: ReturnType<typeof resolvePalette>;
+ look: ToyLook;
heightM: number;
clip: string;
quiet: boolean;
@@ -194,100 +187,46 @@ interface SceneProps {
orbitTick: number;
}
-function FigureScene({ recipe, look, palette, heightM, clip, quiet, paused, orbit, orbitTick }: SceneProps) {
- const assets = useFigureAssets(recipe);
- const gltf = assets.base;
+const CLIP_MODES: readonly FigureMode[] = ["idle", "walk", "work", "talk", "sit", "sleep", "celebrate", "wave"];
+
+function FigureScene({ look, heightM, clip, quiet, paused, orbit, orbitTick }: SceneProps) {
const camera = useThree((s) => s.camera);
const invalidate = useThree((s) => s.invalidate);
const size = useThree((s) => s.size);
const groupRef = useRef<THREE.Group>(null);
- const figureRef = useRef<AssembledFigure | null>(null);
- // What the camera frames: the body plus whatever it wears. A wizard hat
- // reaches above the figure's own height, and framing by the height alone
- // cut its point off the top of the column.
- const [framedHeightM, setFramedHeightM] = useState(heightM);
- // How far the camera stands back: the figure's LARGEST extent, so a fox is
- // framed by its length and a person still by their height.
- const [framedSpanM, setFramedSpanM] = useState(heightM);
-
- // One assembled figure per look; the previous one is disposed first.
- useEffect(() => {
- const figure = assembleFigure(
- gltf,
- palette,
- heightM,
- assets.parts.map((p) => p.gltf),
- assets.clips,
- );
- figureRef.current = figure;
- setFramedHeightM(figure?.renderedHeightM ?? heightM);
- setFramedSpanM(figure?.renderedSpanM ?? heightM);
- const group = groupRef.current;
- if (figure && group) group.add(figure.root);
- if (figure) {
- if (!quiet && figure.actions.wave) playClip(figure, "wave", clip);
- else playClip(figure, clip, clip, 0);
- if (paused) figure.mixer.update(0.001);
- }
- // The first frames after the figure lands: the pixel pass and the size
- // sync may still be settling, so ask for a few draws, not one.
- invalidate();
- let frames = 0;
- const kick = () => {
- invalidate();
- if (++frames < 6) requestAnimationFrame(kick);
- };
- requestAnimationFrame(kick);
- return () => {
- if (figure && group) group.remove(figure.root);
- figure?.dispose();
- figureRef.current = null;
- };
- // `look` stands in for the palette object identity; heightM and the
- // gltf are part of the same identity.
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [gltf, look, heightM]);
+ const settled: FigureMode = (CLIP_MODES as readonly string[]).includes(clip) ? (clip as FigureMode) : "idle";
+ const drive = useRef<FigureDrive>({ mode: quiet ? settled : "wave", speed: 0 });
+ // Wave once on open, then hold the requested clip.
useEffect(() => {
- const figure = figureRef.current;
- if (figure) playClip(figure, clip, clip);
+ drive.current.mode = quiet ? settled : "wave";
invalidate();
- }, [clip, invalidate]);
+ if (quiet) return;
+ const timer = setTimeout(() => { drive.current.mode = settled; invalidate(); }, WAVE_MS);
+ return () => clearTimeout(timer);
+ }, [quiet, settled, invalidate]);
// The camera orbits the figure's middle: yaw turns the figure itself (so
- // the light stays put), pitch and zoom move the camera.
+ // the light stays put), pitch and zoom move the camera. Stand back far
+ // enough for the figure to fit the box both ways, whatever its shape.
useEffect(() => {
const group = groupRef.current;
const o = orbit.current;
if (group) group.rotation.y = o.yaw;
- // Stand back far enough for the figure to fit the box BOTH ways. A fixed
- // multiple of its height only works while the column is tall: the look
- // editor grew, the column became wide and short, and a fixed distance cut
- // the legs off. Solving the frustum for the span in each axis does not
- // care what shape the box is.
- const mid = framedHeightM * 0.5;
- // The stage always mounts a perspective camera; the store types it loosely.
+ const mid = FRAMED_HEIGHT_M * 0.5;
const lens = camera as THREE.PerspectiveCamera;
- const distance = frameDistance({
- spanM: framedSpanM,
- fovDeg: lens.fov,
- aspect: lens.aspect,
- zoom: o.zoom,
- });
+ const distance = frameDistance({ spanM: FRAMED_HEIGHT_M, fovDeg: lens.fov, aspect: lens.aspect, zoom: o.zoom });
camera.position.set(0, mid + Math.sin(o.pitch) * distance, Math.cos(o.pitch) * distance);
camera.lookAt(0, mid, 0);
camera.updateProjectionMatrix();
invalidate();
- }, [orbitTick, framedHeightM, framedSpanM, camera, invalidate, orbit, size]);
-
- useFrame((_, dt) => {
- if (paused) return;
- figureRef.current?.mixer.update(Math.min(dt, 0.1));
- });
+ }, [orbitTick, camera, invalidate, orbit, size]);
return (
<>
- <group ref={groupRef} />
+ <group ref={groupRef}>
+ <ToyFigure look={look} drive={drive} paused={paused} heightM={heightM} />
+ </group>
{/* The room the agent spawns into, lights included (LobbyStage). */}
<LobbyStage heightM={heightM} paused={paused} />
</>
@@ -325,29 +264,6 @@ function HostSizeSync() {
return null;
}
-/** The island's look, in the card: the scene through a low-resolution, nearest-filtered target. */
-function PixelPass() {
- const { gl, scene, camera, size } = useThree();
- const composer = useMemo(() => {
- const c = new EffectComposer(gl);
- const pass = new RenderPixelatedPass(2, scene, camera, { normalEdgeStrength: 0.3, depthEdgeStrength: 0.4 });
- c.addPass(pass);
- c.addPass(new OutputPass());
- return { composer: c, pass };
- }, [gl, scene, camera]);
-
- useEffect(() => {
- const pixelSize = Math.max(2, Math.round(size.width / PIXEL_TARGET_WIDTH));
- composer.pass.setPixelSize(pixelSize);
- composer.composer.setSize(size.width, size.height);
- }, [composer, size]);
-
- useEffect(() => () => composer.composer.dispose(), [composer]);
-
- useFrame(() => composer.composer.render(), 1);
- return null;
-}
-
// ---------------------------------------------------------------------------
// fallbacks
// ---------------------------------------------------------------------------
diff --git a/jarvis/ui/web/frontend/src/components/society/figures/figureRecipe.ts b/jarvis/ui/web/frontend/src/components/society/figures/figureRecipe.ts
index 2d23121db1..cf53f8fed1 100644
--- a/jarvis/ui/web/frontend/src/components/society/figures/figureRecipe.ts
+++ b/jarvis/ui/web/frontend/src/components/society/figures/figureRecipe.ts
@@ -54,6 +54,8 @@ export interface FigureRecipe {
model?: string;
/** The style the look was picked from — metadata for the creator, never read by the runtime. */
style?: string;
+ /** The toy figure's hair or hat ("short", "spiky", "bun", …); absent = derived from the rest of the recipe. */
+ hairStyle?: string;
}
/** The biped's default look — the built sheet's own strip, for a natural first figure. */
@@ -208,7 +210,7 @@ export function recipeKey(recipe: FigureRecipe): string {
.sort(([a], [b]) => a.localeCompare(b))
.map(([k, v]) => `${k}=${v}`)
.join(";");
- return `${recipe.archetype}/${recipe.base}|${recipe.model ?? ""}|${parts}|${palette}|${recipe.heightM ?? ""}`;
+ return `${recipe.archetype}/${recipe.base}|${recipe.model ?? ""}|${parts}|${palette}|${recipe.heightM ?? ""}|${recipe.hairStyle ?? ""}`;
}
/**
diff --git a/jarvis/ui/web/frontend/src/components/society/office/toyFigureModel.ts b/jarvis/ui/web/frontend/src/components/society/office/toyFigureModel.ts
index ec300f2a09..824b734929 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/toyFigureModel.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/toyFigureModel.ts
@@ -17,7 +17,7 @@
* the hip joints sit HIP_UP above it.
*/
-import type { FigureRecipe, Palette } from "../figures/figureRecipe";
+import { recipeKey, type FigureRecipe, type Palette } from "../figures/figureRecipe";
import type { FigureMode } from "../figures/FigureRig";
// ---------------------------------------------------------------------------
@@ -115,6 +115,17 @@ function naturalSkinFor(hex: string): string {
* primary → shirt, accent → shirt accent, secondary → trousers, shoes), with a
* stable hash of `identity` choosing the hair style, blush and any missing colour.
*/
+/** The hair the recipe names explicitly, when it is one this figure can draw. */
+function chosenHair(recipe: FigureRecipe | null): HairStyle | null {
+ const value = recipe?.hairStyle;
+ return typeof value === "string" && (HAIR_STYLE_WHEEL as readonly string[]).includes(value) ? (value as HairStyle) : null;
+}
+
+/**
+ * The toy look for a stored figure. Hair comes from the recipe itself (its own
+ * field, else a hash of the recipe), never from the agent id, so the creator's
+ * preview and the office always draw the same person.
+ */
export function toyLookFor(recipe: FigureRecipe | null, identity: string): ToyLook {
const hash = hashString(identity || "toy");
const palette: Partial<Palette> = recipe?.palette ?? {};
@@ -123,7 +134,7 @@ export function toyLookFor(recipe: FigureRecipe | null, identity: string): ToyLo
return {
skin,
hair: validColour(palette.hair) ?? pick(HAIR_COLOURS, hash, 0x7a),
- hairStyle: pick(HAIR_STYLE_WHEEL, hash, 0x3c),
+ hairStyle: chosenHair(recipe) ?? pick(HAIR_STYLE_WHEEL, recipe ? hashString(recipeKey({ ...recipe, hairStyle: undefined })) : hash, 0x3c),
shirt: validColour(palette.primary) ?? pick(SHIRT_COLOURS, hash, 0x19),
shirtAccent: validColour(palette.accent) ?? pick(SHIRT_COLOURS, hash, 0x2d),
pants: validColour(palette.secondary) ?? pick(PANTS_COLOURS, hash, 0x44),
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/de.json b/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
index 82a07b017a..526f8d7c72 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/de.json
@@ -822,7 +822,8 @@
"hair_long": "Lang",
"hair_beanie": "Mütze",
"hair_cap": "Cap",
- "hair_bald": "Glatze"
+ "hair_bald": "Glatze",
+ "hair_label": "Frisur oder Kopfbedeckung"
}
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/en.json b/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
index 3d57f4dcc0..55cc98e2b0 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/en.json
@@ -822,7 +822,8 @@
"hair_long": "Long",
"hair_beanie": "Beanie",
"hair_cap": "Cap",
- "hair_bald": "Bald"
+ "hair_bald": "Bald",
+ "hair_label": "Hair or hat"
}
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/society/es.json b/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
index 9103bfd752..f6bb297926 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/society/es.json
@@ -822,7 +822,8 @@
"hair_long": "Largo",
"hair_beanie": "Gorro",
"hair_cap": "Gorra",
- "hair_bald": "Calvo"
+ "hair_bald": "Calvo",
+ "hair_label": "Peinado o sombrero"
}
}
}