BlueGit

timfa questward

Files

questward / shared / definitions / clothItems.js

clothItems.js

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