| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { npcDefaultEquipment, npcClothDyeFromSeed, NPC_CLOTH_DYE_BYTE_MIN } from "../../shared/appearance/npcEquipment.js"; |
| 4 | import { ItemId } from "../../shared/definitions/items.js"; |
| 5 | import { LeatherItemId } from "../../shared/definitions/leatherItems.js"; |
| 6 | import { mobComponents } from "../src/simulation/spawners.js"; |
| 7 | import { MobId } from "../../shared/definitions/mobs.js"; |
| 8 | |
| 9 | test("npcDefaultEquipment picks deterministic garments from display name", () => |
| 10 | { |
| 11 | const a = npcDefaultEquipment("Ada Lovelace", "female"); |
| 12 | const b = npcDefaultEquipment("Ada Lovelace", "female"); |
| 13 | assert.deepEqual(a, b); |
| 14 | assert.ok(a.chest?.itemId); |
| 15 | assert.ok([LeatherItemId.clothShorts, LeatherItemId.clothTrousers].includes(a.legs?.itemId)); |
| 16 | assert.equal(a.boots?.itemId, LeatherItemId.leatherShoes); |
| 17 | assert.ok(a.chest.dyeColor); |
| 18 | assert.ok(a.legs.dyeColor); |
| 19 | }); |
| 20 | |
| 21 | test("npc cloth dyes stay above minimum channel", () => |
| 22 | { |
| 23 | const dye = npcClothDyeFromSeed("Test NPC", 3); |
| 24 | const min = NPC_CLOTH_DYE_BYTE_MIN / 255; |
| 25 | assert.ok(dye.r >= min); |
| 26 | assert.ok(dye.g >= min); |
| 27 | assert.ok(dye.b >= min); |
| 28 | }); |
| 29 | |
| 30 | test("humanoid spawner without equipment gets default clothing", () => |
| 31 | { |
| 32 | const components = mobComponents({ |
| 33 | mobTypeId: MobId.humanoid, |
| 34 | tileX: 8, |
| 35 | tileY: 8, |
| 36 | displayName: "Village Guard", |
| 37 | sex: "male", |
| 38 | equipment: {}, |
| 39 | spawnerId: "test" |
| 40 | }); |
| 41 | const slots = components.equipment?.slots ?? {}; |
| 42 | assert.ok(slots.chest?.itemId); |
| 43 | assert.ok(slots.legs?.itemId); |
| 44 | assert.equal(slots.boots?.itemId, LeatherItemId.leatherShoes); |
| 45 | assert.equal(slots.chest?.instance?.kind, "clothing"); |
| 46 | assert.equal(slots.legs?.instance?.kind, "clothing"); |
| 47 | }); |
| 48 | |
| 49 | test("authored spawner chest overrides default clothing", () => |
| 50 | { |
| 51 | const components = mobComponents({ |
| 52 | mobTypeId: MobId.humanoid, |
| 53 | tileX: 8, |
| 54 | tileY: 8, |
| 55 | displayName: "Tailor", |
| 56 | sex: "female", |
| 57 | equipment: { chest: ItemId.clothShirt }, |
| 58 | spawnerId: "test" |
| 59 | }); |
| 60 | assert.equal(components.equipment.slots.chest.itemId, ItemId.clothShirt); |
| 61 | assert.equal(components.equipment.slots.chest.instance, undefined); |
| 62 | }); |