različne velikosti dreves

This commit is contained in:
2025-12-07 03:40:50 +01:00
parent 9eb57ed117
commit 521468c797
8 changed files with 323 additions and 109 deletions

View File

@@ -165,24 +165,56 @@ class UIScene extends Phaser.Scene {
updateInventory(slots) {
if (!this.inventorySlots) return;
for (let i = 0; i < this.inventorySlots.length; i++) {
const slotGraphics = this.inventorySlots[i];
// Clear previous item info (we stored it in container? No, just graphics)
// Ideally slots should be containers.
// For now, let's just redraw the slot and add text on top.
// To do this cleanly, let's remove old item text/sprites if we track them.
if (slotGraphics.itemText) slotGraphics.itemText.destroy();
// Clean up old visual elements
if (slotGraphics.itemSprite) {
slotGraphics.itemSprite.destroy();
slotGraphics.itemSprite = null;
}
if (slotGraphics.itemText) {
slotGraphics.itemText.destroy();
slotGraphics.itemText = null;
}
if (slotGraphics.countText) {
slotGraphics.countText.destroy();
slotGraphics.countText = null;
}
if (slots[i]) {
const { x, y, size } = slotGraphics.userData;
// Simple representation: Text
const text = this.add.text(x + size / 2, y + size / 2,
`${slots[i].type.substring(0, 2)}\n${slots[i].count}`,
{ fontSize: '10px', align: 'center', color: '#ffff00' }
).setOrigin(0.5);
const type = slots[i].type;
const textureKey = `item_${type}`; // e.g., item_axe, item_wood
slotGraphics.itemText = text;
// Check if texture exists
if (this.textures.exists(textureKey)) {
// Draw Sprite
const sprite = this.add.sprite(x + size / 2, y + size / 2, textureKey);
// Scale to fit slot (32px slot, maybe 24px icon)
const scale = (size - 8) / Math.max(sprite.width, sprite.height);
sprite.setScale(scale);
slotGraphics.itemSprite = sprite;
} else {
// Fallback Text
const text = this.add.text(x + size / 2, y + size / 2,
type.substring(0, 2).toUpperCase(),
{ fontSize: '12px', align: 'center', color: '#ffff00', stroke: '#000', strokeThickness: 2 }
).setOrigin(0.5);
slotGraphics.itemText = text;
}
// Draw Count (if > 1)
if (slots[i].count > 1) {
const countText = this.add.text(x + size - 2, y + size - 2,
slots[i].count.toString(),
{ fontSize: '10px', align: 'right', color: '#ffffff', stroke: '#000', strokeThickness: 2 }
).setOrigin(1, 1);
slotGraphics.countText = countText;
}
}
}
}