export async function loadWohnhaus() { const ui = document.querySelector(".building-ui"); ui.innerHTML = `

Inventar

`; loadInventory(); loadEquipment(); } async function loadEquipment() { const res = await fetch("/api/equipment"); const equipment = await res.json(); equipment.forEach((item) => { const slot = document.querySelector( '.equip-slot[data-slot="' + item.slot + '"]', ); if (!slot) return; slot.innerHTML = ``; }); } async function loadInventory() { const res = await fetch("/api/inventory"); const items = await res.json(); const grid = document.getElementById("inventory-grid"); let html = ""; items.forEach((item) => { const icon = item.icon || "/images/items/default.png"; html += `
`; }); grid.innerHTML = html; initEquip(); } function initEquip() { document.querySelectorAll(".inventory-slot").forEach((item) => { const icon = item.querySelector("img").src; item.addEventListener("click", () => { const slotType = item.dataset.slot; const target = document.querySelector( '.equip-slot[data-slot="' + slotType + '"]', ); if (!target) return; target.innerHTML = ``; saveEquipment(slotType, item.dataset.id, item.dataset.level); }); }); } async function saveEquipment(slot, itemId, itemLevelId) { await fetch("/api/equip", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ slot: slot, itemId: itemId, itemLevelId: itemLevelId, }), }); }