BlueGit

timfa questward

Files

questward / shared / definitions / items.js

items.js

items.js 3.4 KiB Download Raw
1import { equipImageName, spriteImageName } from "./tileSprites.js";
2
3export const ItemId = Object.freeze({
4 paper: 1,
5 apple: 2,
6 stick: 3,
7 blankCheque: 4,
8 clothShirt: 5
9});
10
11export const EQUIPMENT_SLOT = Object.freeze({
12 head: "head",
13 chest: "chest",
14 legs: "legs",
15 boots: "boots",
16 weapon: "weapon",
17 offhand: "offhand"
18});
19
20export const EQUIPMENT_DRAW_ORDER = Object.freeze([
21 EQUIPMENT_SLOT.boots,
22 EQUIPMENT_SLOT.legs,
23 EQUIPMENT_SLOT.chest,
24 EQUIPMENT_SLOT.head,
25 EQUIPMENT_SLOT.offhand,
26 EQUIPMENT_SLOT.weapon
27]);
28
29export const DEFAULT_MAX_STACK = 99;
30
31export const ITEM_DEFINITIONS = Object.freeze({
32 [ItemId.paper]: Object.freeze({
33 itemId: ItemId.paper,
34 key: "paper",
35 displayName: "Paper",
36 description: "Blank paper. Later used to write letters.",
37 seedValue: 2,
38 stackable: true,
39 maxStackSize: DEFAULT_MAX_STACK,
40 uniqueInstance: false,
41 category: "document"
42 }),
43 [ItemId.apple]: Object.freeze({
44 itemId: ItemId.apple,
45 key: "apple",
46 displayName: "Apple",
47 description: "A placeholder fruit.",
48 seedValue: 1,
49 stackable: true,
50 maxStackSize: DEFAULT_MAX_STACK,
51 uniqueInstance: false,
52 category: "other"
53 }),
54 [ItemId.stick]: Object.freeze({
55 itemId: ItemId.stick,
56 key: "stick",
57 displayName: "Stick",
58 description: "A wooden stick. Can be wielded.",
59 seedValue: 3,
60 stackable: true,
61 maxStackSize: DEFAULT_MAX_STACK,
62 uniqueInstance: false,
63 category: "finished",
64 equipment: Object.freeze({
65 slot: EQUIPMENT_SLOT.weapon
66 })
67 }),
68 [ItemId.blankCheque]: Object.freeze({
69 itemId: ItemId.blankCheque,
70 key: "blank-cheque",
71 displayName: "Blank cheque",
72 description: "Placeholder bank paper. Filling comes with the bank.",
73 seedValue: 5,
74 stackable: true,
75 maxStackSize: DEFAULT_MAX_STACK,
76 uniqueInstance: false,
77 category: "document"
78 }),
79 [ItemId.clothShirt]: Object.freeze({
80 itemId: ItemId.clothShirt,
81 key: "cloth-shirt",
82 displayName: "Cloth shirt",
83 description: "A placeholder shirt worn on the chest.",
84 seedValue: 8,
85 stackable: false,
86 maxStackSize: 1,
87 uniqueInstance: false,
88 category: "finished",
89 equipment: Object.freeze({
90 slot: EQUIPMENT_SLOT.chest
91 })
92 })
93});
94
95export function itemDefinition (itemId)
96{
97 return ITEM_DEFINITIONS[itemId] ?? null;
98}
99
100export function itemDefaultState (def)
101{
102 return def?.defaultState ?? def?.key ?? "paper";
103}
104
105export function itemSpriteName (itemId)
106{
107 const def = itemDefinition(itemId);
108 if (!def)
109 { return spriteImageName("item", "paper", "paper"); }
110 return def.sprite ?? spriteImageName("item", def.key, itemDefaultState(def));
111}
112
113export function itemEquipSprite (itemId)
114{
115 const def = itemDefinition(itemId);
116 const equipment = def?.equipment;
117 if (!equipment)
118 { return null; }
119 return equipment.equipSprite
120 ?? equipment.overlaySpriteId
121 ?? equipImageName("item", def.key, itemDefaultState(def));
122}
123
124export function itemAssetPath (itemId, companion = null)
125{
126 const def = itemDefinition(itemId);
127 const key = def?.key ?? "paper";
128 const state = itemDefaultState(def ?? { key });
129 const suffix = companion ? `-${companion}` : "";
130 return `/assets/items/${key}/${state}${suffix}.png`;
131}
132
133export const STARTER_CURRENCY = 25;
134export const STARTER_ITEMS = Object.freeze([
135 Object.freeze({ itemId: ItemId.paper, quantity: 5 }),
136 Object.freeze({ itemId: ItemId.apple, quantity: 3 }),
137 Object.freeze({ itemId: ItemId.stick, quantity: 1 }),
138 Object.freeze({ itemId: ItemId.clothShirt, quantity: 1 })
139]);