e35zuq3
This commit is contained in:
parent
1603503569
commit
8c72ce0bba
72
app.js
72
app.js
@ -151,10 +151,10 @@ app.get("/api/building/:id", requireLogin, async (req, res) => {
|
||||
upgradeCost: nextLevel[0]
|
||||
? `${nextLevel[0].wood} Holz, ${nextLevel[0].stone} Stein, ${nextLevel[0].gold} Gold`
|
||||
: "Max Level erreicht",
|
||||
upgradeWood: nextLevel[0]?.wood ?? null,
|
||||
upgradeStone: nextLevel[0]?.stone ?? null,
|
||||
upgradeGold: nextLevel[0]?.gold ?? null,
|
||||
upgradeRequiredPoints: nextLevel[0]?.required_points ?? null, // NEU
|
||||
upgradeWood: nextLevel[0]?.wood ?? null,
|
||||
upgradeStone: nextLevel[0]?.stone ?? null,
|
||||
upgradeGold: nextLevel[0]?.gold ?? null,
|
||||
upgradeRequiredPoints: nextLevel[0]?.required_points ?? null, // NEU
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@ -190,7 +190,9 @@ app.post("/api/building/:id/upgrade", requireLogin, async (req, res) => {
|
||||
);
|
||||
|
||||
if (!levelData) {
|
||||
return res.status(400).json({ error: "Maximales Level bereits erreicht" });
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: "Maximales Level bereits erreicht" });
|
||||
}
|
||||
|
||||
// Punkte prüfen
|
||||
@ -210,11 +212,23 @@ app.post("/api/building/:id/upgrade", requireLogin, async (req, res) => {
|
||||
return res.status(400).json({ error: "Keine Währungsdaten gefunden" });
|
||||
}
|
||||
|
||||
if (currency.wood < levelData.wood || currency.stone < levelData.stone || currency.gold < levelData.gold) {
|
||||
if (
|
||||
currency.wood < levelData.wood ||
|
||||
currency.stone < levelData.stone ||
|
||||
currency.gold < levelData.gold
|
||||
) {
|
||||
return res.status(400).json({
|
||||
error: "Nicht genügend Ressourcen",
|
||||
required: { wood: levelData.wood, stone: levelData.stone, gold: levelData.gold },
|
||||
current: { wood: currency.wood, stone: currency.stone, gold: currency.gold },
|
||||
required: {
|
||||
wood: levelData.wood,
|
||||
stone: levelData.stone,
|
||||
gold: levelData.gold,
|
||||
},
|
||||
current: {
|
||||
wood: currency.wood,
|
||||
stone: currency.stone,
|
||||
gold: currency.gold,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -233,7 +247,11 @@ app.post("/api/building/:id/upgrade", requireLogin, async (req, res) => {
|
||||
res.json({
|
||||
success: true,
|
||||
newLevel: nextLevel,
|
||||
cost: { wood: levelData.wood, stone: levelData.stone, gold: levelData.gold },
|
||||
cost: {
|
||||
wood: levelData.wood,
|
||||
stone: levelData.stone,
|
||||
gold: levelData.gold,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@ -297,6 +315,42 @@ app.get("/api/buildings", requireLogin, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/* ========================
|
||||
Cards API
|
||||
======================== */
|
||||
|
||||
app.get("/api/cards", requireLogin, async (req, res) => {
|
||||
const { race, page = 1, limit = 12 } = req.query;
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
try {
|
||||
const [cards] = await db.query(
|
||||
`SELECT c.*, cg.name AS group_name, cg.color AS group_color,
|
||||
cl.attack, cl.defense, cl.cooldown
|
||||
FROM cards c
|
||||
LEFT JOIN card_groups cg ON cg.id = c.group_id
|
||||
LEFT JOIN card_levels cl ON cl.card_id = c.id AND cl.level = 1
|
||||
WHERE c.race = ?
|
||||
LIMIT ? OFFSET ?`,
|
||||
[race, parseInt(limit), parseInt(offset)],
|
||||
);
|
||||
const [[{ total }]] = await db.query(
|
||||
"SELECT COUNT(*) as total FROM cards WHERE race = ?",
|
||||
[race],
|
||||
);
|
||||
|
||||
res.json({
|
||||
cards,
|
||||
total,
|
||||
page: parseInt(page),
|
||||
totalPages: Math.ceil(total / limit),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: "DB Fehler" });
|
||||
}
|
||||
});
|
||||
|
||||
/* ========================
|
||||
Body Parser
|
||||
======================== */
|
||||
|
||||
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
337
public/js/lucky-box.js
Normal file
337
public/js/lucky-box.js
Normal file
@ -0,0 +1,337 @@
|
||||
const CARDS_PER_PAGE = 12;
|
||||
|
||||
const RACES = [
|
||||
{ id: "menschen", label: "Menschen", icon: "⚔️" },
|
||||
{ id: "elfen", label: "Elfen", icon: "🌿" },
|
||||
{ id: "zwerge", label: "Zwerge", icon: "⛏️" },
|
||||
{ id: "orks", label: "Orks", icon: "💀" },
|
||||
{ id: "untote", label: "Untote", icon: "💀" },
|
||||
{ id: "drachen", label: "Drachen", icon: "🐉" },
|
||||
];
|
||||
|
||||
let currentRace = RACES[0].id;
|
||||
let currentPage = 1;
|
||||
|
||||
export async function loadLuckyBox() {
|
||||
const body = document.getElementById("qm-body-glucksbox");
|
||||
if (!body) return;
|
||||
|
||||
body.innerHTML = renderShell();
|
||||
attachTabEvents();
|
||||
await loadCards();
|
||||
}
|
||||
|
||||
/* ── HTML-Grundstruktur ─────────────────────── */
|
||||
function renderShell() {
|
||||
const tabs = RACES.map((r, i) => `
|
||||
<button class="kd-tab ${i === 0 ? "kd-tab-active" : ""}" data-race="${r.id}">
|
||||
<span class="kd-tab-icon">${r.icon}</span>
|
||||
<span class="kd-tab-label">${r.label}</span>
|
||||
</button>
|
||||
`).join("");
|
||||
|
||||
return `
|
||||
<div class="kd-wrap">
|
||||
<aside class="kd-tabs">${tabs}</aside>
|
||||
<main class="kd-main">
|
||||
<div class="kd-grid" id="kd-grid"></div>
|
||||
<div class="kd-pagination" id="kd-pagination"></div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.kd-wrap {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
gap: 0;
|
||||
font-family: "Cinzel", serif;
|
||||
}
|
||||
|
||||
/* ── Tabs ── */
|
||||
.kd-tabs {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 20px 10px;
|
||||
background: rgba(0,0,0,0.25);
|
||||
border-right: 2px solid #6b4b2a;
|
||||
min-width: 130px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.kd-tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 14px;
|
||||
background: linear-gradient(135deg, #2a1a08, #1a0f04);
|
||||
border: 1px solid #6b4b2a;
|
||||
border-radius: 8px;
|
||||
color: #c8a86a;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.kd-tab:hover {
|
||||
border-color: #f0d060;
|
||||
color: #f0d9a6;
|
||||
background: linear-gradient(135deg, #3a2810, #2a1a08);
|
||||
box-shadow: 0 0 10px rgba(200,160,60,0.2);
|
||||
}
|
||||
|
||||
.kd-tab-active {
|
||||
background: linear-gradient(135deg, #6b4b2a, #3c2414) !important;
|
||||
border-color: #f0d060 !important;
|
||||
color: #fff5cc !important;
|
||||
box-shadow: inset 0 0 10px rgba(0,0,0,0.4), 0 0 12px rgba(200,160,60,0.3) !important;
|
||||
}
|
||||
|
||||
.kd-tab-icon { font-size: 18px; }
|
||||
|
||||
/* ── Main ── */
|
||||
.kd-main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 20px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Grid ── */
|
||||
.kd-grid {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(6, 1fr);
|
||||
gap: 14px;
|
||||
overflow-y: auto;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
/* ── Karte ── */
|
||||
.kd-card {
|
||||
position: relative;
|
||||
border: 2px solid #6b4b2a;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: #1a0f04;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
|
||||
aspect-ratio: 3/4;
|
||||
}
|
||||
|
||||
.kd-card:hover {
|
||||
transform: scale(1.05) translateY(-4px);
|
||||
border-color: #f0d060;
|
||||
box-shadow: 0 8px 24px rgba(0,0,0,0.7), 0 0 14px rgba(200,160,60,0.3);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.kd-card img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.kd-card-name {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 4px 6px;
|
||||
background: linear-gradient(transparent, rgba(0,0,0,0.85));
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 10px;
|
||||
color: #f0d9a6;
|
||||
text-align: center;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
/* Angriff / Verteidigung Badges */
|
||||
.kd-stat-atk {
|
||||
position: absolute;
|
||||
bottom: 28px;
|
||||
left: 5px;
|
||||
background: rgba(180,40,20,0.85);
|
||||
border: 1px solid #ff6040;
|
||||
border-radius: 4px;
|
||||
color: #fff;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 11px;
|
||||
font-weight: bold;
|
||||
padding: 1px 5px;
|
||||
}
|
||||
|
||||
.kd-stat-def {
|
||||
position: absolute;
|
||||
bottom: 28px;
|
||||
right: 5px;
|
||||
background: rgba(20,80,180,0.85);
|
||||
border: 1px solid #4090ff;
|
||||
border-radius: 4px;
|
||||
color: #fff;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 11px;
|
||||
font-weight: bold;
|
||||
padding: 1px 5px;
|
||||
}
|
||||
|
||||
/* ── Leer-Zustand ── */
|
||||
.kd-empty {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
color: #8b6a3c;
|
||||
font-size: 16px;
|
||||
padding: 60px 0;
|
||||
}
|
||||
|
||||
/* ── Pagination ── */
|
||||
.kd-pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
padding-top: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.kd-page-btn {
|
||||
background: linear-gradient(#3a2810, #1a0f04);
|
||||
border: 1px solid #8b6a3c;
|
||||
border-radius: 6px;
|
||||
color: #f0d9a6;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 12px;
|
||||
padding: 5px 14px;
|
||||
cursor: pointer;
|
||||
transition: 0.15s;
|
||||
}
|
||||
|
||||
.kd-page-btn:hover {
|
||||
border-color: #f0d060;
|
||||
background: linear-gradient(#5a3820, #2a1404);
|
||||
}
|
||||
|
||||
.kd-page-btn:disabled {
|
||||
opacity: 0.35;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.kd-page-btn.kd-page-active {
|
||||
background: linear-gradient(#6b4b2a, #3c2414);
|
||||
border-color: #f0d060;
|
||||
color: #fff5cc;
|
||||
}
|
||||
|
||||
.kd-page-info {
|
||||
color: #a08060;
|
||||
font-size: 12px;
|
||||
min-width: 80px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ── Loading ── */
|
||||
.kd-loading {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
color: #8b6a3c;
|
||||
font-size: 15px;
|
||||
padding: 60px 0;
|
||||
animation: kd-pulse 1.2s infinite;
|
||||
}
|
||||
|
||||
@keyframes kd-pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.4; }
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
}
|
||||
|
||||
/* ── Tab-Klick ─────────────────────────────── */
|
||||
function attachTabEvents() {
|
||||
document.querySelectorAll(".kd-tab").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
document.querySelectorAll(".kd-tab").forEach((b) => b.classList.remove("kd-tab-active"));
|
||||
btn.classList.add("kd-tab-active");
|
||||
currentRace = btn.dataset.race;
|
||||
currentPage = 1;
|
||||
await loadCards();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ── Karten laden ───────────────────────────── */
|
||||
async function loadCards() {
|
||||
const grid = document.getElementById("kd-grid");
|
||||
const pagination = document.getElementById("kd-pagination");
|
||||
if (!grid) return;
|
||||
|
||||
grid.innerHTML = `<div class="kd-loading">Lade Karten...</div>`;
|
||||
pagination.innerHTML = "";
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/cards?race=${currentRace}&page=${currentPage}&limit=${CARDS_PER_PAGE}`);
|
||||
if (!res.ok) throw new Error("API Fehler");
|
||||
const data = await res.json();
|
||||
// data = { cards: [...], total: N, page: N, totalPages: N }
|
||||
|
||||
renderGrid(grid, data.cards);
|
||||
renderPagination(pagination, data.totalPages, data.total);
|
||||
} catch {
|
||||
grid.innerHTML = `<div class="kd-empty">Noch keine Karten für diese Rasse vorhanden.</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Grid rendern ───────────────────────────── */
|
||||
function renderGrid(grid, cards) {
|
||||
if (!cards || !cards.length) {
|
||||
grid.innerHTML = `<div class="kd-empty">Noch keine Karten für diese Rasse vorhanden.</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
grid.innerHTML = cards.map((c) => `
|
||||
<div class="kd-card" title="${c.name}">
|
||||
<img src="/images/cards/${c.image}" alt="${c.name}"
|
||||
onerror="this.src='/images/cards/placeholder.png'">
|
||||
${c.attack !== undefined ? `<span class="kd-stat-atk">${c.attack}</span>` : ""}
|
||||
${c.defense !== undefined ? `<span class="kd-stat-def">${c.defense}</span>` : ""}
|
||||
<div class="kd-card-name">${c.name}</div>
|
||||
</div>
|
||||
`).join("");
|
||||
}
|
||||
|
||||
/* ── Pagination rendern ─────────────────────── */
|
||||
function renderPagination(pagination, totalPages, total) {
|
||||
if (totalPages <= 1) return;
|
||||
|
||||
const pages = Array.from({ length: totalPages }, (_, i) => i + 1);
|
||||
|
||||
pagination.innerHTML = `
|
||||
<button class="kd-page-btn" id="kd-prev" ${currentPage === 1 ? "disabled" : ""}>◀</button>
|
||||
${pages.map((p) => `
|
||||
<button class="kd-page-btn ${p === currentPage ? "kd-page-active" : ""}" data-page="${p}">${p}</button>
|
||||
`).join("")}
|
||||
<button class="kd-page-btn" id="kd-next" ${currentPage === totalPages ? "disabled" : ""}>▶</button>
|
||||
<span class="kd-page-info">${total} Karten</span>
|
||||
`;
|
||||
|
||||
document.getElementById("kd-prev")?.addEventListener("click", async () => {
|
||||
if (currentPage > 1) { currentPage--; await loadCards(); }
|
||||
});
|
||||
document.getElementById("kd-next")?.addEventListener("click", async () => {
|
||||
if (currentPage < totalPages) { currentPage++; await loadCards(); }
|
||||
});
|
||||
pagination.querySelectorAll("[data-page]").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
currentPage = parseInt(btn.dataset.page);
|
||||
await loadCards();
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user