import test from "node:test"; import assert from "node:assert/strict"; import { npcDefaultEquipment, npcClothDyeFromSeed, NPC_CLOTH_DYE_BYTE_MIN } from "../../shared/appearance/npcEquipment.js"; import { layersFromSpawnerConfig } from "../../shared/appearance/layers.js"; import { ItemId } from "../../shared/definitions/items.js"; import { JewelryItemId } from "../../shared/definitions/jewelryItems.js"; import { LeatherItemId } from "../../shared/definitions/leatherItems.js"; import { clothTierForItemId } from "../../shared/definitions/clothItems.js"; import { itemDefinition } from "../../shared/definitions/items.js"; import { mobComponents } from "../src/simulation/spawners.js"; import { MobId } from "../../shared/definitions/mobs.js"; test("npcDefaultEquipment picks deterministic garments from display name", () => { const a = npcDefaultEquipment("Ada Lovelace", "female"); const b = npcDefaultEquipment("Ada Lovelace", "female"); assert.deepEqual(a, b); assert.ok(a.chest?.itemId); assert.ok(clothTierForItemId(a.legs?.itemId)); const legsKey = itemDefinition(a.legs.itemId)?.key ?? ""; assert.ok(legsKey.endsWith("-shorts") || legsKey.endsWith("-skirt") || legsKey.endsWith("-trousers")); assert.equal(a.boots?.itemId, LeatherItemId.leatherShoes); assert.ok(a.chest.dyeColor); assert.ok(a.legs.dyeColor); }); test("npc cloth dyes stay above minimum channel", () => { const dye = npcClothDyeFromSeed("Test NPC", 3); const min = NPC_CLOTH_DYE_BYTE_MIN / 255; assert.ok(dye.r >= min); assert.ok(dye.g >= min); assert.ok(dye.b >= min); }); test("humanoid spawner without equipment gets default clothing", () => { const components = mobComponents({ mobTypeId: MobId.humanoid, tileX: 8, tileY: 8, displayName: "Village Guard", sex: "male", equipment: {}, spawnerId: "test" }); const slots = components.equipment?.slots ?? {}; assert.ok(slots.chest?.itemId); assert.ok(slots.legs?.itemId); assert.equal(slots.boots?.itemId, LeatherItemId.leatherShoes); assert.equal(slots.chest?.instance?.kind, "clothing"); assert.equal(slots.legs?.instance?.kind, "clothing"); }); test("authored spawner jewelry equips on humanoid NPCs", () => { const components = mobComponents({ mobTypeId: MobId.humanoid, tileX: 8, tileY: 8, displayName: "Jeweler", sex: "female", equipment: { ring: JewelryItemId.opalRing, amulet: JewelryItemId.rubyAmulet }, spawnerId: "test" }); assert.equal(components.equipment.slots.ring.itemId, JewelryItemId.opalRing); assert.equal(components.equipment.slots.amulet.itemId, JewelryItemId.rubyAmulet); }); test("layersFromSpawnerConfig previews body gear for humanoid NPCs only", () => { assert.equal(layersFromSpawnerConfig({ mobTypeId: MobId.deer }), null); const layers = layersFromSpawnerConfig({ mobTypeId: MobId.humanoid, displayName: "Preview Bob", sex: "male", equipment: { weapon: { itemId: ItemId.stick } } }); assert.ok(layers?.length >= 2); assert.match(layers[0].sprite, /player-body-male/); assert.ok(layers.some((layer) => layer.itemId === ItemId.stick)); assert.ok(layers.some((layer) => layer.itemId === LeatherItemId.leatherShoes)); });