Compare commits

..

No commits in common. "07c5c5efa710ceeb87cd4102d81d62f554508237" and "a8bb5f90e5a60f53f555584507c24e9c5e90bee1" have entirely different histories.

3 changed files with 18 additions and 59 deletions

View File

@ -505,13 +505,6 @@ body {
transform: scale(1.1);
}
#inv-left:disabled,
#inv-right:disabled {
opacity: 0.25;
cursor: not-allowed;
transform: none;
}
#inventory-nav {
display: flex;
align-items: center;

View File

@ -1,7 +1,6 @@
let inventoryPage = 0;
const slotsPerPage = 32;
let inventoryItems = [];
let totalInventoryPages = 1;
export async function loadWohnhaus() {
const ui = document.querySelector(".building-ui");
@ -63,16 +62,9 @@ export async function loadWohnhaus() {
<button id="inv-right">&#9658;</button>
</div>`;
// Variablen zurücksetzen beim Öffnen
inventoryPage = 0;
totalInventoryPages = 1;
inventoryItems = [];
// Buttons zuerst initialisieren
initInventoryButtons();
await loadInventory();
await loadEquipment();
initInventoryButtons();
initDrag();
initSlotDrag();
initDrop();
@ -84,9 +76,7 @@ export async function loadWohnhaus() {
================================ */
function updateAvatarOverlay(slotName, iconSrc) {
const overlay = document.querySelector(
`.avatar-overlay[data-slot="${slotName}"]`,
);
const overlay = document.querySelector(`.avatar-overlay[data-slot="${slotName}"]`);
if (!overlay) return;
const img = overlay.querySelector("img");
@ -96,9 +86,7 @@ function updateAvatarOverlay(slotName, iconSrc) {
overlay.classList.add("visible");
} else {
overlay.classList.remove("visible");
setTimeout(() => {
img.src = "";
}, 250);
setTimeout(() => { img.src = ""; }, 250);
}
}
@ -108,11 +96,7 @@ function updateAvatarOverlay(slotName, iconSrc) {
async function loadInventory() {
const res = await fetch("/api/inventory");
const data = await res.json();
inventoryItems = data.items;
totalInventoryPages = data.totalPages;
inventoryItems = await res.json();
renderInventory();
}
@ -147,15 +131,9 @@ function renderInventory() {
grid.innerHTML = html;
const totalPages = Math.max(1, Math.ceil(inventoryItems.length / slotsPerPage));
document.getElementById("inventory-page").innerText =
"Seite " + (inventoryPage + 1) + " / " + totalInventoryPages;
// Buttons aktivieren/deaktivieren
const btnLeft = document.getElementById("inv-left");
const btnRight = document.getElementById("inv-right");
if (btnLeft) btnLeft.disabled = inventoryPage === 0;
if (btnRight) btnRight.disabled = inventoryPage >= totalInventoryPages - 1;
"Seite " + (inventoryPage + 1) + " / " + totalPages;
initDrag();
}
@ -173,7 +151,8 @@ function initInventoryButtons() {
};
document.getElementById("inv-right").onclick = () => {
if (inventoryPage < totalInventoryPages - 1) {
const totalPages = Math.max(1, Math.ceil(inventoryItems.length / slotsPerPage));
if (inventoryPage < totalPages - 1) {
inventoryPage++;
renderInventory();
}
@ -260,17 +239,13 @@ function initDrop() {
let icon;
if (source === "inventory") {
const inventoryItem = document.querySelector(
'.inventory-slot[data-id="' + itemId + '"]',
);
const inventoryItem = document.querySelector('.inventory-slot[data-id="' + itemId + '"]');
if (!inventoryItem) return;
icon = inventoryItem.querySelector("img").src;
inventoryItem.classList.add("empty");
inventoryItem.innerHTML = "";
} else {
const slotItem = document.querySelector(
'.slot[data-slot="' + itemSlot + '"] img',
);
const slotItem = document.querySelector('.slot[data-slot="' + itemSlot + '"] img');
if (!slotItem) return;
icon = slotItem.src;
}

View File

@ -24,16 +24,7 @@ WHERE user_inventory.user_id=?
[userId],
);
// Gekaufte Seiten laden
const [ownedPages] = await db.query(
`SELECT COUNT(*) as total FROM user_inventory_pages WHERE user_id = ?`,
[userId],
);
// Seite 1 ist immer kostenlos
const totalPages = Math.max(1, ownedPages[0].total);
res.json({ items, totalPages });
res.json(items);
} catch (err) {
console.error("Inventory Fehler:", err);
res.status(500).json({ error: "DB Fehler" });