Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea/people: a role's headwear drawn per person by weight on its own fork, so everything else draws as before

shinyobjectz7c83b42fbb59
diff --git a/sdk/character/src/people/persona.ts b/sdk/character/src/people/persona.ts
index 383127d5..de93f217 100644
--- a/sdk/character/src/people/persona.ts
+++ b/sdk/character/src/people/persona.ts
@@ -90,11 +90,13 @@ export function makePerson(id: string, role: Role, folk: Folk, home: Place, seed
const [hm, hsd] = (folk.heights ?? DEFAULT_HEIGHT)[sex];
const body: Body = { height: Math.round(r.normal(hm, hsd) * 100) / 100, build: Math.round(build * 10) / 10 };
const dress = r.weighted(role.dress);
+ // (on its own fork, so a role given headwear draws everything else as it did)
+ const head = role.head ? r.fork("head").weighted(role.head) : "none";
const carry = Object.entries(role.carry ?? {}).filter(([k, p]) => r.fork(`carry-${k}`).chance(p)).map(([k]) => k);
const modes: Partial<Record<Mode, number>> = role.modes ?? { walk: 1 };
return {
id, name, sex, age, role: role.id, ...(role.rank ? { rank: role.rank } : {}), home: home.id, ...(work ? { work: work.id } : {}),
- traits, habits, face, body, hair: { style, colour, grey: Math.round(grey * 100) / 100 }, dress, carry, modes,
+ traits, habits, face, body, hair: { style, colour, grey: Math.round(grey * 100) / 100 }, dress, ...(head === "none" ? {} : { head }), carry, modes,
gait: gaitOf(role, age, traits, r.fork("gait")), seed,
};
}
diff --git a/sdk/character/src/people/types.ts b/sdk/character/src/people/types.ts
index 308da278..52e1754b 100644
--- a/sdk/character/src/people/types.ts
+++ b/sdk/character/src/people/types.ts
@@ -91,6 +91,9 @@ export interface Role {
rank?: string;
/** the dress, by the project's kit ids: one is drawn per person, as likely as its weight */
dress: Record<string, number>;
+ /** what they wear on the head, by the project's kit ids, drawn like the dress; a weight under "none" leaves some
+ * bareheaded, and a role without it draws none */
+ head?: Record<string, number>;
/** what they carry, by the project's thing ids, each with its chance */
carry?: Record<string, number>;
/** how they get about, by weight (walk unless said) */
@@ -156,6 +159,8 @@ export interface Person {
body: Body;
hair: { style: string; colour: string; grey: number };
dress: string;
+ /** the kit id worn on the head, when the role draws one */
+ head?: string;
carry: string[];
modes: Partial<Record<Mode, number>>;
gait: string;
diff --git a/sdk/character/test/people.test.ts b/sdk/character/test/people.test.ts
index fc86bd7d..f7d29502 100644
--- a/sdk/character/test/people.test.ts
+++ b/sdk/character/test/people.test.ts
@@ -53,6 +53,19 @@ test("a role's sex, ages, rank and gait hold for everyone drawn from it", () =>
expect(new Set(ps.map((p) => (p.face.kind === "crowd" ? p.face.seed : 0))).size).toBe(ps.length);
});
+test("headwear is drawn by the role's weights, and giving a role headwear draws everything else as before", () => {
+ const capped = roles.map((r) => (r.id === "sentry" ? { ...r, head: { "landsturm-cap": 2, feldmuetze: 1 } } : r.id === "housewife" ? { ...r, head: { headscarf: 1, none: 1 } } : r));
+ const a = populate({ roles, places, folk, mix, seed: 3 }), b = populate({ roles: capped, places, folk, mix, seed: 3 });
+ expect(b.map(({ head: _, ...p }) => p)).toEqual(a);
+ expect(a.every((p) => p.head === undefined)).toBe(true);
+ const sentries = b.filter((p) => p.role === "sentry"), wives = b.filter((p) => p.role === "housewife");
+ expect(sentries.every((p) => p.head === "landsturm-cap" || p.head === "feldmuetze")).toBe(true);
+ // "none" leaves some bareheaded, about as often as its weight says
+ const bare = wives.filter((p) => p.head === undefined).length / wives.length;
+ expect(bare).toBeGreaterThan(0.3); expect(bare).toBeLessThan(0.7);
+ expect(b.filter((p) => p.role === "munitions-worker").every((p) => p.head === undefined)).toBe(true);
+});
+
test("a day covers 00:00 to 24:00 with no gaps, and a trip joins every change of place", () => {
const ps = populate({ roles, places, folk, mix, seed: 5 });
const d = cityDay(ps, roles, places, { key: "1917-12-03", weekday: 1 });