Skip to content

Commit 16195cd

Browse files
committed
Fix draw
1 parent 3fd2c30 commit 16195cd

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/commands/inventar.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,41 +160,44 @@ export default class InventarCommand implements ApplicationCommand {
160160
}
161161
}
162162

163-
type CircleItem = { path: string; target: Vec2; size?: Vec2 };
163+
const size = new Vec2(80, 80);
164+
165+
type CircleItem = { path: string; target: Vec2; size: Vec2 };
164166
const lookup: Partial<Record<lootDataService.LootKindId, CircleItem>> = {
165167
[lootDataService.LootKind.BABYBEL_CHEDDAR]: {
166168
path: "assets/inventory/bb-cheddar.png",
167-
target: new Vec2(42, 200),
168-
size: new Vec2(40, 40),
169+
target: new Vec2(200, 42),
170+
size,
169171
},
170172
[lootDataService.LootKind.BABYBEL_EMMENTALER]: {
171173
path: "assets/inventory/bb-emmentaler.png",
172174
target: new Vec2(61, 120),
173-
size: new Vec2(40, 40),
175+
size,
174176
},
175177
[lootDataService.LootKind.BABYBEL_GOUDA]: {
176178
path: "assets/inventory/bb-gouda.png",
177179
target: new Vec2(337, 120),
178-
size: new Vec2(40, 40),
180+
size,
179181
},
180182
[lootDataService.LootKind.BABYBEL_LIGHT]: {
181183
path: "assets/inventory/bb-light.png",
182184
target: new Vec2(337, 276),
185+
size,
183186
},
184187
[lootDataService.LootKind.BABYBEL_ORIGINAL]: {
185188
path: "assets/inventory/bb-original.png",
186189
target: new Vec2(200, 200),
187-
size: new Vec2(40, 40),
190+
size,
188191
},
189192
[lootDataService.LootKind.BABYBEL_PROTEIN]: {
190193
path: "assets/inventory/bb-protein.png",
191194
target: new Vec2(61, 276),
192-
size: new Vec2(40, 40),
195+
size,
193196
},
194197
[lootDataService.LootKind.BABYBEL_VEGAN]: {
195198
path: "assets/inventory/bb-vegan.png",
196199
target: new Vec2(200, 353),
197-
size: new Vec2(40, 40),
200+
size,
198201
},
199202
};
200203

@@ -209,21 +212,15 @@ async function drawBbCircle(contents: Set<lootDataService.LootKindId>) {
209212

210213
for (const id of contents) {
211214
const entry = lookup[id];
212-
if (!entry) continue;
215+
if (!entry) {
216+
continue;
217+
}
213218

214219
try {
215220
const buf = await fs.readFile(entry.path);
216221
const img = await loadImage(buf);
217222

218-
// center all images: compute draw position by subtracting half of the image dimensions
219-
const offset = new Vec2(img.width / 2, img.height / 2);
220-
const drawPos = entry.target.minus(offset);
221-
222-
if (entry.size) {
223-
ctx.drawImageEx(drawPos, entry.size, img);
224-
} else {
225-
ctx.drawImage(img, drawPos.x, drawPos.y);
226-
}
223+
ctx.drawImageEx(entry.target.minus(entry.size.scale(0.5)), entry.size, img);
227224
} catch (err) {
228225
log.warn(`Failed to draw inventory item '${id}': ${err}`);
229226
}

0 commit comments

Comments
 (0)