import { ItemCategory } from "./itemCategories.js"; import { EquipmentKind } from "./equipmentKinds.js"; import { equipImageName } from "./tileSprites.js"; import { ClothTier, CLOTH_TIER_ORDER, CLOTH_DISPLAY_NAME, tierMinSkillLevel } from "./materialTiers.js"; /** * Cloth family: raw fibre (wool sprite), yarn, woven cloth — shared magenta * sprites under items/cloth/{wool,yarn,cloth}.png with per-tier tint. * Cotton raw reuses CraftingItemId.wool (11); yarn/cloth reuse 12/25. * Garments: shirt / shorts / skirt / trousers / sweater, all tiered + dyeable. * Cotton shirt keeps historic ItemId 5; cotton shorts/trousers keep 239/240. */ export const ClothItemId = Object.freeze({ cotton: 11, cottonYarn: 12, cottonCloth: 25, wool: 133, woolYarn: 134, woolCloth: 135, linen: 136, linenYarn: 137, linenCloth: 138, cashmere: 139, cashmereYarn: 140, cashmereCloth: 141, silk: 142, silkYarn: 143, silkCloth: 144, fairySilk: 145, fairySilkYarn: 146, fairySilkCloth: 147, dragonweave: 148, dragonweaveYarn: 149, dragonweaveCloth: 150, cottonSweater: 151, woolSweater: 152, linenSweater: 153, cashmereSweater: 154, silkSweater: 155, fairySilkSweater: 156, dragonweaveSweater: 157, cottonShirt: 5, woolShirt: 250, linenShirt: 251, cashmereShirt: 252, silkShirt: 253, fairySilkShirt: 254, dragonweaveShirt: 255, cottonShorts: 239, woolShorts: 256, linenShorts: 257, cashmereShorts: 258, silkShorts: 259, fairySilkShorts: 260, dragonweaveShorts: 261, cottonTrousers: 240, woolTrousers: 262, linenTrousers: 263, cashmereTrousers: 264, silkTrousers: 265, fairySilkTrousers: 266, dragonweaveTrousers: 267, cottonSkirt: 268, woolSkirt: 269, linenSkirt: 270, cashmereSkirt: 271, silkSkirt: 272, fairySilkSkirt: 273, dragonweaveSkirt: 274 }); const RAW_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cotton, [ClothTier.wool]: ClothItemId.wool, [ClothTier.linen]: ClothItemId.linen, [ClothTier.cashmere]: ClothItemId.cashmere, [ClothTier.silk]: ClothItemId.silk, [ClothTier.fairySilk]: ClothItemId.fairySilk, [ClothTier.dragonweave]: ClothItemId.dragonweave }); const YARN_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cottonYarn, [ClothTier.wool]: ClothItemId.woolYarn, [ClothTier.linen]: ClothItemId.linenYarn, [ClothTier.cashmere]: ClothItemId.cashmereYarn, [ClothTier.silk]: ClothItemId.silkYarn, [ClothTier.fairySilk]: ClothItemId.fairySilkYarn, [ClothTier.dragonweave]: ClothItemId.dragonweaveYarn }); const CLOTH_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cottonCloth, [ClothTier.wool]: ClothItemId.woolCloth, [ClothTier.linen]: ClothItemId.linenCloth, [ClothTier.cashmere]: ClothItemId.cashmereCloth, [ClothTier.silk]: ClothItemId.silkCloth, [ClothTier.fairySilk]: ClothItemId.fairySilkCloth, [ClothTier.dragonweave]: ClothItemId.dragonweaveCloth }); const SWEATER_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cottonSweater, [ClothTier.wool]: ClothItemId.woolSweater, [ClothTier.linen]: ClothItemId.linenSweater, [ClothTier.cashmere]: ClothItemId.cashmereSweater, [ClothTier.silk]: ClothItemId.silkSweater, [ClothTier.fairySilk]: ClothItemId.fairySilkSweater, [ClothTier.dragonweave]: ClothItemId.dragonweaveSweater }); const SHIRT_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cottonShirt, [ClothTier.wool]: ClothItemId.woolShirt, [ClothTier.linen]: ClothItemId.linenShirt, [ClothTier.cashmere]: ClothItemId.cashmereShirt, [ClothTier.silk]: ClothItemId.silkShirt, [ClothTier.fairySilk]: ClothItemId.fairySilkShirt, [ClothTier.dragonweave]: ClothItemId.dragonweaveShirt }); const SHORTS_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cottonShorts, [ClothTier.wool]: ClothItemId.woolShorts, [ClothTier.linen]: ClothItemId.linenShorts, [ClothTier.cashmere]: ClothItemId.cashmereShorts, [ClothTier.silk]: ClothItemId.silkShorts, [ClothTier.fairySilk]: ClothItemId.fairySilkShorts, [ClothTier.dragonweave]: ClothItemId.dragonweaveShorts }); const TROUSERS_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cottonTrousers, [ClothTier.wool]: ClothItemId.woolTrousers, [ClothTier.linen]: ClothItemId.linenTrousers, [ClothTier.cashmere]: ClothItemId.cashmereTrousers, [ClothTier.silk]: ClothItemId.silkTrousers, [ClothTier.fairySilk]: ClothItemId.fairySilkTrousers, [ClothTier.dragonweave]: ClothItemId.dragonweaveTrousers }); const SKIRT_ID = Object.freeze({ [ClothTier.cotton]: ClothItemId.cottonSkirt, [ClothTier.wool]: ClothItemId.woolSkirt, [ClothTier.linen]: ClothItemId.linenSkirt, [ClothTier.cashmere]: ClothItemId.cashmereSkirt, [ClothTier.silk]: ClothItemId.silkSkirt, [ClothTier.fairySilk]: ClothItemId.fairySilkSkirt, [ClothTier.dragonweave]: ClothItemId.dragonweaveSkirt }); const DEFAULT_STACK = 99; function clothKeyPrefix (tier) { return String(tier) === "fairySilk" ? "fairy-silk" : String(tier); } function rawLabel (tier) { if (tier === ClothTier.cotton) { return "Cotton"; } if (tier === ClothTier.linen) { return "Flax"; } if (tier === ClothTier.silk) { return "Silk"; } return CLOTH_DISPLAY_NAME[tier] ?? tier; } function fibreDef (itemId, tier, key) { const name = rawLabel(tier); const spinHint = tier === ClothTier.linen ? "Spin into linen yarn at a spinning wheel." : `Spin into yarn at a spinning wheel.`; let description; if (tier === ClothTier.linen) { description = `Harvested flax stems. ${spinHint}`; } else if (tier === ClothTier.silk) { description = `Soft fibre drawn from a cocoon. ${spinHint}`; } else { description = `Raw ${name.toLowerCase()} fibre. ${spinHint}`; } return Object.freeze({ itemId, key, displayName: name, description, seedValue: 2, stackable: true, maxStackSize: DEFAULT_STACK, uniqueInstance: false, category: ItemCategory.ingredient, iconKey: "cloth", defaultState: "wool", tier, tintFromTier: true }); } function yarnDef (itemId, tier, key) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return Object.freeze({ itemId, key, displayName: `${name} yarn`, description: `Spun ${name.toLowerCase()} yarn. Weave into cloth at a loom, or knit garments at a tailor's bench.`, seedValue: 3, stackable: true, maxStackSize: DEFAULT_STACK, uniqueInstance: false, category: ItemCategory.intermediate, iconKey: "cloth", defaultState: "yarn", tier, tintFromTier: true }); } function clothDef (itemId, tier, key) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return Object.freeze({ itemId, key, displayName: `${name} cloth`, description: `Woven ${name.toLowerCase()} cloth for tailored garments.`, seedValue: 4, stackable: true, maxStackSize: DEFAULT_STACK, uniqueInstance: false, category: ItemCategory.intermediate, iconKey: "cloth", defaultState: "cloth", tier, tintFromTier: true }); } function garmentDef ({ itemId, tier, key, pieceLabel, description, seedValue, defaultState, slot, warm = false, tightFit = true, equipStem }) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return Object.freeze({ itemId, key, displayName: `${name} ${pieceLabel}`, description, seedValue, stackable: false, maxStackSize: 1, uniqueInstance: false, category: ItemCategory.finished, iconKey: "clothing", defaultState, tier, tintFromTier: true, dyeable: true, tightFit, clothing: Object.freeze({ warm, style: true }), equipment: Object.freeze({ slot, tier, kind: EquipmentKind.clothArmour, bonus: 0, minSkillLevel: tierMinSkillLevel(tier), tintFromTier: true, equipSprite: equipImageName("item", "clothing", equipStem) }) }); } function sweaterDef (itemId, tier, key) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return garmentDef({ itemId, tier, key, pieceLabel: "sweater", description: `A warm ${name.toLowerCase()} sweater, soft enough for travel.`, seedValue: 10, defaultState: "sweater", slot: "chest", warm: true, equipStem: "sweater" }); } function shirtDef (itemId, tier, key) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return garmentDef({ itemId, tier, key, pieceLabel: "shirt", description: `A simple ${name.toLowerCase()} shirt, plain and practical.`, seedValue: 8, defaultState: "shirt", slot: "chest", warm: false, equipStem: "shirt" }); } function shortsDef (itemId, tier, key) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return garmentDef({ itemId, tier, key, pieceLabel: "shorts", description: `Light ${name.toLowerCase()} shorts cut for warm days on the road.`, seedValue: 4, defaultState: "shorts", slot: "legs", warm: false, equipStem: "shorts" }); } function skirtDef (itemId, tier, key) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return garmentDef({ itemId, tier, key, pieceLabel: "skirt", description: `A light ${name.toLowerCase()} skirt for easy travel.`, seedValue: 4, defaultState: "skirt", slot: "legs", warm: false, tightFit: false, equipStem: "skirt" }); } function trousersDef (itemId, tier, key) { const name = CLOTH_DISPLAY_NAME[tier] ?? tier; return garmentDef({ itemId, tier, key, pieceLabel: "trousers", description: `Plain ${name.toLowerCase()} trousers, sturdy enough for travel.`, seedValue: 5, defaultState: "trousers", slot: "legs", warm: false, equipStem: "trousers" }); } function buildClothDefinitions () { const defs = {}; for (const tier of CLOTH_TIER_ORDER) { const prefix = clothKeyPrefix(tier); defs[RAW_ID[tier]] = fibreDef(RAW_ID[tier], tier, prefix === "fairy-silk" ? "fairy-silk" : prefix); defs[YARN_ID[tier]] = yarnDef(YARN_ID[tier], tier, `${prefix}-yarn`); defs[CLOTH_ID[tier]] = clothDef(CLOTH_ID[tier], tier, `${prefix}-cloth`); defs[SWEATER_ID[tier]] = sweaterDef(SWEATER_ID[tier], tier, `${prefix}-sweater`); defs[SHIRT_ID[tier]] = shirtDef(SHIRT_ID[tier], tier, `${prefix}-shirt`); defs[SHORTS_ID[tier]] = shortsDef(SHORTS_ID[tier], tier, `${prefix}-shorts`); defs[SKIRT_ID[tier]] = skirtDef(SKIRT_ID[tier], tier, `${prefix}-skirt`); defs[TROUSERS_ID[tier]] = trousersDef(TROUSERS_ID[tier], tier, `${prefix}-trousers`); } // Prefer display key "cotton" for the plant fibre. defs[ClothItemId.cotton] = fibreDef(ClothItemId.cotton, ClothTier.cotton, "cotton"); return Object.freeze(defs); } export const CLOTH_ITEM_DEFINITIONS = buildClothDefinitions(); export function rawClothItemId (tier) { return RAW_ID[tier] ?? null; } export function yarnItemId (tier) { return YARN_ID[tier] ?? null; } export function wovenClothItemId (tier) { return CLOTH_ID[tier] ?? null; } export function sweaterItemId (tier) { return SWEATER_ID[tier] ?? null; } export function shirtItemId (tier) { return SHIRT_ID[tier] ?? null; } export function shortsItemId (tier) { return SHORTS_ID[tier] ?? null; } export function skirtItemId (tier) { return SKIRT_ID[tier] ?? null; } export function trousersItemId (tier) { return TROUSERS_ID[tier] ?? null; } export function clothTierForItemId (itemId) { for (const tier of CLOTH_TIER_ORDER) { if (RAW_ID[tier] === itemId || YARN_ID[tier] === itemId || CLOTH_ID[tier] === itemId || SWEATER_ID[tier] === itemId || SHIRT_ID[tier] === itemId || SHORTS_ID[tier] === itemId || SKIRT_ID[tier] === itemId || TROUSERS_ID[tier] === itemId) { return tier; } } return null; } /** Tailor garment templates (UI + recipes). */ export const CLOTHING_TEMPLATES = Object.freeze({ shirt: Object.freeze({ templateId: "shirt", displayName: "Shirt", slot: "chest", warm: false, inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), outputItemIdForTier: shirtItemId, minSkillLevel: 1 }), shorts: Object.freeze({ templateId: "shorts", displayName: "Shorts", slot: "legs", warm: false, inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), outputItemIdForTier: shortsItemId, minSkillLevel: 1 }), skirt: Object.freeze({ templateId: "skirt", displayName: "Skirt", slot: "legs", warm: false, inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), outputItemIdForTier: skirtItemId, minSkillLevel: 1 }), trousers: Object.freeze({ templateId: "trousers", displayName: "Trousers", slot: "legs", warm: false, inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), outputItemIdForTier: trousersItemId, minSkillLevel: 1 }), sweater: Object.freeze({ templateId: "sweater", displayName: "Sweater", slot: "chest", warm: true, inputs: Object.freeze([{ kind: "yarn", quantity: 3 }]), outputItemIdForTier: sweaterItemId, minSkillLevel: 1 }) }); export function clothingTemplate (templateId) { return CLOTHING_TEMPLATES[templateId] ?? null; } export function listClothingTemplates () { return Object.values(CLOTHING_TEMPLATES); } export { tierMinSkillLevel };