BlueGit

timfa questward

Files

questward / shared / definitions / clothItems.js

clothItems.js

clothItems.js 6.6 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 */
16export 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
47const 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
57const 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
67const 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
77const 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
87const DEFAULT_STACK = 99;
88
89function rawLabel (tier)
90{
91 if (tier === ClothTier.cotton)
92 { return "Cotton"; }
93 return CLOTH_DISPLAY_NAME[tier] ?? tier;
94}
95
96function 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
116function 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
136function 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
156function 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. Mostly cosmetic for now; optional dye overrides the material colour.`,
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 clothing: Object.freeze({ warm: true, style: true }),
174 equipment: Object.freeze({
175 slot: "chest",
176 tier,
177 kind: EquipmentKind.clothArmour,
178 bonus: 0,
179 minSkillLevel: tierMinSkillLevel(tier),
180 tintFromTier: true,
181 equipSprite: equipImageName("item", "clothing", "sweater")
182 })
183 });
184}
185
186function buildClothDefinitions ()
187{
188 const defs = {};
189 for (const tier of CLOTH_TIER_ORDER)
190 {
191 const label = String(tier);
192 defs[RAW_ID[tier]] = fibreDef(RAW_ID[tier], tier, label === "fairySilk" ? "fairy-silk" : label);
193 defs[YARN_ID[tier]] = yarnDef(
194 YARN_ID[tier],
195 tier,
196 `${label === "fairySilk" ? "fairy-silk" : label}-yarn`
197 );
198 defs[CLOTH_ID[tier]] = clothDef(
199 CLOTH_ID[tier],
200 tier,
201 `${label === "fairySilk" ? "fairy-silk" : label}-cloth`
202 );
203 defs[SWEATER_ID[tier]] = sweaterDef(
204 SWEATER_ID[tier],
205 tier,
206 `${label === "fairySilk" ? "fairy-silk" : label}-sweater`
207 );
208 }
209 // Prefer display key "cotton" for the plant fibre.
210 defs[ClothItemId.cotton] = fibreDef(ClothItemId.cotton, ClothTier.cotton, "cotton");
211 return Object.freeze(defs);
212}
213
214export const CLOTH_ITEM_DEFINITIONS = buildClothDefinitions();
215
216export function rawClothItemId (tier)
217{
218 return RAW_ID[tier] ?? null;
219}
220
221export function yarnItemId (tier)
222{
223 return YARN_ID[tier] ?? null;
224}
225
226export function wovenClothItemId (tier)
227{
228 return CLOTH_ID[tier] ?? null;
229}
230
231export function sweaterItemId (tier)
232{
233 return SWEATER_ID[tier] ?? null;
234}
235
236export function clothTierForItemId (itemId)
237{
238 for (const tier of CLOTH_TIER_ORDER)
239 {
240 if (RAW_ID[tier] === itemId || YARN_ID[tier] === itemId
241 || CLOTH_ID[tier] === itemId || SWEATER_ID[tier] === itemId)
242 { return tier; }
243 }
244 return null;
245}
246
247/** Tailor garment templates (UI + recipes). */
248export const CLOTHING_TEMPLATES = Object.freeze({
249 sweater: Object.freeze({
250 templateId: "sweater",
251 displayName: "Sweater",
252 slot: "chest",
253 warm: true,
254 inputs: Object.freeze([{ kind: "yarn", quantity: 3 }]),
255 outputItemIdForTier: sweaterItemId,
256 minSkillLevel: 1
257 })
258});
259
260export function clothingTemplate (templateId)
261{
262 return CLOTHING_TEMPLATES[templateId] ?? null;
263}
264
265export function listClothingTemplates ()
266{
267 return Object.values(CLOTHING_TEMPLATES);
268}
269
270export { tierMinSkillLevel };