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): office wardrobe with outfits, colourways, hair, glasses and dressing agents

rubenluetke10-beepf07a6fe929f2
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 cf53f8fed1..1cef4a31e4 100644
--- a/jarvis/ui/web/frontend/src/components/society/figures/figureRecipe.ts
+++ b/jarvis/ui/web/frontend/src/components/society/figures/figureRecipe.ts
@@ -56,6 +56,12 @@ export interface FigureRecipe {
style?: string;
/** The toy figure's hair or hat ("short", "spiky", "bun", …); absent = derived from the rest of the recipe. */
hairStyle?: string;
+ /** The toy figure's outfit ("tee", "suit", "leather", …); absent = the casual tee. */
+ outfit?: string;
+ /** The shirt colour under a jacket or vest (#rrggbb); absent = white. */
+ inner?: string;
+ /** "none" | "glasses" | "shades"; absent = none. */
+ eyewear?: string;
}
/** The biped's default look — the built sheet's own strip, for a natural first figure. */
@@ -202,6 +208,12 @@ export function resolvePalette(
return out;
}
+/** The toy wardrobe's part of the key; empty for a recipe without one, so older keys stay unchanged. */
+function wardrobeKey(recipe: FigureRecipe): string {
+ const fields = [recipe.outfit, recipe.inner, recipe.eyewear];
+ return fields.some(Boolean) ? `|${fields.map((v) => v ?? "").join("|")}` : "";
+}
+
/** A stable key for caching painted sheets and face crops per look. */
export function recipeKey(recipe: FigureRecipe): string {
const palette = PALETTE_CELLS.map((c) => recipe.palette?.[c] ?? "").join(",");
@@ -210,7 +222,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 ?? ""}|${recipe.hairStyle ?? ""}`;
+ return `${recipe.archetype}/${recipe.base}|${recipe.model ?? ""}|${parts}|${palette}|${recipe.heightM ?? ""}|${recipe.hairStyle ?? ""}${wardrobeKey(recipe)}`;
}
/**
diff --git a/jarvis/ui/web/frontend/src/components/society/office/ToyFigure.tsx b/jarvis/ui/web/frontend/src/components/society/office/ToyFigure.tsx
index 65884c69c8..d8c80e9099 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/ToyFigure.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/ToyFigure.tsx
@@ -14,15 +14,15 @@
import { useMemo, useRef, type MutableRefObject } from "react";
import { useFrame } from "@react-three/fiber";
import {
- CapsuleGeometry, Color, ConeGeometry, MeshBasicMaterial, MeshStandardMaterial, SphereGeometry, TorusGeometry,
- type Group,
+ BoxGeometry, CapsuleGeometry, Color, ConeGeometry, CylinderGeometry, MeshBasicMaterial, MeshStandardMaterial,
+ SphereGeometry, TorusGeometry, type Group,
} from "three";
import { RoundedBoxGeometry } from "three-stdlib";
import type { FigureMode } from "../figures/FigureRig";
import {
blendPose, copyPose, createPose, poseFor, TOY, TOY_HEIGHT, walkCadence,
- type HairStyle, type PoseOptions, type ToyLook, type ToyPose,
+ type HairStyle, type OutfitId, type PoseOptions, type ToyLook, type ToyPose,
} from "./toyFigureModel";
// ---------------------------------------------------------------------------
@@ -48,15 +48,21 @@ const GEO = {
brim: new RoundedBoxGeometry(0.3, 0.022, 0.17, 2, 0.01),
/** A band of hair around the back and sides, from just above the equator down: the hair a hat leaves visible. */
hairBand: new SphereGeometry(1, 40, 14, Math.PI * 0.92, Math.PI * 1.16, Math.PI * 0.46, Math.PI * 0.3),
+ /** A unit triangular pyramid, one flat face towards +z, tip up: a jacket's V-opening (scaled, turned tip down). */
+ wedge: new ConeGeometry(1, 1, 3, 1, false, Math.PI),
+ box: new BoxGeometry(1, 1, 1),
+ collar: new CylinderGeometry(0.085, 0.097, 1, 24),
+ pocket: new RoundedBoxGeometry(0.2, 0.07, 0.02, 2, 0.01),
+ lens: new TorusGeometry(0.047, 0.008, 8, 24),
};
const materials = new Map<string, MeshStandardMaterial>();
-/** A matte material per colour, shared by every figure. */
-function matte(color: string, roughness = 0.82): MeshStandardMaterial {
- const key = `${color}|${roughness}`;
+/** A material per colour, shared by every figure; matte unless a garment asks for sheen. */
+function matte(color: string, roughness = 0.82, metalness = 0): MeshStandardMaterial {
+ const key = `${color}|${roughness}|${metalness}`;
let m = materials.get(key);
if (!m) {
- m = new MeshStandardMaterial({ color, roughness, metalness: 0 });
+ m = new MeshStandardMaterial({ color, roughness, metalness });
materials.set(key, m);
}
return m;
@@ -66,6 +72,9 @@ const EYE = new MeshStandardMaterial({ color: "#16161b", roughness: 0.35, metaln
const CATCHLIGHT = new MeshBasicMaterial({ color: "#ffffff" });
const MOUTH = matte("#5b2b28", 0.7);
const SOLE_LIGHT = "#f4f4f2";
+const METAL = matte("#c7c9cc", 0.3, 0.8);
+const FRAME = matte("#1a1a1e", 0.4);
+const SHADES = matte("#101014", 0.15, 0.2);
function mix(a: string, b: string, k: number): string {
return `#${new Color(a).lerp(new Color(b), k).getHexString()}`;
@@ -232,6 +241,37 @@ function Hair({ style, look }: { style: HairStyle; look: ToyLook }) {
))}
</group>
);
+ case "slick":
+ // Combed straight back with a little quiff: no fringe, a polished sheen.
+ return (
+ <group>
+ <HairCap color={look.hair} fringe={false} />
+ {/* Sunk into the cap at the front hairline, so it reads as swept-up hair rather than a hat. */}
+ <mesh geometry={GEO.sphere} material={matte(look.hair, 0.45)} position={[0, HD.y + HD.ry - 0.075, 0.12]} rotation={[-0.75, 0, 0]}
+ scale={[0.19, 0.06, 0.11]} castShadow />
+ </group>
+ );
+ case "sidepart":
+ return (
+ <group>
+ <HairCap color={look.hair} fringe={false} />
+ {/* One swept wave from the parting across the forehead. */}
+ <mesh geometry={GEO.sphere} material={hair} position={[-0.04, HD.y + 0.2, faceZ(-0.04, HD.y + 0.2, 0.04)]} rotation={[0.55, 0, 0.22]}
+ scale={[0.22, 0.07, 0.08]} castShadow />
+ </group>
+ );
+ case "buzz":
+ // Close-cropped: a thin cap tinted towards the skin, no fringe.
+ return <HairCap color={mix(look.hair, look.skin, 0.3)} grow={-0.014} fringe={false} />;
+ case "ponytail":
+ return (
+ <group>
+ <HairCap color={look.hair} />
+ <mesh geometry={GEO.lowSphere} material={matte(look.shirtAccent)} position={[0, HD.y + 0.06, -(HD.rz + 0.025)]} scale={0.035} />
+ <mesh geometry={GEO.sphere} material={hair} position={[0, HD.y - 0.08, -(HD.rz + 0.035)]} rotation={[0.18, 0, 0]}
+ scale={[0.06, 0.15, 0.055]} castShadow />
+ </group>
+ );
case "beanie": {
const knit = matte(look.shirtAccent, 0.95);
return (
@@ -262,16 +302,165 @@ function Hair({ style, look }: { style: HairStyle; look: ToyLook }) {
}
}
+// ---------------------------------------------------------------------------
+// Clothes
+
+/** Outfits worn with polished dress shoes (when the shoe colour is dark). */
+const DRESS_SHOES: ReadonlySet<OutfitId> = new Set(["suit", "blazer", "leather"]);
+
+/** Outfits whose jacket shows a shirt cuff at the wrist. */
+const CUFFED: ReadonlySet<OutfitId> = new Set(["suit", "blazer"]);
+
+/** The material of a garment: leather shines, knits and fleece stay soft. */
+function garment(look: ToyLook, color: string): MeshStandardMaterial {
+ if (look.outfit === "leather" && color === look.shirt) return matte(color, 0.32, 0.12);
+ if (look.outfit === "quarterzip" || look.outfit === "turtleneck" || look.outfit === "hoodie") return matte(color, 0.95);
+ return matte(color);
+}
+
+/** Front of the chest (torso-local z) at mid height; the rounded box curves back above and below. */
+const FRONT = TOY.torso.d / 2;
+
+/**
+ * The opening of a jacket or vest: a shirt-coloured V (tip down) with lapels
+ * along its edges, tilted back to follow the chest's rounded top.
+ */
+function VOpening({ look, width, depth, lapel, tie }: { look: ToyLook; width: number; depth: number; lapel: number; tie: boolean }) {
+ const top = 0.285;
+ const angle = Math.atan2(width / 2, depth);
+ const edge = Math.hypot(width / 2, depth);
+ const shade = garment(look, mix(look.shirt, "#000000", look.outfit === "leather" ? 0.25 : 0.14));
+ return (
+ <group position={[0, top - depth / 2, FRONT - 0.012]} rotation={[-0.22, 0, 0]}>
+ {/* A cone of radius r has a face r·√3 wide; scaled flat in z it is a triangle on the chest. */}
+ <mesh geometry={GEO.wedge} material={matte(look.inner)} rotation={[0, 0, Math.PI]} scale={[width / Math.sqrt(3), depth, 0.03]} />
+ {[-1, 1].map((sx) => (
+ <mesh key={sx} geometry={GEO.box} material={shade} castShadow
+ position={[sx * (width / 4 + lapel * 0.45), 0, 0.02]} rotation={[0, 0, -sx * angle]} scale={[lapel, edge + 0.02, 0.012]} />
+ ))}
+ {tie && (
+ <group position={[0, 0, 0.022]}>
+ <mesh geometry={GEO.box} material={matte(look.shirtAccent, 0.5)} position={[0, depth / 2 - 0.018, 0]} scale={[0.03, 0.024, 0.014]} />
+ <mesh geometry={GEO.box} material={matte(look.shirtAccent, 0.5)} position={[0, -0.012, 0]} scale={[0.028, depth - 0.05, 0.01]} />
+ </group>
+ )}
+ </group>
+ );
+}
+
+function Buttons({ count, color }: { count: number; color: string }) {
+ return (
+ <>
+ {Array.from({ length: count }, (_, i) => (
+ <mesh key={i} geometry={GEO.lowSphere} material={matte(color, 0.4)} position={[0, 0.105 - i * 0.04, FRONT + 0.004 - i * 0.006]} scale={[0.011, 0.011, 0.006]} />
+ ))}
+ </>
+ );
+}
+
+/** Everything an outfit adds to the chest: opening, lapels, tie, collar, hood, zip, pockets. */
+function OutfitDetails({ look }: { look: ToyLook }) {
+ const accent = matte(look.shirtAccent);
+ const dark = mix(look.shirt, "#000000", 0.35);
+ switch (look.outfit) {
+ case "suit":
+ return (
+ <group>
+ <VOpening look={look} width={0.13} depth={0.17} lapel={0.034} tie />
+ <Buttons count={2} color={dark} />
+ <mesh geometry={GEO.box} material={accent} position={[0.09, 0.2, FRONT + 0.002]} scale={[0.04, 0.014, 0.01]} />
+ </group>
+ );
+ case "blazer":
+ return (
+ <group>
+ <VOpening look={look} width={0.14} depth={0.16} lapel={0.034} tie={false} />
+ <Buttons count={1} color={mix(look.shirtAccent, "#000000", 0.2)} />
+ <mesh geometry={GEO.box} material={accent} position={[0.09, 0.2, FRONT + 0.002]} scale={[0.04, 0.014, 0.01]} />
+ </group>
+ );
+ case "leather":
+ // A moto-style leather jacket: wide shiny collar and an off-centre zip over a plain tee.
+ return (
+ <group>
+ <VOpening look={look} width={0.16} depth={0.17} lapel={0.05} tie={false} />
+ <mesh geometry={GEO.box} material={METAL} position={[-0.055, 0.075, FRONT + 0.003]} scale={[0.008, 0.1, 0.008]} />
+ <mesh geometry={GEO.box} material={METAL} position={[0.085, 0.11, FRONT + 0.002]} scale={[0.05, 0.006, 0.008]} />
+ </group>
+ );
+ case "vest":
+ // A fleece vest over a button-down: a small shirt V, a centre zip and a chest logo.
+ return (
+ <group>
+ <VOpening look={look} width={0.1} depth={0.09} lapel={0.022} tie={false} />
+ <mesh geometry={GEO.box} material={METAL} position={[0, 0.12, FRONT + 0.002]} scale={[0.007, 0.13, 0.008]} />
+ <mesh geometry={GEO.box} material={accent} position={[0.075, 0.2, FRONT + 0.002]} scale={[0.04, 0.02, 0.008]} />
+ </group>
+ );
+ case "turtleneck":
+ return <mesh geometry={GEO.collar} material={garment(look, look.shirt)} position={[0, 0.29, 0]} scale={[1, 0.075, 1]} castShadow />;
+ case "quarterzip":
+ return (
+ <group>
+ <mesh geometry={GEO.collar} material={garment(look, look.shirt)} position={[0, 0.285, 0]} scale={[1.04, 0.055, 1.04]} castShadow />
+ <mesh geometry={GEO.box} material={METAL} position={[0, 0.25, FRONT - 0.01]} rotation={[-0.45, 0, 0]} scale={[0.008, 0.09, 0.01]} />
+ <mesh geometry={GEO.box} material={METAL} position={[0.012, 0.21, FRONT + 0.004]} scale={[0.012, 0.022, 0.006]} />
+ </group>
+ );
+ case "hoodie":
+ return (
+ <group>
+ {/* The hood lies folded behind the neck. */}
+ <mesh geometry={GEO.sphere} material={garment(look, look.shirt)} position={[0, 0.275, -0.07]} scale={[0.15, 0.065, 0.085]} castShadow />
+ {[-1, 1].map((sx) => (
+ <mesh key={sx} geometry={GEO.box} material={accent} position={[sx * 0.035, 0.22, FRONT - 0.002]} rotation={[-0.3, 0, 0]} scale={[0.009, 0.075, 0.009]} />
+ ))}
+ <mesh geometry={GEO.pocket} material={garment(look, dark)} position={[0, 0.075, FRONT - 0.006]} />
+ </group>
+ );
+ case "tee":
+ default:
+ // Chest emblem in the accent colour, like the logo on a T-shirt.
+ return <mesh geometry={GEO.sphere} material={accent} position={[0, 0.16, FRONT - 0.004]} scale={[0.05, 0.05, 0.012]} />;
+ }
+}
+
+function Eyewear({ look }: { look: ToyLook }) {
+ if (look.eyewear === "none") return null;
+ const eyeY = HD.y - 0.03;
+ const shades = look.eyewear === "shades";
+ return (
+ <group>
+ {[-1, 1].map((sx) => {
+ const x = sx * 0.1;
+ return (
+ <group key={sx} position={[x, eyeY, faceZ(x, eyeY) + 0.012]} rotation={[0, sx * 0.4, 0]}>
+ <mesh geometry={GEO.lens} material={FRAME} />
+ {shades && <mesh geometry={GEO.sphere} material={SHADES} scale={[0.046, 0.046, 0.006]} />}
+ </group>
+ );
+ })}
+ <mesh geometry={GEO.box} material={FRAME} position={[0, eyeY + 0.012, faceZ(0, eyeY) + 0.01]} scale={[0.06, 0.01, 0.01]} />
+ </group>
+ );
+}
+
type JointRef = MutableRefObject<Group | null>;
function Arm({ side, look, shoulder, elbow }: { side: 1 | -1; look: ToyLook; shoulder: JointRef; elbow: JointRef }) {
const skin = matte(look.skin);
+ // A tee leaves the arms bare; everything else has long sleeves (a vest shows the shirt's).
+ const shirtSleeve = look.outfit === "vest" ? look.inner : look.shirt;
+ const sleeve = look.outfit === "tee" ? null : garment(look, shirtSleeve);
return (
<group ref={shoulder} position={[side * TOY.shoulderX, TOY.shoulderY, 0]}>
- <mesh geometry={GEO.sphere} material={matte(look.shirt)} position={[0, -0.03, 0]} scale={[0.068, 0.078, 0.07]} castShadow />
- <mesh geometry={GEO.upperArm} material={skin} position={[0, -TOY.upperArm / 2, 0]} castShadow />
+ <mesh geometry={GEO.sphere} material={garment(look, shirtSleeve)} position={[0, -0.03, 0]} scale={[0.068, 0.078, 0.07]} castShadow />
+ <mesh geometry={GEO.upperArm} material={sleeve ?? skin} position={[0, -TOY.upperArm / 2, 0]} scale={sleeve ? 1.08 : 1} castShadow />
<group ref={elbow} position={[0, -TOY.upperArm, 0]}>
- <mesh geometry={GEO.foreArm} material={skin} position={[0, -0.06, 0]} castShadow />
+ <mesh geometry={GEO.foreArm} material={sleeve ?? skin} position={[0, -0.06, 0]} scale={sleeve ? 1.1 : 1} castShadow />
+ {CUFFED.has(look.outfit) && (
+ <mesh geometry={GEO.sphere} material={matte(look.inner)} position={[0, -TOY.foreArm + 0.05, 0]} scale={[0.05, 0.016, 0.05]} />
+ )}
<mesh geometry={GEO.sphere} material={skin} position={[0, -TOY.foreArm, 0]} scale={TOY.handRadius} castShadow />
</group>
</group>
@@ -280,14 +469,16 @@ function Arm({ side, look, shoulder, elbow }: { side: 1 | -1; look: ToyLook; sho
function Leg({ side, look, hip, knee, ankle }: { side: 1 | -1; look: ToyLook; hip: JointRef; knee: JointRef; ankle: JointRef }) {
const pants = matte(look.pants);
- const sole = matte(isLight(look.shoes) ? mix(look.shoes, "#9a9aa0", 0.25) : SOLE_LIGHT);
+ // Dress shoes are polished with a dark sole; sneakers keep the light rubber sole.
+ const dress = DRESS_SHOES.has(look.outfit) && !isLight(look.shoes);
+ const sole = matte(dress ? mix(look.shoes, "#000000", 0.45) : isLight(look.shoes) ? mix(look.shoes, "#9a9aa0", 0.25) : SOLE_LIGHT);
return (
<group ref={hip} position={[side * TOY.hipX, TOY.hipUp, 0]}>
<mesh geometry={GEO.thigh} material={pants} position={[0, -TOY.thigh / 2, 0]} castShadow />
<group ref={knee} position={[0, -TOY.thigh, 0]}>
<mesh geometry={GEO.shin} material={pants} position={[0, -TOY.shin / 2 + 0.005, 0]} castShadow />
<group ref={ankle} position={[0, -TOY.shin, 0]}>
- <mesh geometry={GEO.shoe} material={matte(look.shoes, 0.6)} position={[0, -TOY.sole + 0.0425, (TOY.toe - TOY.heel) / 2]} castShadow />
+ <mesh geometry={GEO.shoe} material={matte(look.shoes, dress ? 0.3 : 0.6)} position={[0, -TOY.sole + 0.0425, (TOY.toe - TOY.heel) / 2]} castShadow />
<mesh geometry={GEO.sole} material={sole} position={[0, -TOY.sole + 0.011, (TOY.toe - TOY.heel) / 2]} castShadow />
</group>
</group>
@@ -341,8 +532,6 @@ export function ToyFigure({ look, drive, paused, heightM = TOY_HEIGHT, seatHeigh
settled: false,
}), []);
- const shirtAccent = matte(look.shirtAccent);
-
useFrame((_, rawDt) => {
const s = state;
const dt = Math.min(rawDt, MAX_DT);
@@ -399,15 +588,15 @@ export function ToyFigure({ look, drive, paused, heightM = TOY_HEIGHT, seatHeigh
<Leg side={1} look={look} hip={lHip} knee={lKnee} ankle={lAnkle} />
<Leg side={-1} look={look} hip={rHip} knee={rKnee} ankle={rAnkle} />
<group ref={torso} position={[0, TOY.hipUp, 0]}>
- <mesh geometry={GEO.chest} material={matte(look.shirt)} position={[0, 0.02 + (TOY.torso.h - 0.02) / 2, 0]} castShadow />
- {/* Chest emblem in the accent colour, like the logo on a T-shirt. */}
- <mesh geometry={GEO.sphere} material={shirtAccent} position={[0, 0.16, TOY.torso.d / 2 - 0.004]} scale={[0.05, 0.05, 0.012]} />
+ <mesh geometry={GEO.chest} material={garment(look, look.shirt)} position={[0, 0.02 + (TOY.torso.h - 0.02) / 2, 0]} castShadow />
+ <OutfitDetails look={look} />
<mesh geometry={GEO.lowSphere} material={matte(look.skin)} position={[0, TOY.neckY - 0.01, 0]} scale={[0.07, 0.04, 0.07]} />
<Arm side={1} look={look} shoulder={lShoulder} elbow={lElbow} />
<Arm side={-1} look={look} shoulder={rShoulder} elbow={rElbow} />
<group ref={head} position={[0, TOY.neckY, 0]}>
<mesh geometry={GEO.sphere} material={matte(look.skin)} position={[0, HD.y, 0]} scale={[HD.rx, HD.ry, HD.rz]} castShadow />
<Face look={look} />
+ <Eyewear look={look} />
<Hair style={look.hairStyle} look={look} />
</group>
</group>
diff --git a/jarvis/ui/web/frontend/src/components/society/office/WardrobePanel.tsx b/jarvis/ui/web/frontend/src/components/society/office/WardrobePanel.tsx
new file mode 100644
index 0000000000..af4c15a212
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/WardrobePanel.tsx
@@ -0,0 +1,191 @@
+/**
+ * The wardrobe checkpoint: dress your own character or any agent on foot —
+ * office outfits in curated colourways, hair style and colour, skin tone and
+ * eyewear. Your own look saves in this browser at once; an agent's look is a
+ * draft with a live preview until you save it to the roster (the same
+ * `avatar` PATCH the appearance editor uses).
+ */
+import { lazy, Suspense, useId, useMemo, useState, type ReactNode } from "react";
+import { useQueryClient } from "@tanstack/react-query";
+import { useT } from "@/i18n";
+import type { SocietyAgent } from "../data";
+import type { FigureRecipe } from "../figures/figureRecipe";
+import { playerLook, type PlayerProfile } from "./playerProfile";
+import { EYEWEAR, HAIR_STYLES, toyLookFor, type OutfitId } from "./toyFigureModel";
+import {
+ colourwayIndexOf, dressIn, HAIR_COLOURS, OUTFITS, outfitById, randomLook, SKIN_TONES,
+ withEyewear, withHair, withHairColour, withSkin,
+} from "./wardrobe";
+import "./wardrobe.css";
+
+const AgentFigureViewer = lazy(() => import("../figures/AgentFigureViewer").then((m) => ({ default: m.AgentFigureViewer })));
+
+const YOU = "__you__";
+
+function Section({ label, children }: { label: string; children: ReactNode }) {
+ const id = useId();
+ return (
+ <div className="wardrobe-section">
+ <p className="office-subhead" id={id}>{label}</p>
+ <div className="wardrobe-row" role="group" aria-labelledby={id}>{children}</div>
+ </div>
+ );
+}
+
+function Swatch({ colours, label, pressed, onClick }: { colours: string[]; label: string; pressed: boolean; onClick: () => void }) {
+ const background = colours.length > 1
+ ? `linear-gradient(135deg, ${colours[0]} 0 50%, ${colours[1]} 50% 100%)`
+ : colours[0];
+ return <button type="button" className="wardrobe-swatch" style={{ background }} aria-label={label} title={label} aria-pressed={pressed} onClick={onClick} />;
+}
+
+/** The editor itself: works on any biped recipe and reports every change. */
+function LookEditor({ recipe, onChange }: { recipe: FigureRecipe; onChange: (next: FigureRecipe) => void }) {
+ const t = useT();
+ const look = toyLookFor(recipe, "");
+ const way = colourwayIndexOf(recipe);
+ const outfit = outfitById(look.outfit);
+ const same = (a: string, b: string) => a.toLowerCase() === b.toLowerCase();
+ return (
+ <>
+ <Section label={t("society.office.wardrobe_outfit")}>
+ <div className="wardrobe-outfits">
+ {OUTFITS.map((o) => (
+ <button key={o.id} type="button" className="wardrobe-outfit" aria-pressed={look.outfit === o.id}
+ onClick={() => onChange(dressIn(recipe, o.id as OutfitId, 0))}>
+ <i aria-hidden style={{ background: `linear-gradient(135deg, ${o.colourways[0].primary} 0 55%, ${o.colourways[0].inner} 55% 100%)` }} />
+ {t(`society.office.outfit_${o.id}`)}
+ </button>
+ ))}
+ </div>
+ </Section>
+ <Section label={t("society.office.wardrobe_colourway")}>
+ {outfit.colourways.map((w, i) => (
+ <Swatch key={w.id} colours={[w.primary, w.inner === w.primary ? w.secondary : w.inner]} pressed={way === i}
+ label={t(`society.office.colourway_${w.id}`)} onClick={() => onChange(dressIn(recipe, look.outfit, i))} />
+ ))}
+ </Section>
+ <Section label={t("society.office.hair_label")}>
+ {HAIR_STYLES.map((style) => (
+ <button key={style} type="button" className="office-chip" aria-pressed={look.hairStyle === style} onClick={() => onChange(withHair(recipe, style))}>
+ {t(`society.office.hair_${style}`)}
+ </button>
+ ))}
+ </Section>
+ <Section label={t("society.office.wardrobe_hair_colour")}>
+ {HAIR_COLOURS.map((c, i) => (
+ <Swatch key={c} colours={[c]} pressed={same(look.hair, c)} label={`${t("society.office.wardrobe_hair_colour")} ${i + 1}`}
+ onClick={() => onChange(withHairColour(recipe, c))} />
+ ))}
+ </Section>
+ <Section label={t("society.office.wardrobe_skin")}>
+ {SKIN_TONES.map((c, i) => (
+ <Swatch key={c} colours={[c]} pressed={same(look.skin, c)} label={`${t("society.office.wardrobe_skin")} ${i + 1}`}
+ onClick={() => onChange(withSkin(recipe, c))} />
+ ))}
+ </Section>
+ <Section label={t("society.office.wardrobe_eyewear")}>
+ {EYEWEAR.map((e) => (
+ <button key={e} type="button" className="office-chip" aria-pressed={look.eyewear === e} onClick={() => onChange(withEyewear(recipe, e))}>
+ {t(`society.office.eyewear_${e}`)}
+ </button>
+ ))}
+ </Section>
+ </>
+ );
+}
+
+/** Agents the wardrobe can dress: two-legged figures (Gigi and other spirits fly in their own shape). */
+function dressable(agents: SocietyAgent[]): SocietyAgent[] {
+ return agents.filter((a) => a.figure?.archetype === "biped" && !a.figure.model);
+}
+
+export function WardrobePanel({ profile, onProfile, agents, sample }: {
+ profile: PlayerProfile; onProfile: (next: PlayerProfile) => void; agents: SocietyAgent[]; sample: boolean;
+}) {
+ const t = useT();
+ const client = useQueryClient();
+ const [target, setTarget] = useState<string>(YOU);
+ const [drafts, setDrafts] = useState<Record<string, FigureRecipe>>({});
+ const [saving, setSaving] = useState(false);
+ const [status, setStatus] = useState<"idle" | "saved" | "error">("idle");
+ const people = useMemo(() => dressable(agents), [agents]);
+ const agent = people.find((a) => a.agentId === target) ?? null;
+
+ const playerRecipe: FigureRecipe = { ...profile.recipe, hairStyle: playerLook(profile).hairStyle };
+ const recipe = agent ? drafts[agent.agentId] ?? agent.figure! : playerRecipe;
+ const dirty = agent ? Boolean(drafts[agent.agentId]) && JSON.stringify(drafts[agent.agentId]) !== JSON.stringify(agent.figure) : false;
+
+ const change = (next: FigureRecipe) => {
+ setStatus("idle");
+ // Your own look: saved at once. The legacy profile-level hair moves into the recipe.
+ if (!agent) onProfile({ ...profile, recipe: next, hairStyle: undefined });
+ else setDrafts((d) => ({ ...d, [agent.agentId]: next }));
+ };
+
+ const save = async () => {
+ if (!agent) return;
+ setSaving(true);
+ setStatus("idle");
+ try {
+ const response = await fetch(`/api/society/agents/${encodeURIComponent(agent.agentId)}`, {
+ method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ avatar: recipe }),
+ });
+ if (!response.ok) throw new Error(`wardrobe save ${response.status}`);
+ await Promise.all([client.invalidateQueries({ queryKey: ["society", "roster"] }), client.invalidateQueries({ queryKey: ["mars"] })]);
+ setDrafts((d) => { const { [agent.agentId]: _saved, ...rest } = d; return rest; });
+ setStatus("saved");
+ } catch (error) {
+ // Keep the draft so nothing is lost; the message offers another try.
+ console.warn("Wardrobe could not save the agent's look", error);
+ setStatus("error");
+ } finally {
+ setSaving(false);
+ }
+ };
+
+ return (
+ <>
+ <p>{t("society.office.wardrobe_body")}</p>
+ {people.length > 0 && (
+ <Section label={t("society.office.wardrobe_who")}>
+ <button type="button" className="office-chip" aria-pressed={target === YOU} onClick={() => { setTarget(YOU); setStatus("idle"); }}>
+ {t("society.office.wardrobe_you")}
+ </button>
+ {people.map((a) => (
+ <button key={a.agentId} type="button" className="office-chip" aria-pressed={target === a.agentId} title={a.name}
+ onClick={() => { setTarget(a.agentId); setStatus("idle"); }}>
+ <span className="wardrobe-chip-name">{a.name}</span>
+ </button>
+ ))}
+ </Section>
+ )}
+ {agent ? (
+ <div className="wardrobe-preview">
+ <Suspense fallback={null}><AgentFigureViewer recipe={recipe} quiet /></Suspense>
+ </div>
+ ) : (
+ <label className="office-field">
+ <span>{t("society.office.wardrobe_name")}</span>
+ <input value={profile.name} maxLength={40} placeholder={t("society.office.you")} autoComplete="off" spellCheck={false}
+ onChange={(e) => onProfile({ ...profile, name: e.target.value })} />
+ <span>{t("society.office.wardrobe_saved")}</span>
+ </label>
+ )}
+ <LookEditor recipe={recipe} onChange={change} />
+ <button type="button" className="office-action" onClick={() => change(randomLook(recipe, `${target}:${Math.random()}`))}>
+ {t("society.office.wardrobe_random")}
+ </button>
+ {agent && (
+ <>
+ <button type="button" className="office-action office-action-primary" disabled={!dirty || saving || sample} aria-busy={saving} onClick={() => void save()}>
+ {t(saving ? "society.card.saving" : "society.office.wardrobe_save_agent").replace("{0}", agent.name)}
+ </button>
+ {sample && <p className="office-hint">{t("society.office.wardrobe_sample_hint")}</p>}
+ {status === "saved" && <p className="office-success" role="status">{t("society.office.wardrobe_saved_agent").replace("{0}", agent.name)}</p>}
+ {status === "error" && <p className="office-error" role="alert">{t("society.office.wardrobe_save_error")}</p>}
+ </>
+ )}
+ </>
+ );
+}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/playerProfile.ts b/jarvis/ui/web/frontend/src/components/society/office/playerProfile.ts
index a82e4a7a85..a6b5a3fe2e 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/playerProfile.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/playerProfile.ts
@@ -6,8 +6,8 @@
* a missing or blocked storage and falls back to the default look.
*/
import { CATALOG } from "../figures/figureRegistry";
-import { shufflePalette, type FigureRecipe } from "../figures/figureRecipe";
-import { toyLookFor, type HairStyle, type ToyLook } from "./toyFigureModel";
+import type { FigureRecipe } from "../figures/figureRecipe";
+import { HAIR_STYLES, toyLookFor, type HairStyle, type ToyLook } from "./toyFigureModel";
const STORAGE_KEY = "jarvis.office.player.v1";
@@ -18,7 +18,7 @@ export interface PlayerProfile {
hairStyle?: HairStyle;
}
-export const HAIR_STYLES: readonly HairStyle[] = ["short", "spiky", "bun", "curly", "long", "beanie", "cap", "bald"];
+export { HAIR_STYLES };
/** The look the office draws for the person. */
export function playerLook(profile: PlayerProfile): ToyLook {
@@ -26,10 +26,6 @@ export function playerLook(profile: PlayerProfile): ToyLook {
return profile.hairStyle ? { ...look, hairStyle: profile.hairStyle } : look;
}
-export function withHairStyle(profile: PlayerProfile, hairStyle: HairStyle): PlayerProfile {
- return { ...profile, hairStyle };
-}
-
/** Bodies offered in the wardrobe: two-legged, first-party, not reserved. */
export const WARDROBE_BASES: readonly string[] = CATALOG.bases
.filter((b) => b.archetype === "biped" && !b.styles.includes("custom"))
@@ -78,7 +74,3 @@ export function saveProfile(profile: PlayerProfile): void {
export function withBase(profile: PlayerProfile, base: string): PlayerProfile {
return { ...profile, recipe: { ...profile.recipe, base, parts: {} } };
}
-
-export function withShuffledColours(profile: PlayerProfile, seed = Math.random()): PlayerProfile {
- return { ...profile, recipe: { ...profile.recipe, palette: shufflePalette(seed) } };
-}
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 824b734929..33f8386fb0 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/toyFigureModel.ts
+++ b/jarvis/ui/web/frontend/src/components/society/office/toyFigureModel.ts
@@ -23,17 +23,37 @@ import type { FigureMode } from "../figures/FigureRig";
// ---------------------------------------------------------------------------
// Look
-export type HairStyle = "short" | "spiky" | "bun" | "curly" | "long" | "beanie" | "cap" | "bald";
+export type HairStyle =
+ | "short" | "spiky" | "bun" | "curly" | "long" | "beanie" | "cap" | "bald"
+ | "slick" | "sidepart" | "buzz" | "ponytail";
+
+/**
+ * What the figure wears on its upper body. "tee" is the original casual look
+ * and the default for every recipe that names no outfit.
+ */
+export type OutfitId = "tee" | "hoodie" | "suit" | "leather" | "vest" | "turtleneck" | "blazer" | "quarterzip";
+
+export const OUTFIT_IDS: readonly OutfitId[] = ["tee", "hoodie", "suit", "leather", "vest", "turtleneck", "blazer", "quarterzip"];
+
+export type Eyewear = "none" | "glasses" | "shades";
+
+export const EYEWEAR: readonly Eyewear[] = ["none", "glasses", "shades"];
export interface ToyLook {
skin: string;
hair: string;
hairStyle: HairStyle;
+ /** The main upper-body garment: tee, hoodie, jacket, vest or knit. */
shirt: string;
+ /** Emblem, tie, drawstrings or pocket square, depending on the outfit. */
shirtAccent: string;
+ /** The shirt worn under a jacket or vest (collar, V-opening, sleeves under a vest). */
+ inner: string;
pants: string;
shoes: string;
blush: boolean;
+ outfit: OutfitId;
+ eyewear: Eyewear;
}
/** Natural skin tones, light to dark; the fallback and the snap target for fantasy skins. */
@@ -115,12 +135,30 @@ 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.
*/
+/** Every hair style the figure can draw; the hash wheel above only picks from the original eight. */
+export const HAIR_STYLES: readonly HairStyle[] = [
+ "short", "slick", "sidepart", "buzz", "spiky", "curly", "long", "ponytail", "bun", "beanie", "cap", "bald",
+];
+
/** 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;
+ return typeof value === "string" && (HAIR_STYLES as readonly string[]).includes(value) ? (value as HairStyle) : null;
+}
+
+function chosenOutfit(recipe: FigureRecipe | null): OutfitId {
+ const value = recipe?.outfit;
+ return typeof value === "string" && (OUTFIT_IDS as readonly string[]).includes(value) ? (value as OutfitId) : "tee";
}
+function chosenEyewear(recipe: FigureRecipe | null): Eyewear {
+ const value = recipe?.eyewear;
+ return typeof value === "string" && (EYEWEAR as readonly string[]).includes(value) ? (value as Eyewear) : "none";
+}
+
+/** The shirt under a jacket when the recipe names none: a crisp white. */
+const DEFAULT_INNER = "#f2f2ee";
+
/**
* 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
@@ -134,12 +172,15 @@ export function toyLookFor(recipe: FigureRecipe | null, identity: string): ToyLo
return {
skin,
hair: validColour(palette.hair) ?? pick(HAIR_COLOURS, hash, 0x7a),
- hairStyle: chosenHair(recipe) ?? pick(HAIR_STYLE_WHEEL, recipe ? hashString(recipeKey({ ...recipe, hairStyle: undefined })) : hash, 0x3c),
+ hairStyle: chosenHair(recipe) ?? pick(HAIR_STYLE_WHEEL, recipe ? hashString(recipeKey({ ...recipe, hairStyle: undefined, outfit: undefined, inner: undefined, eyewear: 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),
+ inner: validColour(recipe?.inner) ?? DEFAULT_INNER,
shoes: validColour(palette.shoes) ?? DEFAULT_SHOES,
blush: (hash & 0x3) !== 0,
+ outfit: chosenOutfit(recipe),
+ eyewear: chosenEyewear(recipe),
};
}
diff --git a/jarvis/ui/web/frontend/src/components/society/office/wardrobe.css b/jarvis/ui/web/frontend/src/components/society/office/wardrobe.css
new file mode 100644
index 0000000000..d1dff86bf3
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/wardrobe.css
@@ -0,0 +1,13 @@
+/* Wardrobe panel: theme tokens only, so light and dark mode both work. Swatches show real garment colours. */
+.wardrobe-section { display:flex; flex-direction:column; gap:5px; }
+.wardrobe-row { display:flex; flex-wrap:wrap; gap:5px; }
+.wardrobe-outfits { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:5px; width:100%; }
+.wardrobe-outfit { display:flex; align-items:center; gap:7px; min-width:0; border:1px solid hsl(var(--border)); border-radius:9px; padding:5px 8px; background:hsl(var(--background)); color:hsl(var(--foreground)); font-size:11px; text-align:left; cursor:pointer; }
+.wardrobe-outfit i { flex:none; width:16px; height:16px; border-radius:5px; box-shadow:inset 0 0 0 1px hsl(var(--foreground) / .18); }
+.wardrobe-outfit:hover:not([aria-pressed="true"]) { background:hsl(var(--secondary)); }
+.wardrobe-outfit[aria-pressed="true"] { border-color:hsl(var(--ring)); background:hsl(var(--secondary)); font-weight:600; }
+.wardrobe-swatch { width:22px; height:22px; border-radius:999px; border:0; padding:0; cursor:pointer; box-shadow:inset 0 0 0 1px hsl(var(--foreground) / .2); }
+.wardrobe-swatch[aria-pressed="true"] { outline:2px solid hsl(var(--ring)); outline-offset:2px; }
+.wardrobe-outfit:focus-visible, .wardrobe-swatch:focus-visible { outline:2px solid hsl(var(--ring)); outline-offset:2px; }
+.wardrobe-chip-name { display:inline-block; max-width:110px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; vertical-align:bottom; }
+.wardrobe-preview { height:240px; flex:none; border-radius:10px; background:hsl(var(--secondary) / .6); overflow:hidden; }
diff --git a/jarvis/ui/web/frontend/src/components/society/office/wardrobe.test.ts b/jarvis/ui/web/frontend/src/components/society/office/wardrobe.test.ts
new file mode 100644
index 0000000000..d267b3145f
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/wardrobe.test.ts
@@ -0,0 +1,59 @@
+import { describe, expect, it } from "vitest";
+
+import { recipeKey, type FigureRecipe } from "../figures/figureRecipe";
+import { HAIR_STYLES, OUTFIT_IDS, toyLookFor } from "./toyFigureModel";
+import { colourwayIndexOf, dressIn, OUTFITS, randomLook, withEyewear, withHairColour, withSkin } from "./wardrobe";
+
+const BASE: FigureRecipe = { contract: 1, archetype: "biped", base: "toon", parts: {}, palette: { primary: "#3f9d5a", secondary: "#2b4a8b" } };
+const HEX = /^#[0-9a-f]{6}$/i;
+
+describe("wardrobe catalogue", () => {
+ it("offers every outfit the figure can draw, each with valid colourways", () => {
+ expect(OUTFITS.map((o) => o.id).sort()).toEqual([...OUTFIT_IDS].sort());
+ for (const outfit of OUTFITS) {
+ expect(outfit.colourways.length).toBeGreaterThan(0);
+ for (const way of outfit.colourways) for (const c of [way.primary, way.secondary, way.accent, way.inner, way.shoes]) expect(c).toMatch(HEX);
+ }
+ });
+
+ it("has the signature black leather jacket", () => {
+ const look = toyLookFor(dressIn(BASE, "leather"), "x");
+ expect(look.outfit).toBe("leather");
+ expect(look.shirt).toBe("#131316");
+ });
+});
+
+describe("dressing a recipe", () => {
+ it("applies the colourway to the look and recognises it again", () => {
+ const suit = dressIn(BASE, "suit", 1);
+ const look = toyLookFor(suit, "x");
+ const navy = OUTFITS.find((o) => o.id === "suit")!.colourways[1];
+ expect(look).toMatchObject({ outfit: "suit", shirt: navy.primary, pants: navy.secondary, shirtAccent: navy.accent, inner: navy.inner, shoes: navy.shoes });
+ expect(colourwayIndexOf(suit)).toBe(1);
+ });
+
+ it("keeps the hair when the colours change", () => {
+ const hair = toyLookFor(BASE, "").hairStyle;
+ for (const outfit of OUTFIT_IDS) expect(toyLookFor(dressIn(BASE, outfit, 2), "").hairStyle).toBe(hair);
+ expect(toyLookFor(withSkin(BASE, "#8a5a3c"), "").hairStyle).toBe(hair);
+ expect(toyLookFor(withHairColour(BASE, "#d9b36c"), "").hairStyle).toBe(hair);
+ });
+
+ it("reads eyewear and falls back safely on unknown values", () => {
+ expect(toyLookFor(withEyewear(BASE, "shades"), "").eyewear).toBe("shades");
+ expect(toyLookFor({ ...BASE, eyewear: "monocle", outfit: "cape" }, "")).toMatchObject({ eyewear: "none", outfit: "tee" });
+ });
+
+ it("produces complete random looks from the catalogue", () => {
+ for (let i = 0; i < 30; i += 1) {
+ const look = toyLookFor(randomLook(BASE, `seed-${i}`), "");
+ expect(OUTFIT_IDS).toContain(look.outfit);
+ expect(HAIR_STYLES).toContain(look.hairStyle);
+ }
+ });
+
+ it("leaves the key of an undressed recipe unchanged", () => {
+ expect(recipeKey(BASE).endsWith("|")).toBe(true);
+ expect(recipeKey(dressIn(BASE, "suit"))).not.toBe(recipeKey(BASE));
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/society/office/wardrobe.ts b/jarvis/ui/web/frontend/src/components/society/office/wardrobe.ts
new file mode 100644
index 0000000000..6c1e227874
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/society/office/wardrobe.ts
@@ -0,0 +1,159 @@
+/**
+ * The wardrobe catalogue: office outfits with curated colourways, hair and
+ * skin swatches, and the pure recipe edits the wardrobe panel applies.
+ *
+ * An outfit's colours live in the recipe itself (palette primary = main
+ * garment, secondary = trousers, accent = tie / trim, shoes; `inner` = the
+ * shirt under a jacket), so a dressed figure looks the same in the office,
+ * the creator preview and the appearance editor.
+ */
+import type { FigureRecipe } from "../figures/figureRecipe";
+import { hashString, SKIN_TONES, toyLookFor, type Eyewear, type HairStyle, type OutfitId } from "./toyFigureModel";
+
+export interface Colourway {
+ /** Stable id, also the i18n key suffix (`society.office.colourway_<id>`). */
+ id: string;
+ primary: string;
+ secondary: string;
+ accent: string;
+ inner: string;
+ shoes: string;
+}
+
+export interface Outfit {
+ id: OutfitId;
+ colourways: readonly Colourway[];
+}
+
+/** The office outfits, casual to formal; the first colourway is the signature one. */
+export const OUTFITS: readonly Outfit[] = [
+ {
+ id: "leather",
+ colourways: [
+ { id: "black", primary: "#131316", secondary: "#1d2029", accent: "#9aa0a8", inner: "#1b1b1e", shoes: "#101012" },
+ { id: "cognac", primary: "#5c3622", secondary: "#2a3346", accent: "#c9a227", inner: "#efe8dc", shoes: "#3b2418" },
+ { id: "oxblood", primary: "#4a1a1f", secondary: "#1d2029", accent: "#9aa0a8", inner: "#1b1b1e", shoes: "#101012" },
+ ],
+ },
+ {
+ id: "suit",
+ colourways: [
+ { id: "charcoal", primary: "#3a3d44", secondary: "#3a3d44", accent: "#8b1e2d", inner: "#f4f4f0", shoes: "#1a1414" },
+ { id: "navy", primary: "#1f2a44", secondary: "#1f2a44", accent: "#c9a227", inner: "#eaf1fb", shoes: "#3b2418" },
+ { id: "tuxedo", primary: "#141418", secondary: "#141418", accent: "#141418", inner: "#ffffff", shoes: "#0d0d0d" },
+ { id: "linen", primary: "#cbb795", secondary: "#cbb795", accent: "#2f4a7a", inner: "#ffffff", shoes: "#6b4226" },
+ ],
+ },
+ {
+ id: "blazer",
+ colourways: [
+ { id: "old_money", primary: "#23304f", secondary: "#dccfb3", accent: "#b8943e", inner: "#f2efe6", shoes: "#6b4226" },
+ { id: "camel", primary: "#b08a5a", secondary: "#3b3f4a", accent: "#f2efe6", inner: "#ffffff", shoes: "#2a1d15" },
+ { id: "forest", primary: "#2f4a3a", secondary: "#e3dccb", accent: "#c9a227", inner: "#f2efe6", shoes: "#4a2e22" },
+ ],
+ },
+ {
+ id: "quarterzip",
+ colourways: [
+ { id: "oat", primary: "#d8cbb4", secondary: "#3b3f4a", accent: "#c7c9cc", inner: "#ffffff", shoes: "#f4f4f2" },
+ { id: "navy", primary: "#1f2a44", secondary: "#c8b28e", accent: "#c7c9cc", inner: "#cfe0f5", shoes: "#3b2418" },
+ { id: "forest", primary: "#2f4a3a", secondary: "#e3dccb", accent: "#c7c9cc", inner: "#ffffff", shoes: "#f4f4f2" },
+ ],
+ },
+ {
+ id: "vest",
+ colourways: [
+ { id: "navy", primary: "#1f2a44", secondary: "#b9a27f", accent: "#e5674f", inner: "#cfe0f5", shoes: "#3b2418" },
+ { id: "charcoal", primary: "#3b3f4a", secondary: "#2b2f38", accent: "#6fbf5a", inner: "#ffffff", shoes: "#f4f4f2" },
+ { id: "black", primary: "#18181c", secondary: "#c8b28e", accent: "#f2c14e", inner: "#eaf1fb", shoes: "#2a1d15" },
+ ],
+ },
+ {
+ id: "turtleneck",
+ colourways: [
+ { id: "black", primary: "#141416", secondary: "#3d5a80", accent: "#141416", inner: "#141416", shoes: "#9a9aa0" },
+ { id: "camel", primary: "#b08a5a", secondary: "#2b2b33", accent: "#b08a5a", inner: "#b08a5a", shoes: "#3b2418" },
+ { id: "cream", primary: "#eee6d6", secondary: "#3b3f4a", accent: "#eee6d6", inner: "#eee6d6", shoes: "#2a1d15" },
+ ],
+ },
+ {
+ id: "hoodie",
+ colourways: [
+ { id: "grey", primary: "#8a8d93", secondary: "#2b2f38", accent: "#f2f2ee", inner: "#f2f2ee", shoes: "#f4f4f2" },
+ { id: "black", primary: "#1c1c20", secondary: "#1c1c20", accent: "#d9d9d9", inner: "#1c1c20", shoes: "#f4f4f2" },
+ { id: "navy", primary: "#23304f", secondary: "#8a8d93", accent: "#f2f2ee", inner: "#23304f", shoes: "#f4f4f2" },
+ { id: "sage", primary: "#8fa58a", secondary: "#e3dccb", accent: "#f2f2ee", inner: "#8fa58a", shoes: "#f4f4f2" },
+ ],
+ },
+ {
+ id: "tee",
+ colourways: [
+ { id: "white", primary: "#f2f2ee", secondary: "#3d5a80", accent: "#2b2b33", inner: "#f2f2ee", shoes: "#f4f4f2" },
+ { id: "black", primary: "#1c1c20", secondary: "#2b2f38", accent: "#f2f2ee", inner: "#1c1c20", shoes: "#f4f4f2" },
+ { id: "green", primary: "#3f9d5a", secondary: "#2b4a8b", accent: "#f2c14e", inner: "#3f9d5a", shoes: "#f2f2ee" },
+ { id: "coral", primary: "#e5674f", secondary: "#2b2f38", accent: "#f2f2ee", inner: "#e5674f", shoes: "#f4f4f2" },
+ ],
+ },
+];
+
+export const HAIR_COLOURS = ["#1d1d24", "#2a1d15", "#4a3020", "#6b4226", "#9e5d47", "#c0392b", "#d9b36c", "#e8dcc0", "#8a8d93", "#d6d6d6"] as const;
+
+export { SKIN_TONES };
+
+export function outfitById(id: OutfitId): Outfit {
+ return OUTFITS.find((o) => o.id === id) ?? OUTFITS[OUTFITS.length - 1];
+}
+
+/**
+ * Dress a recipe in an outfit and one of its colourways. The current hair is
+ * pinned explicitly, because a hair style derived from the palette would
+ * otherwise change with the new colours.
+ */
+export function dressIn(recipe: FigureRecipe, outfit: OutfitId, colourwayIndex = 0): FigureRecipe {
+ const look = toyLookFor(recipe, "");
+ const ways = outfitById(outfit).colourways;
+ const way = ways[((colourwayIndex % ways.length) + ways.length) % ways.length];
+ return {
+ ...recipe,
+ outfit,
+ inner: way.inner,
+ hairStyle: look.hairStyle,
+ palette: { ...recipe.palette, primary: way.primary, secondary: way.secondary, accent: way.accent, shoes: way.shoes },
+ };
+}
+
+/** The colourway index the recipe currently wears, or -1 after a manual colour change. */
+export function colourwayIndexOf(recipe: FigureRecipe): number {
+ const look = toyLookFor(recipe, "");
+ const same = (a: string, b: string) => a.toLowerCase() === b.toLowerCase();
+ return outfitById(look.outfit).colourways.findIndex((w) =>
+ same(w.primary, look.shirt) && same(w.secondary, look.pants) && same(w.accent, look.shirtAccent)
+ && same(w.inner, look.inner) && same(w.shoes, look.shoes));
+}
+
+export function withHair(recipe: FigureRecipe, hairStyle: HairStyle): FigureRecipe {
+ return { ...recipe, hairStyle };
+}
+
+export function withHairColour(recipe: FigureRecipe, hair: string): FigureRecipe {
+ return { ...recipe, hairStyle: toyLookFor(recipe, "").hairStyle, palette: { ...recipe.palette, hair } };
+}
+
+export function withSkin(recipe: FigureRecipe, skin: string): FigureRecipe {
+ return { ...recipe, hairStyle: toyLookFor(recipe, "").hairStyle, palette: { ...recipe.palette, skin } };
+}
+
+export function withEyewear(recipe: FigureRecipe, eyewear: Eyewear): FigureRecipe {
+ return { ...recipe, eyewear };
+}
+
+/** A complete random office look: outfit, colourway, hair, hair colour and eyewear. */
+export function randomLook(recipe: FigureRecipe, seed: string): FigureRecipe {
+ const h = hashString(seed);
+ const at = <T,>(list: readonly T[], salt: number): T => list[(Math.imul(h ^ salt, 0x9e3779b1) >>> 0) % list.length];
+ const outfit = at(OUTFITS, 0x11);
+ const hairStyles: readonly HairStyle[] = ["short", "slick", "sidepart", "buzz", "curly", "long", "ponytail", "bun", "spiky"];
+ const dressed = dressIn(recipe, outfit.id, (h >>> 8) % outfit.colourways.length);
+ const eyewear = at<Eyewear>(["none", "none", "none", "glasses", "shades"], 0x33);
+ return { ...dressed, hairStyle: at(hairStyles, 0x22), eyewear, palette: { ...dressed.palette, hair: at(HAIR_COLOURS, 0x44) } };
+}