ftjsrtydh

This commit is contained in:
cay 2026-04-06 16:26:04 +01:00
parent 886954178f
commit 90db689e4b
2 changed files with 66 additions and 6 deletions

View File

@ -130,6 +130,7 @@ export async function loadEvents() {
overlay.addEventListener("click", e => { if (e.target === overlay) overlay.classList.remove("active"); });
body.querySelector("#booster-back-btn").addEventListener("click", () => {
if (isSpinning || !allRevealed) return; // ← gesperrt bis alle Karten enthüllt
eventsGrid.style.display = "";
boosterUi.style.display = "none";
clearAllIntervals();
@ -139,15 +140,18 @@ export async function loadEvents() {
document.addEventListener("keydown", e => {
if (e.key === "Escape") {
overlay.classList.remove("active");
eventsGrid.style.display = "";
boosterUi.style.display = "none";
clearAllIntervals();
if (!isSpinning && allRevealed) { // ← ESC im Booster nur wenn fertig
eventsGrid.style.display = "";
boosterUi.style.display = "none";
clearAllIntervals();
}
}
});
/* ── Booster Zustand ── */
let allCards = [];
let isSpinning = false;
let allRevealed = false; // true sobald alle 5 Karten aufgedeckt + gespeichert
let spinIntervals = {}; // { index: intervalId }
let slotLocked = {}; // { index: true } → verhindert Überschreiben nach reveal
@ -170,7 +174,8 @@ export async function loadEvents() {
function resetBooster() {
clearAllIntervals();
isSpinning = false;
isSpinning = false;
allRevealed = false;
for (let i = 0; i < 5; i++) {
const inner = body.querySelector(`#booster-slot-${i} .booster-slot-inner`);
@ -238,6 +243,11 @@ export async function loadEvents() {
stapel.style.cursor = "default";
body.querySelector("#booster-hint").textContent = "Wird gezogen...";
// Zurück-Button während der Animation sperren
const backBtn = body.querySelector("#booster-back-btn");
backBtn.style.opacity = "0.35";
backBtn.style.cursor = "not-allowed";
let drawnCards = [];
try {
const res = await fetch("/api/booster/open", { method: "POST" });
@ -259,9 +269,28 @@ export async function loadEvents() {
setTimeout(() => revealSlot(i, drawnCards[i]), (i + 1) * 5000);
}
setTimeout(() => {
body.querySelector("#booster-hint").textContent = "Alle Karten enthüllt!";
setTimeout(async () => {
body.querySelector("#booster-hint").textContent = "Karten werden gespeichert...";
isSpinning = false;
// Karten in user_cards speichern
try {
const cardIds = drawnCards.map(c => c.id);
const saveRes = await fetch("/api/booster/save", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ cardIds }),
});
if (!saveRes.ok) throw new Error(saveRes.status);
} catch (e) {
console.error("Karten speichern fehlgeschlagen", e);
}
allRevealed = true;
body.querySelector("#booster-hint").textContent = "Alle Karten erhalten! ✓";
const backBtn = body.querySelector("#booster-back-btn");
backBtn.style.opacity = "1";
backBtn.style.cursor = "pointer";
}, 5 * 5000 + 500);
});

View File

@ -112,4 +112,35 @@ router.post("/booster/open", async (req, res) => {
}
});
/* ================================
POST /api/booster/save
Gezogene Karten in user_cards speichern
Body: { cardIds: [1, 2, 3, 4, 5] }
================================ */
router.post("/booster/save", async (req, res) => {
if (!req.session?.user) return res.status(401).json({ error: "Nicht eingeloggt" });
const userId = req.session.user.id;
const cardIds = req.body?.cardIds;
if (!Array.isArray(cardIds) || cardIds.length === 0) {
return res.status(400).json({ error: "Keine Karten übergeben" });
}
try {
for (const cardId of cardIds) {
await db.query(
`INSERT INTO user_cards (user_id, card_id, amount)
VALUES (?, ?, 1)
ON DUPLICATE KEY UPDATE amount = amount + 1`,
[userId, cardId]
);
}
res.json({ success: true });
} catch (err) {
console.error(err);
res.status(500).json({ error: "DB Fehler beim Speichern" });
}
});
module.exports = router;