BlueGit

timfa questward

Files

questward / shared / definitions / clothItems.js

clothItems.js

clothItems.js 12.3 KiB Download Raw
1import { ItemCategory } from "./itemCategories.js";
2import { EquipmentKind } from "./equipmentKinds.js";
3import { equipImageName } from "./tileSprites.js";
4import {
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 */
18export 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
77const 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
87const 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
97const 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
107const 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
117const 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
127const 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
137const 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
147const 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
157const DEFAULT_STACK = 99;
158
159function clothKeyPrefix (tier)
160{
161 return String(tier) === "fairySilk" ? "fairy-silk" : String(tier);
162}
163
164function rawLabel (tier)
165{
166 if (tier === ClothTier.cotton)
167 { return "Cotton"; }
168 if (tier === ClothTier.linen)
169 { return "Flax"; }
170 return CLOTH_DISPLAY_NAME[tier] ?? tier;
171}
172
173function fibreDef (itemId, tier, key)
174{
175 const name = rawLabel(tier);
176 const spinHint = tier === ClothTier.linen
177 ? "Spin into linen yarn at a spinning wheel."
178 : `Spin into yarn at a spinning wheel.`;
179 return Object.freeze({
180 itemId,
181 key,
182 displayName: name,
183 description: tier === ClothTier.linen
184 ? `Harvested flax stems. ${spinHint}`
185 : `Raw ${name.toLowerCase()} fibre. ${spinHint}`,
186 seedValue: 2,
187 stackable: true,
188 maxStackSize: DEFAULT_STACK,
189 uniqueInstance: false,
190 category: ItemCategory.ingredient,
191 iconKey: "cloth",
192 defaultState: "wool",
193 tier,
194 tintFromTier: true
195 });
196}
197
198function yarnDef (itemId, tier, key)
199{
200 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
201 return Object.freeze({
202 itemId,
203 key,
204 displayName: `${name} yarn`,
205 description: `Spun ${name.toLowerCase()} yarn. Weave into cloth at a loom, or knit garments at a tailor's bench.`,
206 seedValue: 3,
207 stackable: true,
208 maxStackSize: DEFAULT_STACK,
209 uniqueInstance: false,
210 category: ItemCategory.intermediate,
211 iconKey: "cloth",
212 defaultState: "yarn",
213 tier,
214 tintFromTier: true
215 });
216}
217
218function clothDef (itemId, tier, key)
219{
220 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
221 return Object.freeze({
222 itemId,
223 key,
224 displayName: `${name} cloth`,
225 description: `Woven ${name.toLowerCase()} cloth for tailored garments.`,
226 seedValue: 4,
227 stackable: true,
228 maxStackSize: DEFAULT_STACK,
229 uniqueInstance: false,
230 category: ItemCategory.intermediate,
231 iconKey: "cloth",
232 defaultState: "cloth",
233 tier,
234 tintFromTier: true
235 });
236}
237
238function garmentDef ({
239 itemId,
240 tier,
241 key,
242 pieceLabel,
243 description,
244 seedValue,
245 defaultState,
246 slot,
247 warm = false,
248 tightFit = true,
249 equipStem
250})
251{
252 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
253 return Object.freeze({
254 itemId,
255 key,
256 displayName: `${name} ${pieceLabel}`,
257 description,
258 seedValue,
259 stackable: false,
260 maxStackSize: 1,
261 uniqueInstance: false,
262 category: ItemCategory.finished,
263 iconKey: "clothing",
264 defaultState,
265 tier,
266 tintFromTier: true,
267 dyeable: true,
268 tightFit,
269 clothing: Object.freeze({ warm, style: true }),
270 equipment: Object.freeze({
271 slot,
272 tier,
273 kind: EquipmentKind.clothArmour,
274 bonus: 0,
275 minSkillLevel: tierMinSkillLevel(tier),
276 tintFromTier: true,
277 equipSprite: equipImageName("item", "clothing", equipStem)
278 })
279 });
280}
281
282function sweaterDef (itemId, tier, key)
283{
284 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
285 return garmentDef({
286 itemId,
287 tier,
288 key,
289 pieceLabel: "sweater",
290 description: `A warm ${name.toLowerCase()} sweater, soft enough for travel.`,
291 seedValue: 10,
292 defaultState: "sweater",
293 slot: "chest",
294 warm: true,
295 equipStem: "sweater"
296 });
297}
298
299function shirtDef (itemId, tier, key)
300{
301 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
302 return garmentDef({
303 itemId,
304 tier,
305 key,
306 pieceLabel: "shirt",
307 description: `A simple ${name.toLowerCase()} shirt, plain and practical.`,
308 seedValue: 8,
309 defaultState: "shirt",
310 slot: "chest",
311 warm: false,
312 equipStem: "shirt"
313 });
314}
315
316function shortsDef (itemId, tier, key)
317{
318 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
319 return garmentDef({
320 itemId,
321 tier,
322 key,
323 pieceLabel: "shorts",
324 description: `Light ${name.toLowerCase()} shorts cut for warm days on the road.`,
325 seedValue: 4,
326 defaultState: "shorts",
327 slot: "legs",
328 warm: false,
329 equipStem: "shorts"
330 });
331}
332
333function skirtDef (itemId, tier, key)
334{
335 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
336 return garmentDef({
337 itemId,
338 tier,
339 key,
340 pieceLabel: "skirt",
341 description: `A light ${name.toLowerCase()} skirt for easy travel.`,
342 seedValue: 4,
343 defaultState: "skirt",
344 slot: "legs",
345 warm: false,
346 tightFit: false,
347 equipStem: "skirt"
348 });
349}
350
351function trousersDef (itemId, tier, key)
352{
353 const name = CLOTH_DISPLAY_NAME[tier] ?? tier;
354 return garmentDef({
355 itemId,
356 tier,
357 key,
358 pieceLabel: "trousers",
359 description: `Plain ${name.toLowerCase()} trousers, sturdy enough for travel.`,
360 seedValue: 5,
361 defaultState: "trousers",
362 slot: "legs",
363 warm: false,
364 equipStem: "trousers"
365 });
366}
367
368function buildClothDefinitions ()
369{
370 const defs = {};
371 for (const tier of CLOTH_TIER_ORDER)
372 {
373 const prefix = clothKeyPrefix(tier);
374 defs[RAW_ID[tier]] = fibreDef(RAW_ID[tier], tier, prefix === "fairy-silk" ? "fairy-silk" : prefix);
375 defs[YARN_ID[tier]] = yarnDef(YARN_ID[tier], tier, `${prefix}-yarn`);
376 defs[CLOTH_ID[tier]] = clothDef(CLOTH_ID[tier], tier, `${prefix}-cloth`);
377 defs[SWEATER_ID[tier]] = sweaterDef(SWEATER_ID[tier], tier, `${prefix}-sweater`);
378 defs[SHIRT_ID[tier]] = shirtDef(SHIRT_ID[tier], tier, `${prefix}-shirt`);
379 defs[SHORTS_ID[tier]] = shortsDef(SHORTS_ID[tier], tier, `${prefix}-shorts`);
380 defs[SKIRT_ID[tier]] = skirtDef(SKIRT_ID[tier], tier, `${prefix}-skirt`);
381 defs[TROUSERS_ID[tier]] = trousersDef(TROUSERS_ID[tier], tier, `${prefix}-trousers`);
382 }
383 // Prefer display key "cotton" for the plant fibre.
384 defs[ClothItemId.cotton] = fibreDef(ClothItemId.cotton, ClothTier.cotton, "cotton");
385 return Object.freeze(defs);
386}
387
388export const CLOTH_ITEM_DEFINITIONS = buildClothDefinitions();
389
390export function rawClothItemId (tier)
391{
392 return RAW_ID[tier] ?? null;
393}
394
395export function yarnItemId (tier)
396{
397 return YARN_ID[tier] ?? null;
398}
399
400export function wovenClothItemId (tier)
401{
402 return CLOTH_ID[tier] ?? null;
403}
404
405export function sweaterItemId (tier)
406{
407 return SWEATER_ID[tier] ?? null;
408}
409
410export function shirtItemId (tier)
411{
412 return SHIRT_ID[tier] ?? null;
413}
414
415export function shortsItemId (tier)
416{
417 return SHORTS_ID[tier] ?? null;
418}
419
420export function skirtItemId (tier)
421{
422 return SKIRT_ID[tier] ?? null;
423}
424
425export function trousersItemId (tier)
426{
427 return TROUSERS_ID[tier] ?? null;
428}
429
430export function clothTierForItemId (itemId)
431{
432 for (const tier of CLOTH_TIER_ORDER)
433 {
434 if (RAW_ID[tier] === itemId || YARN_ID[tier] === itemId
435 || CLOTH_ID[tier] === itemId || SWEATER_ID[tier] === itemId
436 || SHIRT_ID[tier] === itemId || SHORTS_ID[tier] === itemId
437 || SKIRT_ID[tier] === itemId || TROUSERS_ID[tier] === itemId)
438 { return tier; }
439 }
440 return null;
441}
442
443/** Tailor garment templates (UI + recipes). */
444export const CLOTHING_TEMPLATES = Object.freeze({
445 shirt: Object.freeze({
446 templateId: "shirt",
447 displayName: "Shirt",
448 slot: "chest",
449 warm: false,
450 inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]),
451 outputItemIdForTier: shirtItemId,
452 minSkillLevel: 1
453 }),
454 shorts: Object.freeze({
455 templateId: "shorts",
456 displayName: "Shorts",
457 slot: "legs",
458 warm: false,
459 inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]),
460 outputItemIdForTier: shortsItemId,
461 minSkillLevel: 1
462 }),
463 skirt: Object.freeze({
464 templateId: "skirt",
465 displayName: "Skirt",
466 slot: "legs",
467 warm: false,
468 inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]),
469 outputItemIdForTier: skirtItemId,
470 minSkillLevel: 1
471 }),
472 trousers: Object.freeze({
473 templateId: "trousers",
474 displayName: "Trousers",
475 slot: "legs",
476 warm: false,
477 inputs: Object.freeze([{ kind: "cloth", quantity: 1 }]),
478 outputItemIdForTier: trousersItemId,
479 minSkillLevel: 1
480 }),
481 sweater: Object.freeze({
482 templateId: "sweater",
483 displayName: "Sweater",
484 slot: "chest",
485 warm: true,
486 inputs: Object.freeze([{ kind: "yarn", quantity: 3 }]),
487 outputItemIdForTier: sweaterItemId,
488 minSkillLevel: 1
489 })
490});
491
492export function clothingTemplate (templateId)
493{
494 return CLOTHING_TEMPLATES[templateId] ?? null;
495}
496
497export function listClothingTemplates ()
498{
499 return Object.values(CLOTHING_TEMPLATES);
500}
501
502export { tierMinSkillLevel };