/** * Character-creation clothing: cotton shirt + chosen cotton legs, with HSL dyes. * Applied on top of world-editor starter equipment (chest/legs overwrite). */ import { ClothTier } from "../definitions/materialTiers.js"; import { shirtItemId, shortsItemId, skirtItemId, trousersItemId } from "../definitions/clothItems.js"; import { normalizeHairSliders, hairColorFromSliders, DEFAULT_HAIR_HUE, DEFAULT_HAIR_SATURATION, DEFAULT_HAIR_DARKNESS } from "../appearance/hair.js"; import { EQUIPMENT_SLOT } from "../definitions/items.js"; import { emptyEquipment } from "./inventory.js"; import { godsOrigin, attachOrigins } from "./origin.js"; export const CreationLegsKind = Object.freeze({ shorts: "shorts", skirt: "skirt", trousers: "trousers" }); export const CREATION_LEGS_KINDS = Object.freeze([ CreationLegsKind.shorts, CreationLegsKind.skirt, CreationLegsKind.trousers ]); const LEGS_ITEM_ID = Object.freeze({ [CreationLegsKind.shorts]: () => shortsItemId(ClothTier.cotton), [CreationLegsKind.skirt]: () => skirtItemId(ClothTier.cotton), [CreationLegsKind.trousers]: () => trousersItemId(ClothTier.cotton) }); export function defaultCreateClothing () { return Object.freeze({ legsKind: CreationLegsKind.trousers, shirt: Object.freeze({ hue: DEFAULT_HAIR_HUE, saturation: DEFAULT_HAIR_SATURATION, darkness: DEFAULT_HAIR_DARKNESS }), legs: Object.freeze({ hue: 210, saturation: DEFAULT_HAIR_SATURATION, darkness: DEFAULT_HAIR_DARKNESS }) }); } function normalizePieceSliders (raw) { return normalizeHairSliders(raw ?? {}); } /** * @returns {{ legsKind: string, shirt: object, legs: object }} */ export function normalizeCreateClothing (raw) { const defaults = defaultCreateClothing(); const legsKind = CREATION_LEGS_KINDS.includes(raw?.legsKind) ? raw.legsKind : defaults.legsKind; return { legsKind, shirt: normalizePieceSliders(raw?.shirt), legs: normalizePieceSliders(raw?.legs) }; } export function creationLegsItemId (legsKind) { const resolve = LEGS_ITEM_ID[legsKind] ?? LEGS_ITEM_ID[CreationLegsKind.trousers]; return resolve(); } export function creationShirtItemId () { return shirtItemId(ClothTier.cotton); } function dyedClothingStack (itemId, sliders, origin) { const dyeColor = hairColorFromSliders(sliders); return attachOrigins({ itemId, quantity: 1, instance: Object.freeze({ kind: "clothing", dyeColor }), origins: [{ origin, quantity: 1 }] }); } /** * Build a preview bag (equipment only) for the creation clothing UI. */ export function creationClothingPreviewBag (clothingInput) { const clothing = normalizeCreateClothing(clothingInput); const origin = godsOrigin(); const equipment = emptyEquipment(); equipment.slots[EQUIPMENT_SLOT.chest] = dyedClothingStack( creationShirtItemId(), clothing.shirt, origin ); equipment.slots[EQUIPMENT_SLOT.legs] = dyedClothingStack( creationLegsItemId(clothing.legsKind), clothing.legs, origin ); return { equipment }; } /** * Overlay creation clothing onto an existing starter equipment object (mutates slots). */ export function applyCreationClothingToEquipment (equipment, clothingInput) { const clothing = normalizeCreateClothing(clothingInput); const origin = godsOrigin(); const slots = equipment?.slots ?? emptyEquipment().slots; slots[EQUIPMENT_SLOT.chest] = dyedClothingStack( creationShirtItemId(), clothing.shirt, origin ); slots[EQUIPMENT_SLOT.legs] = dyedClothingStack( creationLegsItemId(clothing.legsKind), clothing.legs, origin ); return equipment; }