| 1 | import { ItemCategory } from "./itemCategories.js"; |
| 2 | import { EquipmentKind } from "./equipmentKinds.js"; |
| 3 | import { equipImageName } from "./tileSprites.js"; |
| 4 | import { |
| 5 | ClothTier, |
| 6 | CLOTH_TIER_ORDER, |
| 7 | CLOTH_DISPLAY_NAME, |
| 8 | tierMinSkillLevel |
| 9 | } from "./materialTiers.js"; |
| 10 | |
| 11 | /** |
| 12 | * Cloth family: raw fibre (wool sprite), yarn, woven cloth — shared magenta |
| 13 | * sprites under items/cloth/{wool,yarn,cloth}.png with per-tier tint. |
| 14 | * Cotton raw reuses CraftingItemId.wool (11); yarn/cloth reuse 12/25. |
| 15 | */ |
| 16 | export const ClothItemId = Object.freeze({ |
| 17 | cotton: 11, |
| 18 | cottonYarn: 12, |
| 19 | cottonCloth: 25, |
| 20 | wool: 133, |
| 21 | woolYarn: 134, |
| 22 | woolCloth: 135, |
| 23 | linen: 136, |
| 24 | linenYarn: 137, |
| 25 | linenCloth: 138, |
| 26 | cashmere: 139, |
| 27 | cashmereYarn: 140, |
| 28 | cashmereCloth: 141, |
| 29 | silk: 142, |
| 30 | silkYarn: 143, |
| 31 | silkCloth: 144, |
| 32 | fairySilk: 145, |
| 33 | fairySilkYarn: 146, |
| 34 | fairySilkCloth: 147, |
| 35 | dragonweave: 148, |
| 36 | dragonweaveYarn: 149, |
| 37 | dragonweaveCloth: 150, |
| 38 | cottonSweater: 151, |
| 39 | woolSweater: 152, |
| 40 | linenSweater: 153, |
| 41 | cashmereSweater: 154, |
| 42 | silkSweater: 155, |
| 43 | fairySilkSweater: 156, |
| 44 | dragonweaveSweater: 157 |
| 45 | }); |
| 46 | |
| 47 | const RAW_ID = Object.freeze({ |
| 48 | [ClothTier.cotton]: ClothItemId.cotton, |
| 49 | [ClothTier.wool]: ClothItemId.wool, |
| 50 | [ClothTier.linen]: ClothItemId.linen, |
| 51 | [ClothTier.cashmere]: ClothItemId.cashmere, |
| 52 | [ClothTier.silk]: ClothItemId.silk, |
| 53 | [ClothTier.fairySilk]: ClothItemId.fairySilk, |
| 54 | [ClothTier.dragonweave]: ClothItemId.dragonweave |
| 55 | }); |
| 56 | |
| 57 | const YARN_ID = Object.freeze({ |
| 58 | [ClothTier.cotton]: ClothItemId.cottonYarn, |
| 59 | [ClothTier.wool]: ClothItemId.woolYarn, |
| 60 | [ClothTier.linen]: ClothItemId.linenYarn, |
| 61 | [ClothTier.cashmere]: ClothItemId.cashmereYarn, |
| 62 | [ClothTier.silk]: ClothItemId.silkYarn, |
| 63 | [ClothTier.fairySilk]: ClothItemId.fairySilkYarn, |
| 64 | [ClothTier.dragonweave]: ClothItemId.dragonweaveYarn |
| 65 | }); |
| 66 | |
| 67 | const CLOTH_ID = Object.freeze({ |
| 68 | [ClothTier.cotton]: ClothItemId.cottonCloth, |
| 69 | [ClothTier.wool]: ClothItemId.woolCloth, |
| 70 | [ClothTier.linen]: ClothItemId.linenCloth, |
| 71 | [ClothTier.cashmere]: ClothItemId.cashmereCloth, |
| 72 | [ClothTier.silk]: ClothItemId.silkCloth, |
| 73 | [ClothTier.fairySilk]: ClothItemId.fairySilkCloth, |
| 74 | [ClothTier.dragonweave]: ClothItemId.dragonweaveCloth |
| 75 | }); |
| 76 | |
| 77 | const SWEATER_ID = Object.freeze({ |
| 78 | [ClothTier.cotton]: ClothItemId.cottonSweater, |
| 79 | [ClothTier.wool]: ClothItemId.woolSweater, |
| 80 | [ClothTier.linen]: ClothItemId.linenSweater, |
| 81 | [ClothTier.cashmere]: ClothItemId.cashmereSweater, |
| 82 | [ClothTier.silk]: ClothItemId.silkSweater, |
| 83 | [ClothTier.fairySilk]: ClothItemId.fairySilkSweater, |
| 84 | [ClothTier.dragonweave]: ClothItemId.dragonweaveSweater |
| 85 | }); |
| 86 | |
| 87 | const DEFAULT_STACK = 99; |
| 88 | |
| 89 | function rawLabel (tier) |
| 90 | { |
| 91 | if (tier === ClothTier.cotton) |
| 92 | { return "Cotton"; } |
| 93 | return CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 94 | } |
| 95 | |
| 96 | function fibreDef (itemId, tier, key) |
| 97 | { |
| 98 | const name = rawLabel(tier); |
| 99 | return Object.freeze({ |
| 100 | itemId, |
| 101 | key, |
| 102 | displayName: name, |
| 103 | description: `Raw ${name.toLowerCase()} fibre. Spin into yarn at a spinning wheel.`, |
| 104 | seedValue: 2, |
| 105 | stackable: true, |
| 106 | maxStackSize: DEFAULT_STACK, |
| 107 | uniqueInstance: false, |
| 108 | category: ItemCategory.ingredient, |
| 109 | iconKey: "cloth", |
| 110 | defaultState: "wool", |
| 111 | tier, |
| 112 | tintFromTier: true |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | function yarnDef (itemId, tier, key) |
| 117 | { |
| 118 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 119 | return Object.freeze({ |
| 120 | itemId, |
| 121 | key, |
| 122 | displayName: `${name} yarn`, |
| 123 | description: `Spun ${name.toLowerCase()} yarn. Weave into cloth at a loom, or knit garments at a tailor's bench.`, |
| 124 | seedValue: 3, |
| 125 | stackable: true, |
| 126 | maxStackSize: DEFAULT_STACK, |
| 127 | uniqueInstance: false, |
| 128 | category: ItemCategory.intermediate, |
| 129 | iconKey: "cloth", |
| 130 | defaultState: "yarn", |
| 131 | tier, |
| 132 | tintFromTier: true |
| 133 | }); |
| 134 | } |
| 135 | |
| 136 | function clothDef (itemId, tier, key) |
| 137 | { |
| 138 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 139 | return Object.freeze({ |
| 140 | itemId, |
| 141 | key, |
| 142 | displayName: `${name} cloth`, |
| 143 | description: `Woven ${name.toLowerCase()} cloth for tailored garments.`, |
| 144 | seedValue: 4, |
| 145 | stackable: true, |
| 146 | maxStackSize: DEFAULT_STACK, |
| 147 | uniqueInstance: false, |
| 148 | category: ItemCategory.intermediate, |
| 149 | iconKey: "cloth", |
| 150 | defaultState: "cloth", |
| 151 | tier, |
| 152 | tintFromTier: true |
| 153 | }); |
| 154 | } |
| 155 | |
| 156 | function sweaterDef (itemId, tier, key) |
| 157 | { |
| 158 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 159 | return Object.freeze({ |
| 160 | itemId, |
| 161 | key, |
| 162 | displayName: `${name} sweater`, |
| 163 | description: `A warm ${name.toLowerCase()} sweater, soft enough for travel.`, |
| 164 | seedValue: 10, |
| 165 | stackable: false, |
| 166 | maxStackSize: 1, |
| 167 | uniqueInstance: false, |
| 168 | category: ItemCategory.finished, |
| 169 | iconKey: "clothing", |
| 170 | defaultState: "sweater", |
| 171 | tier, |
| 172 | tintFromTier: true, |
| 173 | dyeable: true, |
| 174 | tightFit: true, |
| 175 | clothing: Object.freeze({ warm: true, style: true }), |
| 176 | equipment: Object.freeze({ |
| 177 | slot: "chest", |
| 178 | tier, |
| 179 | kind: EquipmentKind.clothArmour, |
| 180 | bonus: 0, |
| 181 | minSkillLevel: tierMinSkillLevel(tier), |
| 182 | tintFromTier: true, |
| 183 | equipSprite: equipImageName("item", "clothing", "sweater") |
| 184 | }) |
| 185 | }); |
| 186 | } |
| 187 | |
| 188 | function buildClothDefinitions () |
| 189 | { |
| 190 | const defs = {}; |
| 191 | for (const tier of CLOTH_TIER_ORDER) |
| 192 | { |
| 193 | const label = String(tier); |
| 194 | defs[RAW_ID[tier]] = fibreDef(RAW_ID[tier], tier, label === "fairySilk" ? "fairy-silk" : label); |
| 195 | defs[YARN_ID[tier]] = yarnDef( |
| 196 | YARN_ID[tier], |
| 197 | tier, |
| 198 | `${label === "fairySilk" ? "fairy-silk" : label}-yarn` |
| 199 | ); |
| 200 | defs[CLOTH_ID[tier]] = clothDef( |
| 201 | CLOTH_ID[tier], |
| 202 | tier, |
| 203 | `${label === "fairySilk" ? "fairy-silk" : label}-cloth` |
| 204 | ); |
| 205 | defs[SWEATER_ID[tier]] = sweaterDef( |
| 206 | SWEATER_ID[tier], |
| 207 | tier, |
| 208 | `${label === "fairySilk" ? "fairy-silk" : label}-sweater` |
| 209 | ); |
| 210 | } |
| 211 | // Prefer display key "cotton" for the plant fibre. |
| 212 | defs[ClothItemId.cotton] = fibreDef(ClothItemId.cotton, ClothTier.cotton, "cotton"); |
| 213 | return Object.freeze(defs); |
| 214 | } |
| 215 | |
| 216 | export const CLOTH_ITEM_DEFINITIONS = buildClothDefinitions(); |
| 217 | |
| 218 | export function rawClothItemId (tier) |
| 219 | { |
| 220 | return RAW_ID[tier] ?? null; |
| 221 | } |
| 222 | |
| 223 | export function yarnItemId (tier) |
| 224 | { |
| 225 | return YARN_ID[tier] ?? null; |
| 226 | } |
| 227 | |
| 228 | export function wovenClothItemId (tier) |
| 229 | { |
| 230 | return CLOTH_ID[tier] ?? null; |
| 231 | } |
| 232 | |
| 233 | export function sweaterItemId (tier) |
| 234 | { |
| 235 | return SWEATER_ID[tier] ?? null; |
| 236 | } |
| 237 | |
| 238 | export function clothTierForItemId (itemId) |
| 239 | { |
| 240 | for (const tier of CLOTH_TIER_ORDER) |
| 241 | { |
| 242 | if (RAW_ID[tier] === itemId || YARN_ID[tier] === itemId |
| 243 | || CLOTH_ID[tier] === itemId || SWEATER_ID[tier] === itemId) |
| 244 | { return tier; } |
| 245 | } |
| 246 | return null; |
| 247 | } |
| 248 | |
| 249 | /** Tailor garment templates (UI + recipes). */ |
| 250 | export const CLOTHING_TEMPLATES = Object.freeze({ |
| 251 | sweater: Object.freeze({ |
| 252 | templateId: "sweater", |
| 253 | displayName: "Sweater", |
| 254 | slot: "chest", |
| 255 | warm: true, |
| 256 | inputs: Object.freeze([{ kind: "yarn", quantity: 3 }]), |
| 257 | outputItemIdForTier: sweaterItemId, |
| 258 | minSkillLevel: 1 |
| 259 | }) |
| 260 | }); |
| 261 | |
| 262 | export function clothingTemplate (templateId) |
| 263 | { |
| 264 | return CLOTHING_TEMPLATES[templateId] ?? null; |
| 265 | } |
| 266 | |
| 267 | export function listClothingTemplates () |
| 268 | { |
| 269 | return Object.values(CLOTHING_TEMPLATES); |
| 270 | } |
| 271 | |
| 272 | export { tierMinSkillLevel }; |