diff --git a/public/js/buildings/wohnhaus.js b/public/js/buildings/wohnhaus.js index 43248e3..4b910cd 100644 --- a/public/js/buildings/wohnhaus.js +++ b/public/js/buildings/wohnhaus.js @@ -77,6 +77,8 @@ async function loadEquipment() { if (label) { slot.appendChild(label); } + + slot.classList.add("has-item"); }); } @@ -175,22 +177,38 @@ function initDrop() { const itemSlot = e.dataTransfer.getData("slot"); const targetSlot = slot.dataset.slot; - console.log("Item Slot:", itemSlot); - console.log("Target Slot:", targetSlot); - if (itemSlot !== targetSlot) return; + if (!itemSlot || itemSlot !== targetSlot) return; - const icon = document.querySelector( - '.inventory-slot[data-id="' + itemId + '"] img', - ).src; + const item = document.querySelector( + '.inventory-slot[data-id="' + itemId + '"]', + ); + + const icon = item.querySelector("img").src; + + /* Wenn Slot schon Item hat */ + + const existingItem = slot.querySelector("img"); + + if (existingItem) { + const inventory = document.getElementById("inventory-grid"); + + const newSlot = document.createElement("div"); + + newSlot.classList.add("inventory-slot"); + + newSlot.innerHTML = ``; + + inventory.appendChild(newSlot); + } + + /* Neues Item setzen */ const label = slot.querySelector(".slot-label"); slot.innerHTML = ``; - if (label) { - slot.appendChild(label); - } + if (label) slot.appendChild(label); slot.classList.add("has-item");