| 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 | * Garments: shirt / shorts / skirt / trousers / sweater, all tiered + dyeable. |
| 16 | * Cotton shirt keeps historic ItemId 5; cotton shorts/trousers keep 239/240. |
| 17 | */ |
| 18 | export const ClothItemId = Object.freeze({ |
| 19 | cotton: 11, |
| 20 | cottonYarn: 12, |
| 21 | cottonCloth: 25, |
| 22 | wool: 133, |
| 23 | woolYarn: 134, |
| 24 | woolCloth: 135, |
| 25 | linen: 136, |
| 26 | linenYarn: 137, |
| 27 | linenCloth: 138, |
| 28 | cashmere: 139, |
| 29 | cashmereYarn: 140, |
| 30 | cashmereCloth: 141, |
| 31 | silk: 142, |
| 32 | silkYarn: 143, |
| 33 | silkCloth: 144, |
| 34 | fairySilk: 145, |
| 35 | fairySilkYarn: 146, |
| 36 | fairySilkCloth: 147, |
| 37 | dragonweave: 148, |
| 38 | dragonweaveYarn: 149, |
| 39 | dragonweaveCloth: 150, |
| 40 | cottonSweater: 151, |
| 41 | woolSweater: 152, |
| 42 | linenSweater: 153, |
| 43 | cashmereSweater: 154, |
| 44 | silkSweater: 155, |
| 45 | fairySilkSweater: 156, |
| 46 | dragonweaveSweater: 157, |
| 47 | cottonShirt: 5, |
| 48 | woolShirt: 250, |
| 49 | linenShirt: 251, |
| 50 | cashmereShirt: 252, |
| 51 | silkShirt: 253, |
| 52 | fairySilkShirt: 254, |
| 53 | dragonweaveShirt: 255, |
| 54 | cottonShorts: 239, |
| 55 | woolShorts: 256, |
| 56 | linenShorts: 257, |
| 57 | cashmereShorts: 258, |
| 58 | silkShorts: 259, |
| 59 | fairySilkShorts: 260, |
| 60 | dragonweaveShorts: 261, |
| 61 | cottonTrousers: 240, |
| 62 | woolTrousers: 262, |
| 63 | linenTrousers: 263, |
| 64 | cashmereTrousers: 264, |
| 65 | silkTrousers: 265, |
| 66 | fairySilkTrousers: 266, |
| 67 | dragonweaveTrousers: 267, |
| 68 | cottonSkirt: 268, |
| 69 | woolSkirt: 269, |
| 70 | linenSkirt: 270, |
| 71 | cashmereSkirt: 271, |
| 72 | silkSkirt: 272, |
| 73 | fairySilkSkirt: 273, |
| 74 | dragonweaveSkirt: 274 |
| 75 | }); |
| 76 | |
| 77 | const RAW_ID = Object.freeze({ |
| 78 | [ClothTier.cotton]: ClothItemId.cotton, |
| 79 | [ClothTier.wool]: ClothItemId.wool, |
| 80 | [ClothTier.linen]: ClothItemId.linen, |
| 81 | [ClothTier.cashmere]: ClothItemId.cashmere, |
| 82 | [ClothTier.silk]: ClothItemId.silk, |
| 83 | [ClothTier.fairySilk]: ClothItemId.fairySilk, |
| 84 | [ClothTier.dragonweave]: ClothItemId.dragonweave |
| 85 | }); |
| 86 | |
| 87 | const YARN_ID = Object.freeze({ |
| 88 | [ClothTier.cotton]: ClothItemId.cottonYarn, |
| 89 | [ClothTier.wool]: ClothItemId.woolYarn, |
| 90 | [ClothTier.linen]: ClothItemId.linenYarn, |
| 91 | [ClothTier.cashmere]: ClothItemId.cashmereYarn, |
| 92 | [ClothTier.silk]: ClothItemId.silkYarn, |
| 93 | [ClothTier.fairySilk]: ClothItemId.fairySilkYarn, |
| 94 | [ClothTier.dragonweave]: ClothItemId.dragonweaveYarn |
| 95 | }); |
| 96 | |
| 97 | const CLOTH_ID = Object.freeze({ |
| 98 | [ClothTier.cotton]: ClothItemId.cottonCloth, |
| 99 | [ClothTier.wool]: ClothItemId.woolCloth, |
| 100 | [ClothTier.linen]: ClothItemId.linenCloth, |
| 101 | [ClothTier.cashmere]: ClothItemId.cashmereCloth, |
| 102 | [ClothTier.silk]: ClothItemId.silkCloth, |
| 103 | [ClothTier.fairySilk]: ClothItemId.fairySilkCloth, |
| 104 | [ClothTier.dragonweave]: ClothItemId.dragonweaveCloth |
| 105 | }); |
| 106 | |
| 107 | const SWEATER_ID = Object.freeze({ |
| 108 | [ClothTier.cotton]: ClothItemId.cottonSweater, |
| 109 | [ClothTier.wool]: ClothItemId.woolSweater, |
| 110 | [ClothTier.linen]: ClothItemId.linenSweater, |
| 111 | [ClothTier.cashmere]: ClothItemId.cashmereSweater, |
| 112 | [ClothTier.silk]: ClothItemId.silkSweater, |
| 113 | [ClothTier.fairySilk]: ClothItemId.fairySilkSweater, |
| 114 | [ClothTier.dragonweave]: ClothItemId.dragonweaveSweater |
| 115 | }); |
| 116 | |
| 117 | const SHIRT_ID = Object.freeze({ |
| 118 | [ClothTier.cotton]: ClothItemId.cottonShirt, |
| 119 | [ClothTier.wool]: ClothItemId.woolShirt, |
| 120 | [ClothTier.linen]: ClothItemId.linenShirt, |
| 121 | [ClothTier.cashmere]: ClothItemId.cashmereShirt, |
| 122 | [ClothTier.silk]: ClothItemId.silkShirt, |
| 123 | [ClothTier.fairySilk]: ClothItemId.fairySilkShirt, |
| 124 | [ClothTier.dragonweave]: ClothItemId.dragonweaveShirt |
| 125 | }); |
| 126 | |
| 127 | const SHORTS_ID = Object.freeze({ |
| 128 | [ClothTier.cotton]: ClothItemId.cottonShorts, |
| 129 | [ClothTier.wool]: ClothItemId.woolShorts, |
| 130 | [ClothTier.linen]: ClothItemId.linenShorts, |
| 131 | [ClothTier.cashmere]: ClothItemId.cashmereShorts, |
| 132 | [ClothTier.silk]: ClothItemId.silkShorts, |
| 133 | [ClothTier.fairySilk]: ClothItemId.fairySilkShorts, |
| 134 | [ClothTier.dragonweave]: ClothItemId.dragonweaveShorts |
| 135 | }); |
| 136 | |
| 137 | const TROUSERS_ID = Object.freeze({ |
| 138 | [ClothTier.cotton]: ClothItemId.cottonTrousers, |
| 139 | [ClothTier.wool]: ClothItemId.woolTrousers, |
| 140 | [ClothTier.linen]: ClothItemId.linenTrousers, |
| 141 | [ClothTier.cashmere]: ClothItemId.cashmereTrousers, |
| 142 | [ClothTier.silk]: ClothItemId.silkTrousers, |
| 143 | [ClothTier.fairySilk]: ClothItemId.fairySilkTrousers, |
| 144 | [ClothTier.dragonweave]: ClothItemId.dragonweaveTrousers |
| 145 | }); |
| 146 | |
| 147 | const SKIRT_ID = Object.freeze({ |
| 148 | [ClothTier.cotton]: ClothItemId.cottonSkirt, |
| 149 | [ClothTier.wool]: ClothItemId.woolSkirt, |
| 150 | [ClothTier.linen]: ClothItemId.linenSkirt, |
| 151 | [ClothTier.cashmere]: ClothItemId.cashmereSkirt, |
| 152 | [ClothTier.silk]: ClothItemId.silkSkirt, |
| 153 | [ClothTier.fairySilk]: ClothItemId.fairySilkSkirt, |
| 154 | [ClothTier.dragonweave]: ClothItemId.dragonweaveSkirt |
| 155 | }); |
| 156 | |
| 157 | const DEFAULT_STACK = 99; |
| 158 | |
| 159 | function clothKeyPrefix (tier) |
| 160 | { |
| 161 | return String(tier) === "fairySilk" ? "fairy-silk" : String(tier); |
| 162 | } |
| 163 | |
| 164 | function rawLabel (tier) |
| 165 | { |
| 166 | if (tier === ClothTier.cotton) |
| 167 | { return "Cotton"; } |
| 168 | return CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 169 | } |
| 170 | |
| 171 | function fibreDef (itemId, tier, key) |
| 172 | { |
| 173 | const name = rawLabel(tier); |
| 174 | return Object.freeze({ |
| 175 | itemId, |
| 176 | key, |
| 177 | displayName: name, |
| 178 | description: `Raw ${name.toLowerCase()} fibre. Spin into yarn at a spinning wheel.`, |
| 179 | seedValue: 2, |
| 180 | stackable: true, |
| 181 | maxStackSize: DEFAULT_STACK, |
| 182 | uniqueInstance: false, |
| 183 | category: ItemCategory.ingredient, |
| 184 | iconKey: "cloth", |
| 185 | defaultState: "wool", |
| 186 | tier, |
| 187 | tintFromTier: true |
| 188 | }); |
| 189 | } |
| 190 | |
| 191 | function yarnDef (itemId, tier, key) |
| 192 | { |
| 193 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 194 | return Object.freeze({ |
| 195 | itemId, |
| 196 | key, |
| 197 | displayName: `${name} yarn`, |
| 198 | description: `Spun ${name.toLowerCase()} yarn. Weave into cloth at a loom, or knit garments at a tailor's bench.`, |
| 199 | seedValue: 3, |
| 200 | stackable: true, |
| 201 | maxStackSize: DEFAULT_STACK, |
| 202 | uniqueInstance: false, |
| 203 | category: ItemCategory.intermediate, |
| 204 | iconKey: "cloth", |
| 205 | defaultState: "yarn", |
| 206 | tier, |
| 207 | tintFromTier: true |
| 208 | }); |
| 209 | } |
| 210 | |
| 211 | function clothDef (itemId, tier, key) |
| 212 | { |
| 213 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 214 | return Object.freeze({ |
| 215 | itemId, |
| 216 | key, |
| 217 | displayName: `${name} cloth`, |
| 218 | description: `Woven ${name.toLowerCase()} cloth for tailored garments.`, |
| 219 | seedValue: 4, |
| 220 | stackable: true, |
| 221 | maxStackSize: DEFAULT_STACK, |
| 222 | uniqueInstance: false, |
| 223 | category: ItemCategory.intermediate, |
| 224 | iconKey: "cloth", |
| 225 | defaultState: "cloth", |
| 226 | tier, |
| 227 | tintFromTier: true |
| 228 | }); |
| 229 | } |
| 230 | |
| 231 | function garmentDef ({ |
| 232 | itemId, |
| 233 | tier, |
| 234 | key, |
| 235 | pieceLabel, |
| 236 | description, |
| 237 | seedValue, |
| 238 | defaultState, |
| 239 | slot, |
| 240 | warm = false, |
| 241 | tightFit = true, |
| 242 | equipStem |
| 243 | }) |
| 244 | { |
| 245 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 246 | return Object.freeze({ |
| 247 | itemId, |
| 248 | key, |
| 249 | displayName: `${name} ${pieceLabel}`, |
| 250 | description, |
| 251 | seedValue, |
| 252 | stackable: false, |
| 253 | maxStackSize: 1, |
| 254 | uniqueInstance: false, |
| 255 | category: ItemCategory.finished, |
| 256 | iconKey: "clothing", |
| 257 | defaultState, |
| 258 | tier, |
| 259 | tintFromTier: true, |
| 260 | dyeable: true, |
| 261 | tightFit, |
| 262 | clothing: Object.freeze({ warm, style: true }), |
| 263 | equipment: Object.freeze({ |
| 264 | slot, |
| 265 | tier, |
| 266 | kind: EquipmentKind.clothArmour, |
| 267 | bonus: 0, |
| 268 | minSkillLevel: tierMinSkillLevel(tier), |
| 269 | tintFromTier: true, |
| 270 | equipSprite: equipImageName("item", "clothing", equipStem) |
| 271 | }) |
| 272 | }); |
| 273 | } |
| 274 | |
| 275 | function sweaterDef (itemId, tier, key) |
| 276 | { |
| 277 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 278 | return garmentDef({ |
| 279 | itemId, |
| 280 | tier, |
| 281 | key, |
| 282 | pieceLabel: "sweater", |
| 283 | description: `A warm ${name.toLowerCase()} sweater, soft enough for travel.`, |
| 284 | seedValue: 10, |
| 285 | defaultState: "sweater", |
| 286 | slot: "chest", |
| 287 | warm: true, |
| 288 | equipStem: "sweater" |
| 289 | }); |
| 290 | } |
| 291 | |
| 292 | function shirtDef (itemId, tier, key) |
| 293 | { |
| 294 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 295 | return garmentDef({ |
| 296 | itemId, |
| 297 | tier, |
| 298 | key, |
| 299 | pieceLabel: "shirt", |
| 300 | description: `A simple ${name.toLowerCase()} shirt, plain and practical.`, |
| 301 | seedValue: 8, |
| 302 | defaultState: "shirt", |
| 303 | slot: "chest", |
| 304 | warm: false, |
| 305 | equipStem: "shirt" |
| 306 | }); |
| 307 | } |
| 308 | |
| 309 | function shortsDef (itemId, tier, key) |
| 310 | { |
| 311 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 312 | return garmentDef({ |
| 313 | itemId, |
| 314 | tier, |
| 315 | key, |
| 316 | pieceLabel: "shorts", |
| 317 | description: `Light ${name.toLowerCase()} shorts cut for warm days on the road.`, |
| 318 | seedValue: 4, |
| 319 | defaultState: "shorts", |
| 320 | slot: "legs", |
| 321 | warm: false, |
| 322 | equipStem: "shorts" |
| 323 | }); |
| 324 | } |
| 325 | |
| 326 | function skirtDef (itemId, tier, key) |
| 327 | { |
| 328 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 329 | return garmentDef({ |
| 330 | itemId, |
| 331 | tier, |
| 332 | key, |
| 333 | pieceLabel: "skirt", |
| 334 | description: `A light ${name.toLowerCase()} skirt for easy travel.`, |
| 335 | seedValue: 4, |
| 336 | defaultState: "skirt", |
| 337 | slot: "legs", |
| 338 | warm: false, |
| 339 | tightFit: false, |
| 340 | equipStem: "skirt" |
| 341 | }); |
| 342 | } |
| 343 | |
| 344 | function trousersDef (itemId, tier, key) |
| 345 | { |
| 346 | const name = CLOTH_DISPLAY_NAME[tier] ?? tier; |
| 347 | return garmentDef({ |
| 348 | itemId, |
| 349 | tier, |
| 350 | key, |
| 351 | pieceLabel: "trousers", |
| 352 | description: `Plain ${name.toLowerCase()} trousers, sturdy enough for travel.`, |
| 353 | seedValue: 5, |
| 354 | defaultState: "trousers", |
| 355 | slot: "legs", |
| 356 | warm: false, |
| 357 | equipStem: "trousers" |
| 358 | }); |
| 359 | } |
| 360 | |
| 361 | function buildClothDefinitions () |
| 362 | { |
| 363 | const defs = {}; |
| 364 | for (const tier of CLOTH_TIER_ORDER) |
| 365 | { |
| 366 | const prefix = clothKeyPrefix(tier); |
| 367 | defs[RAW_ID[tier]] = fibreDef(RAW_ID[tier], tier, prefix === "fairy-silk" ? "fairy-silk" : prefix); |
| 368 | defs[YARN_ID[tier]] = yarnDef(YARN_ID[tier], tier, `${prefix}-yarn`); |
| 369 | defs[CLOTH_ID[tier]] = clothDef(CLOTH_ID[tier], tier, `${prefix}-cloth`); |
| 370 | defs[SWEATER_ID[tier]] = sweaterDef(SWEATER_ID[tier], tier, `${prefix}-sweater`); |
| 371 | defs[SHIRT_ID[tier]] = shirtDef(SHIRT_ID[tier], tier, `${prefix}-shirt`); |
| 372 | defs[SHORTS_ID[tier]] = shortsDef(SHORTS_ID[tier], tier, `${prefix}-shorts`); |
| 373 | defs[SKIRT_ID[tier]] = skirtDef(SKIRT_ID[tier], tier, `${prefix}-skirt`); |
| 374 | defs[TROUSERS_ID[tier]] = trousersDef(TROUSERS_ID[tier], tier, `${prefix}-trousers`); |
| 375 | } |
| 376 | // Prefer display key "cotton" for the plant fibre. |
| 377 | defs[ClothItemId.cotton] = fibreDef(ClothItemId.cotton, ClothTier.cotton, "cotton"); |
| 378 | return Object.freeze(defs); |
| 379 | } |
| 380 | |
| 381 | export const CLOTH_ITEM_DEFINITIONS = buildClothDefinitions(); |
| 382 | |
| 383 | export function rawClothItemId (tier) |
| 384 | { |
| 385 | return RAW_ID[tier] ?? null; |
| 386 | } |
| 387 | |
| 388 | export function yarnItemId (tier) |
| 389 | { |
| 390 | return YARN_ID[tier] ?? null; |
| 391 | } |
| 392 | |
| 393 | export function wovenClothItemId (tier) |
| 394 | { |
| 395 | return CLOTH_ID[tier] ?? null; |
| 396 | } |
| 397 | |
| 398 | export function sweaterItemId (tier) |
| 399 | { |
| 400 | return SWEATER_ID[tier] ?? null; |
| 401 | } |
| 402 | |
| 403 | export function shirtItemId (tier) |
| 404 | { |
| 405 | return SHIRT_ID[tier] ?? null; |
| 406 | } |
| 407 | |
| 408 | export function shortsItemId (tier) |
| 409 | { |
| 410 | return SHORTS_ID[tier] ?? null; |
| 411 | } |
| 412 | |
| 413 | export function skirtItemId (tier) |
| 414 | { |
| 415 | return SKIRT_ID[tier] ?? null; |
| 416 | } |
| 417 | |
| 418 | export function trousersItemId (tier) |
| 419 | { |
| 420 | return TROUSERS_ID[tier] ?? null; |
| 421 | } |
| 422 | |
| 423 | export function clothTierForItemId (itemId) |
| 424 | { |
| 425 | for (const tier of CLOTH_TIER_ORDER) |
| 426 | { |
| 427 | if (RAW_ID[tier] === itemId || YARN_ID[tier] === itemId |
| 428 | || CLOTH_ID[tier] === itemId || SWEATER_ID[tier] === itemId |
| 429 | || SHIRT_ID[tier] === itemId || SHORTS_ID[tier] === itemId |
| 430 | || SKIRT_ID[tier] === itemId || TROUSERS_ID[tier] === itemId) |
| 431 | { return tier; } |
| 432 | } |
| 433 | return null; |
| 434 | } |
| 435 | |
| 436 | /** Tailor garment templates (UI + recipes). */ |
| 437 | export const CLOTHING_TEMPLATES = Object.freeze({ |
| 438 | shirt: Object.freeze({ |
| 439 | templateId: "shirt", |
| 440 | displayName: "Shirt", |
| 441 | slot: "chest", |
| 442 | warm: false, |
| 443 | inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), |
| 444 | outputItemIdForTier: shirtItemId, |
| 445 | minSkillLevel: 1 |
| 446 | }), |
| 447 | shorts: Object.freeze({ |
| 448 | templateId: "shorts", |
| 449 | displayName: "Shorts", |
| 450 | slot: "legs", |
| 451 | warm: false, |
| 452 | inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), |
| 453 | outputItemIdForTier: shortsItemId, |
| 454 | minSkillLevel: 1 |
| 455 | }), |
| 456 | skirt: Object.freeze({ |
| 457 | templateId: "skirt", |
| 458 | displayName: "Skirt", |
| 459 | slot: "legs", |
| 460 | warm: false, |
| 461 | inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), |
| 462 | outputItemIdForTier: skirtItemId, |
| 463 | minSkillLevel: 1 |
| 464 | }), |
| 465 | trousers: Object.freeze({ |
| 466 | templateId: "trousers", |
| 467 | displayName: "Trousers", |
| 468 | slot: "legs", |
| 469 | warm: false, |
| 470 | inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]), |
| 471 | outputItemIdForTier: trousersItemId, |
| 472 | minSkillLevel: 1 |
| 473 | }), |
| 474 | sweater: Object.freeze({ |
| 475 | templateId: "sweater", |
| 476 | displayName: "Sweater", |
| 477 | slot: "chest", |
| 478 | warm: true, |
| 479 | inputs: Object.freeze([{ kind: "yarn", quantity: 3 }]), |
| 480 | outputItemIdForTier: sweaterItemId, |
| 481 | minSkillLevel: 1 |
| 482 | }) |
| 483 | }); |
| 484 | |
| 485 | export function clothingTemplate (templateId) |
| 486 | { |
| 487 | return CLOTHING_TEMPLATES[templateId] ?? null; |
| 488 | } |
| 489 | |
| 490 | export function listClothingTemplates () |
| 491 | { |
| 492 | return Object.values(CLOTHING_TEMPLATES); |
| 493 | } |
| 494 | |
| 495 | export { tierMinSkillLevel }; |