pop35
This commit is contained in:
parent
71dd938144
commit
25671fda3d
@ -139,7 +139,7 @@ async function loadInventory() {
|
|||||||
================================ */
|
================================ */
|
||||||
|
|
||||||
function initDrag() {
|
function initDrag() {
|
||||||
document.querySelectorAll(".inventory-slot").forEach((item) => {
|
document.querySelectorAll(".inventory-slot:not(.empty)").forEach((item) => {
|
||||||
item.addEventListener("dragstart", (e) => {
|
item.addEventListener("dragstart", (e) => {
|
||||||
e.dataTransfer.setData("itemId", item.dataset.id);
|
e.dataTransfer.setData("itemId", item.dataset.id);
|
||||||
e.dataTransfer.setData("itemLevel", item.dataset.level);
|
e.dataTransfer.setData("itemLevel", item.dataset.level);
|
||||||
@ -217,18 +217,18 @@ function initDrop() {
|
|||||||
if (existing) {
|
if (existing) {
|
||||||
const grid = document.getElementById("inventory-grid");
|
const grid = document.getElementById("inventory-grid");
|
||||||
|
|
||||||
const newItem = document.createElement("div");
|
const emptySlot = grid.querySelector(".inventory-slot.empty");
|
||||||
|
|
||||||
newItem.classList.add("inventory-slot");
|
if (emptySlot) {
|
||||||
newItem.setAttribute("draggable", "true");
|
emptySlot.classList.remove("empty");
|
||||||
|
|
||||||
newItem.dataset.id = existing.dataset.id;
|
emptySlot.dataset.id = existing.dataset.id;
|
||||||
newItem.dataset.level = existing.dataset.level;
|
emptySlot.dataset.level = existing.dataset.level;
|
||||||
newItem.dataset.slot = existing.dataset.slot;
|
emptySlot.dataset.slot = existing.dataset.slot;
|
||||||
|
emptySlot.setAttribute("draggable", "true");
|
||||||
|
|
||||||
newItem.innerHTML = `<img src="${existing.src}">`;
|
emptySlot.innerHTML = `<img src="${existing.src}">`;
|
||||||
|
}
|
||||||
grid.appendChild(newItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* neues Item setzen */
|
/* neues Item setzen */
|
||||||
@ -297,7 +297,20 @@ function initInventoryDrop() {
|
|||||||
|
|
||||||
newItem.innerHTML = `<img src="${img.src}">`;
|
newItem.innerHTML = `<img src="${img.src}">`;
|
||||||
|
|
||||||
grid.appendChild(newItem);
|
const emptySlot = grid.querySelector(".inventory-slot.empty");
|
||||||
|
|
||||||
|
if (emptySlot) {
|
||||||
|
emptySlot.classList.remove("empty");
|
||||||
|
|
||||||
|
emptySlot.dataset.id = itemId;
|
||||||
|
emptySlot.dataset.level = itemLevel;
|
||||||
|
emptySlot.dataset.slot = slotName;
|
||||||
|
emptySlot.setAttribute("draggable", "true");
|
||||||
|
|
||||||
|
emptySlot.innerHTML = `<img src="${img.src}">`;
|
||||||
|
}
|
||||||
|
|
||||||
|
initDrag();
|
||||||
|
|
||||||
/* Slot leeren */
|
/* Slot leeren */
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user