From 620b214671161e264eccd4c6e8817868be18aad1 Mon Sep 17 00:00:00 2001 From: Cay Date: Fri, 13 Mar 2026 16:56:22 +0000 Subject: [PATCH] pop23 --- public/js/buildings/wohnhaus.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/public/js/buildings/wohnhaus.js b/public/js/buildings/wohnhaus.js index c683265..8ac89e9 100644 --- a/public/js/buildings/wohnhaus.js +++ b/public/js/buildings/wohnhaus.js @@ -107,21 +107,28 @@ async function loadInventory() { } function initEquip() { + let draggedItem = null; + document.querySelectorAll(".inventory-slot").forEach((item) => { - const icon = item.querySelector("img").src; + item.addEventListener("dragstart", () => { + draggedItem = item; + }); + }); - item.addEventListener("click", () => { - const slotType = item.dataset.slot; + document.querySelectorAll(".slot").forEach((slot) => { + slot.addEventListener("dragover", (e) => { + e.preventDefault(); + }); - const target = document.querySelector( - '.slot[data-slot="' + slotType + '"]', - ); + slot.addEventListener("drop", (e) => { + e.preventDefault(); - if (!target) return; + const itemSlot = draggedItem.dataset.slot; + const targetSlot = slot.dataset.slot; - target.innerHTML = ``; + if (itemSlot !== targetSlot) return; - saveEquipment(slotType, item.dataset.id, item.dataset.level); + slot.innerHTML = draggedItem.innerHTML; }); }); }