BlueGit

timfa questward

Files

questward / shared / definitions / clothItems.js

clothItems.js

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