frtsjrt
This commit is contained in:
parent
c1c752874f
commit
51ca9a27f4
@ -227,7 +227,8 @@
|
||||
padding: 16px 10px;
|
||||
background: rgba(0, 0, 0, 0.25);
|
||||
border-right: 2px solid #8b6a3c;
|
||||
min-width: 160px;
|
||||
min-width: 140px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.gaststaette-tab {
|
||||
@ -245,32 +246,29 @@
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.gaststaette-tab:hover {
|
||||
border-color: #f0d060;
|
||||
background: linear-gradient(145deg, #5a3c18, #2a1a08);
|
||||
}
|
||||
|
||||
.gaststaette-tab.active {
|
||||
background: linear-gradient(145deg, #6b4b2a, #3c2414);
|
||||
border-color: #f0d060;
|
||||
color: #f0d060;
|
||||
box-shadow: inset 0 0 8px rgba(0,0,0,0.5);
|
||||
}
|
||||
|
||||
.gaststaette-content {
|
||||
flex: 1;
|
||||
padding: 24px 40px;
|
||||
overflow-y: auto;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 16px;
|
||||
color: #5c3b20;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.gaststaette-tab-content {
|
||||
display: none;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.gaststaette-tab-content.active {
|
||||
display: block;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
641
public/js/gaststaette/glucksspiel.js
Normal file
641
public/js/gaststaette/glucksspiel.js
Normal file
@ -0,0 +1,641 @@
|
||||
/* ============================================================
|
||||
public/js/gaststaette/glucksspiel.js
|
||||
Glücksspiel-Tab in der Gaststätte
|
||||
– Karten nach Fraktion anzeigen (wie Kartendeck)
|
||||
– Karten gleicher ID ins Kombinier-Feld legen
|
||||
– "Kombinieren"-Button
|
||||
============================================================ */
|
||||
|
||||
const CARDS_PER_PAGE = 18;
|
||||
|
||||
const RARITY_CRYSTALS = {
|
||||
1: "roter-cristal.png",
|
||||
2: "blauer-cristal.png",
|
||||
3: "gelber-cristal.png",
|
||||
4: "gruener-cristal.png",
|
||||
5: "oranger-cristal.png",
|
||||
6: "violet-cristal.png",
|
||||
7: "pinker-cristal.png",
|
||||
};
|
||||
|
||||
function rarityImgs(rarity, size = 13) {
|
||||
const file = RARITY_CRYSTALS[String(rarity)];
|
||||
if (!file) return "";
|
||||
const count = parseInt(rarity) || 0;
|
||||
const img = `<img src="/images/items/${file}" alt="Stufe ${rarity}"
|
||||
style="width:${size}px;height:${size}px;object-fit:contain;filter:drop-shadow(0 1px 2px rgba(0,0,0,0.8));">`;
|
||||
return img.repeat(count);
|
||||
}
|
||||
|
||||
// State
|
||||
let gs_groupId = null;
|
||||
let gs_page = 1;
|
||||
let gs_cards = []; // aktuelle Seite
|
||||
let gs_combineId = null; // card_id der Karte im Kombinier-Feld
|
||||
let gs_combineCards = []; // [{card_id, name, image, rarity, attack, defends, cooldown}] im Feld
|
||||
let gs_initialized = false;
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
INIT
|
||||
══════════════════════════════════════════════ */
|
||||
export async function loadGlucksspiel() {
|
||||
const container = document.getElementById("gs-tab1");
|
||||
if (!container) return;
|
||||
|
||||
// Nur beim ersten Aufruf rendern
|
||||
if (gs_initialized) return;
|
||||
gs_initialized = true;
|
||||
|
||||
container.innerHTML = renderShell();
|
||||
attachCombineEvents();
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/card-groups");
|
||||
if (!res.ok) throw new Error();
|
||||
const groups = await res.json();
|
||||
renderTabs(groups);
|
||||
if (groups.length) {
|
||||
gs_groupId = groups[0].id;
|
||||
await loadCards();
|
||||
}
|
||||
} catch {
|
||||
container.innerHTML = `<p style="color:#8b6a3c;padding:20px;font-family:'Cinzel',serif;">Fehler beim Laden.</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
SHELL
|
||||
══════════════════════════════════════════════ */
|
||||
function renderShell() {
|
||||
return `
|
||||
<div class="gs-wrap">
|
||||
|
||||
<!-- Linke Tab-Leiste (Fraktionen) -->
|
||||
<aside class="gs-faction-tabs" id="gs-faction-tabs">
|
||||
<div class="gs-loading">Lade...</div>
|
||||
</aside>
|
||||
|
||||
<!-- Mittlere Spalte: Karten-Sammlung -->
|
||||
<div class="gs-collection">
|
||||
<div class="gs-col-header">Meine Karten</div>
|
||||
<div class="gs-grid" id="gs-grid">
|
||||
<div class="gs-loading">Lade Karten...</div>
|
||||
</div>
|
||||
<div class="gs-pagination" id="gs-pagination"></div>
|
||||
</div>
|
||||
|
||||
<!-- Rechte Spalte: Kombinier-Feld -->
|
||||
<div class="gs-combine-panel">
|
||||
<div class="gs-col-header">Kombinieren</div>
|
||||
<div class="gs-combine-hint" id="gs-combine-hint">
|
||||
Klicke auf eine Karte links um sie hier zu platzieren.<br>
|
||||
Nur Karten gleicher Art können kombiniert werden.
|
||||
</div>
|
||||
<div class="gs-combine-grid" id="gs-combine-grid"></div>
|
||||
<div class="gs-combine-count" id="gs-combine-count"></div>
|
||||
<button class="gs-combine-btn" id="gs-combine-btn" disabled>Kombinieren</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* ── Layout ─────────────────────────────── */
|
||||
.gs-wrap {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: "Cinzel", serif;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ── Fraktions-Tabs (ganz links) ─────────── */
|
||||
.gs-faction-tabs {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 14px 10px;
|
||||
background: rgba(0,0,0,0.3);
|
||||
border-right: 2px solid #6b4b2a;
|
||||
min-width: 140px;
|
||||
flex-shrink: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.gs-tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 9px 12px;
|
||||
background: linear-gradient(135deg, #2a1a08, #1a0f04);
|
||||
border: 2px solid #6b4b2a;
|
||||
border-radius: 8px;
|
||||
color: #c8a86a;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.gs-tab:hover { color: #f0d9a6; filter: brightness(1.2); }
|
||||
.gs-tab.gs-tab-active {
|
||||
color: #fff !important;
|
||||
box-shadow: inset 0 0 10px rgba(0,0,0,0.5), 0 0 14px rgba(200,160,60,0.3) !important;
|
||||
}
|
||||
.gs-tab-dot {
|
||||
width: 10px; height: 10px;
|
||||
border-radius: 50%; flex-shrink: 0;
|
||||
border: 1px solid rgba(255,255,255,0.3);
|
||||
}
|
||||
|
||||
/* ── Mittlere Spalte: Sammlung ───────────── */
|
||||
.gs-collection {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-right: 2px solid #6b4b2a;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.gs-col-header {
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
color: #f0d9a6;
|
||||
letter-spacing: 1px;
|
||||
text-transform: uppercase;
|
||||
padding: 10px 16px;
|
||||
background: linear-gradient(#3a2810cc, #1a0f04cc);
|
||||
border-bottom: 2px solid #6b4b2a;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.gs-grid {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 8px;
|
||||
overflow-y: auto;
|
||||
padding: 10px 12px;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
/* ── Karte ───────────────────────────────── */
|
||||
.gs-card {
|
||||
position: relative;
|
||||
border: 2px solid #6b4b2a;
|
||||
border-radius: 8px;
|
||||
overflow: visible;
|
||||
background: #1a0f04;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
|
||||
aspect-ratio: 3/4;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.gs-card:hover {
|
||||
transform: scale(1.06) 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;
|
||||
}
|
||||
.gs-card.gs-card-disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.gs-card.gs-card-disabled:hover {
|
||||
transform: none;
|
||||
box-shadow: none;
|
||||
border-color: #6b4b2a;
|
||||
}
|
||||
.gs-card.gs-card-selected {
|
||||
border-color: #f0d060;
|
||||
box-shadow: 0 0 14px rgba(240,208,96,0.5);
|
||||
}
|
||||
.gs-card img {
|
||||
width: 100%; height: 100%;
|
||||
object-fit: cover; display: block;
|
||||
border-radius: 6px 6px 0 0;
|
||||
}
|
||||
.gs-stat-atk {
|
||||
position: absolute; right: 8px; top: 38%;
|
||||
transform: translateY(-50%);
|
||||
background: rgba(180,40,20,0.88);
|
||||
border: 1px solid #ff6040;
|
||||
border-radius: 45px; color: #fff;
|
||||
font-family: "Cinzel", serif; font-size: 9px; font-weight: bold;
|
||||
padding: 2px 4px; z-index: 5;
|
||||
}
|
||||
.gs-stat-def {
|
||||
position: absolute; left: 8px; top: 38%;
|
||||
transform: translateY(-50%);
|
||||
background: rgba(20,80,180,0.88);
|
||||
border: 1px solid #4090ff;
|
||||
border-radius: 45px; color: #fff;
|
||||
font-family: "Cinzel", serif; font-size: 9px; font-weight: bold;
|
||||
padding: 2px 4px; z-index: 5;
|
||||
}
|
||||
.gs-card-footer {
|
||||
position: absolute; bottom: 4px; left: 6px;
|
||||
z-index: 5; pointer-events: none;
|
||||
}
|
||||
.gs-count-owned {
|
||||
font-family: "Cinzel", serif; font-size: 12px;
|
||||
color: #000; font-weight: bold;
|
||||
text-shadow: 0 0 3px rgba(255,255,255,0.6);
|
||||
}
|
||||
.gs-rarity {
|
||||
position: absolute; top: 72%; left: 0; right: 0;
|
||||
display: flex; justify-content: center; flex-wrap: wrap;
|
||||
gap: 1px; padding: 0 4px;
|
||||
pointer-events: none; z-index: 4;
|
||||
}
|
||||
|
||||
/* ── Pagination ──────────────────────────── */
|
||||
.gs-pagination {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
gap: 5px; padding: 8px 10px; flex-shrink: 0;
|
||||
border-top: 1px solid #3a2810;
|
||||
}
|
||||
.gs-page-btn {
|
||||
background: linear-gradient(#3a2810, #1a0f04);
|
||||
border: 1px solid #8b6a3c; border-radius: 5px;
|
||||
color: #f0d9a6; font-family: "Cinzel", serif;
|
||||
font-size: 11px; padding: 3px 10px; cursor: pointer; transition: 0.15s;
|
||||
}
|
||||
.gs-page-btn:hover { border-color: #f0d060; }
|
||||
.gs-page-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
||||
.gs-page-btn.gs-page-active {
|
||||
background: linear-gradient(#6b4b2a, #3c2414);
|
||||
border-color: #f0d060; color: #fff5cc;
|
||||
}
|
||||
|
||||
/* ── Rechte Spalte: Kombinier-Panel ──────── */
|
||||
.gs-combine-panel {
|
||||
width: 320px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
background: rgba(0,0,0,0.15);
|
||||
}
|
||||
|
||||
.gs-combine-hint {
|
||||
padding: 14px 16px;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 11px;
|
||||
color: #8b6a3c;
|
||||
line-height: 1.7;
|
||||
border-bottom: 1px solid #3a2810;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.gs-combine-grid {
|
||||
flex: 1;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 8px;
|
||||
overflow-y: auto;
|
||||
padding: 10px 12px;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
/* Kombinier-Karte (gleich wie gs-card, grüner Rand) */
|
||||
.gs-combine-card {
|
||||
position: relative;
|
||||
border: 2px solid #4a8b2a;
|
||||
border-radius: 8px;
|
||||
overflow: visible;
|
||||
background: #0f1a04;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, border-color 0.2s;
|
||||
aspect-ratio: 3/4;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.gs-combine-card:hover {
|
||||
border-color: #ff4444;
|
||||
transform: scale(1.05);
|
||||
z-index: 10;
|
||||
}
|
||||
.gs-combine-card:hover::after {
|
||||
content: "✕";
|
||||
position: absolute; inset: 0;
|
||||
background: rgba(180,0,0,0.55);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 24px; color: #fff;
|
||||
border-radius: 6px; pointer-events: none;
|
||||
}
|
||||
.gs-combine-card img {
|
||||
width: 100%; height: 100%;
|
||||
object-fit: cover; display: block;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.gs-combine-count {
|
||||
padding: 6px 12px;
|
||||
font-family: "Cinzel", serif; font-size: 12px;
|
||||
color: #f0d9a6; text-align: center;
|
||||
border-top: 1px solid #3a2810;
|
||||
flex-shrink: 0;
|
||||
min-height: 28px;
|
||||
}
|
||||
|
||||
.gs-combine-btn {
|
||||
margin: 10px 16px 14px;
|
||||
padding: 12px;
|
||||
background: linear-gradient(#6b4b2a, #3c2414);
|
||||
border: 2px solid #8b6a3c;
|
||||
border-radius: 8px;
|
||||
color: #f0d9a6;
|
||||
font-family: "Cinzel", serif;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
letter-spacing: 1px;
|
||||
cursor: pointer;
|
||||
transition: 0.2s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.gs-combine-btn:hover:not(:disabled) {
|
||||
border-color: #f0d060;
|
||||
color: #fff;
|
||||
box-shadow: 0 0 12px rgba(200,160,60,0.4);
|
||||
}
|
||||
.gs-combine-btn:disabled {
|
||||
opacity: 0.35;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* ── Empty / Loading ─────────────────────── */
|
||||
.gs-empty {
|
||||
grid-column: 1 / -1; text-align: center;
|
||||
color: #8b6a3c; font-size: 13px; padding: 30px 0;
|
||||
}
|
||||
.gs-loading {
|
||||
text-align: center; color: #8b6a3c; font-size: 13px;
|
||||
padding: 20px 0; animation: gs-pulse 1.2s infinite;
|
||||
}
|
||||
@keyframes gs-pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
|
||||
</style>
|
||||
`;
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
FRAKTIONS-TABS
|
||||
══════════════════════════════════════════════ */
|
||||
function renderTabs(groups) {
|
||||
const container = document.getElementById("gs-faction-tabs");
|
||||
if (!container) return;
|
||||
|
||||
container.innerHTML = groups
|
||||
.map((g, i) => {
|
||||
const color = g.color || "#6b4b2a";
|
||||
return `
|
||||
<button class="gs-tab ${i === 0 ? "gs-tab-active" : ""}"
|
||||
data-group="${g.id}"
|
||||
style="border-color:${color};${i === 0 ? `background:${color}33;` : ""}">
|
||||
<span class="gs-tab-dot" style="background:${color};"></span>
|
||||
<span>${g.name}</span>
|
||||
</button>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
container.querySelectorAll(".gs-tab").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
const color = btn.style.borderColor;
|
||||
container.querySelectorAll(".gs-tab").forEach((b) => {
|
||||
b.classList.remove("gs-tab-active");
|
||||
b.style.background = "";
|
||||
});
|
||||
btn.classList.add("gs-tab-active");
|
||||
btn.style.background = `${color}33`;
|
||||
gs_groupId = parseInt(btn.dataset.group);
|
||||
gs_page = 1;
|
||||
await loadCards();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
KARTEN LADEN
|
||||
══════════════════════════════════════════════ */
|
||||
async function loadCards() {
|
||||
const grid = document.getElementById("gs-grid");
|
||||
const pagination = document.getElementById("gs-pagination");
|
||||
if (!grid) return;
|
||||
|
||||
grid.innerHTML = `<div class="gs-loading">Lade Karten...</div>`;
|
||||
if (pagination) pagination.innerHTML = "";
|
||||
|
||||
try {
|
||||
const res = await fetch(
|
||||
`/api/user-cards?group_id=${gs_groupId}&page=${gs_page}&limit=${CARDS_PER_PAGE}`
|
||||
);
|
||||
if (!res.ok) throw new Error();
|
||||
const data = await res.json();
|
||||
gs_cards = data.cards || [];
|
||||
renderGrid(grid, gs_cards);
|
||||
renderPagination(pagination, data.totalPages, data.total);
|
||||
} catch {
|
||||
grid.innerHTML = `<div class="gs-empty">Keine Karten gefunden.</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
KARTEN-GRID RENDERN
|
||||
══════════════════════════════════════════════ */
|
||||
function renderGrid(grid, cards) {
|
||||
if (!cards || !cards.length) {
|
||||
grid.innerHTML = `<div class="gs-empty">Keine Karten in dieser Gruppe.</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
grid.innerHTML = cards.map((c) => {
|
||||
// Karte deaktivieren wenn sie nicht zur aktuellen Kombination passt
|
||||
const disabled = gs_combineId !== null && c.card_id !== gs_combineId;
|
||||
// Anzahl bereits im Kombinier-Feld
|
||||
const inField = gs_combineCards.filter(x => x.card_id === c.card_id).length;
|
||||
const available = c.amount - inField;
|
||||
|
||||
return `
|
||||
<div class="gs-card ${disabled ? "gs-card-disabled" : ""} ${gs_combineId === c.card_id ? "gs-card-selected" : ""}"
|
||||
data-card-id="${c.card_id}"
|
||||
title="${c.name}${disabled ? " (andere Karte bereits gewählt)" : ""}${available <= 0 ? " (alle im Feld)" : ""}">
|
||||
<img src="/images/cards/${c.image}" alt="${c.name}"
|
||||
onerror="this.src='/images/avatar_placeholder.svg'">
|
||||
${c.attack != null ? `<span class="gs-stat-atk">${c.attack}</span>` : ""}
|
||||
${c.defends != null ? `<span class="gs-stat-def">${c.defends}</span>` : ""}
|
||||
<div class="gs-card-footer">
|
||||
<span class="gs-count-owned">× ${available < 0 ? 0 : available}</span>
|
||||
</div>
|
||||
${c.rarity ? `<div class="gs-rarity">${rarityImgs(c.rarity, 12)}</div>` : ""}
|
||||
</div>`;
|
||||
}).join("");
|
||||
|
||||
grid.querySelectorAll(".gs-card:not(.gs-card-disabled)").forEach((el) => {
|
||||
el.addEventListener("click", () => {
|
||||
const card = cards.find((c) => c.card_id === parseInt(el.dataset.cardId));
|
||||
if (!card) return;
|
||||
|
||||
const inField = gs_combineCards.filter(x => x.card_id === card.card_id).length;
|
||||
if (inField >= card.amount) {
|
||||
showToast("Keine weiteren Exemplare verfügbar.");
|
||||
return;
|
||||
}
|
||||
addToField(card);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
KARTE ZUM KOMBINIER-FELD HINZUFÜGEN
|
||||
══════════════════════════════════════════════ */
|
||||
function addToField(card) {
|
||||
gs_combineId = card.card_id;
|
||||
gs_combineCards.push({ ...card });
|
||||
renderCombineField();
|
||||
renderGrid(document.getElementById("gs-grid"), gs_cards);
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
KARTE AUS FELD ENTFERNEN
|
||||
══════════════════════════════════════════════ */
|
||||
function removeFromField(index) {
|
||||
gs_combineCards.splice(index, 1);
|
||||
if (gs_combineCards.length === 0) gs_combineId = null;
|
||||
renderCombineField();
|
||||
renderGrid(document.getElementById("gs-grid"), gs_cards);
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
KOMBINIER-FELD RENDERN
|
||||
══════════════════════════════════════════════ */
|
||||
function renderCombineField() {
|
||||
const grid = document.getElementById("gs-combine-grid");
|
||||
const hint = document.getElementById("gs-combine-hint");
|
||||
const count = document.getElementById("gs-combine-count");
|
||||
const btn = document.getElementById("gs-combine-btn");
|
||||
if (!grid) return;
|
||||
|
||||
if (!gs_combineCards.length) {
|
||||
grid.innerHTML = "";
|
||||
hint.style.display = "block";
|
||||
count.textContent = "";
|
||||
btn.disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
hint.style.display = "none";
|
||||
|
||||
grid.innerHTML = gs_combineCards.map((c, i) => `
|
||||
<div class="gs-combine-card" data-index="${i}" title="Entfernen: ${c.name}">
|
||||
<img src="/images/cards/${c.image}" alt="${c.name}"
|
||||
onerror="this.src='/images/avatar_placeholder.svg'">
|
||||
</div>
|
||||
`).join("");
|
||||
|
||||
grid.querySelectorAll(".gs-combine-card").forEach((el) => {
|
||||
el.addEventListener("click", () => {
|
||||
removeFromField(parseInt(el.dataset.index));
|
||||
});
|
||||
});
|
||||
|
||||
count.textContent = `${gs_combineCards.length} Karte${gs_combineCards.length !== 1 ? "n" : ""} im Feld`;
|
||||
btn.disabled = gs_combineCards.length < 2;
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
KOMBINIEREN-BUTTON
|
||||
══════════════════════════════════════════════ */
|
||||
function attachCombineEvents() {
|
||||
// Wird nach renderShell aufgerufen
|
||||
setTimeout(() => {
|
||||
const btn = document.getElementById("gs-combine-btn");
|
||||
if (!btn) return;
|
||||
btn.addEventListener("click", async () => {
|
||||
if (gs_combineCards.length < 2) return;
|
||||
|
||||
btn.disabled = true;
|
||||
btn.textContent = "Kombiniere...";
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/cards/combine", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
card_id: gs_combineId,
|
||||
amount: gs_combineCards.length,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
|
||||
if (!res.ok) {
|
||||
showToast(data.error || "Kombinieren fehlgeschlagen.");
|
||||
btn.disabled = false;
|
||||
btn.textContent = "Kombinieren";
|
||||
return;
|
||||
}
|
||||
|
||||
showToast("Kombinieren erfolgreich! 🎉");
|
||||
gs_combineCards = [];
|
||||
gs_combineId = null;
|
||||
gs_initialized = false; // Neu laden erzwingen
|
||||
renderCombineField();
|
||||
await loadCards();
|
||||
} catch {
|
||||
showToast("Verbindungsfehler.");
|
||||
btn.disabled = false;
|
||||
btn.textContent = "Kombinieren";
|
||||
} finally {
|
||||
btn.textContent = "Kombinieren";
|
||||
}
|
||||
});
|
||||
}, 50);
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
PAGINATION
|
||||
══════════════════════════════════════════════ */
|
||||
function renderPagination(pagination, totalPages, total) {
|
||||
if (!pagination || !totalPages || totalPages <= 1) return;
|
||||
pagination.innerHTML = `
|
||||
<button class="gs-page-btn" id="gs-prev" ${gs_page === 1 ? "disabled" : ""}>◀</button>
|
||||
${Array.from({ length: totalPages }, (_, i) => i + 1)
|
||||
.map((p) => `<button class="gs-page-btn ${p === gs_page ? "gs-page-active" : ""}" data-page="${p}">${p}</button>`)
|
||||
.join("")}
|
||||
<button class="gs-page-btn" id="gs-next" ${gs_page === totalPages ? "disabled" : ""}>▶</button>
|
||||
<span style="color:#a08060;font-size:11px;">${total} Karten</span>`;
|
||||
|
||||
pagination.querySelector("#gs-prev")?.addEventListener("click", async () => {
|
||||
if (gs_page > 1) { gs_page--; await loadCards(); }
|
||||
});
|
||||
pagination.querySelector("#gs-next")?.addEventListener("click", async () => {
|
||||
if (gs_page < totalPages) { gs_page++; await loadCards(); }
|
||||
});
|
||||
pagination.querySelectorAll("[data-page]").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
gs_page = parseInt(btn.dataset.page);
|
||||
await loadCards();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* ══════════════════════════════════════════════
|
||||
TOAST
|
||||
══════════════════════════════════════════════ */
|
||||
function showToast(msg) {
|
||||
const existing = document.querySelector(".gs-toast");
|
||||
if (existing) existing.remove();
|
||||
const t = document.createElement("div");
|
||||
t.className = "gs-toast";
|
||||
t.textContent = msg;
|
||||
t.style.cssText = `
|
||||
position:fixed;bottom:80px;left:50%;transform:translateX(-50%);
|
||||
background:linear-gradient(#4a2808,#2a1004);border:2px solid #8b6a3c;
|
||||
border-radius:8px;color:#f0d9a6;font-family:"Cinzel",serif;font-size:13px;
|
||||
padding:10px 22px;z-index:9999;pointer-events:none;`;
|
||||
document.body.appendChild(t);
|
||||
setTimeout(() => t.remove(), 2800);
|
||||
}
|
||||
@ -2,6 +2,7 @@ import { loadArena } from "./buildings/arena.js?v=4";
|
||||
import { loadCharacterHouse } from "./buildings/character-house.js?v=2";
|
||||
import { loadBlackmarket } from "./buildings/blackmarket.js?v=2";
|
||||
import { loadMine } from "./buildings/mine.js?v=2";
|
||||
import { loadGlucksspiel } from "./gaststaette/glucksspiel.js";
|
||||
const popup = document.getElementById("building-popup");
|
||||
const title = document.getElementById("popup-title");
|
||||
const tooltip = document.getElementById("map-tooltip");
|
||||
@ -21,6 +22,7 @@ document.querySelectorAll(".gaststaette-tab").forEach((tab) => {
|
||||
document.querySelectorAll(".gaststaette-tab-content").forEach((c) => c.classList.remove("active"));
|
||||
tab.classList.add("active");
|
||||
document.getElementById(tab.dataset.tab).classList.add("active");
|
||||
if (tab.dataset.tab === "gs-tab1") loadGlucksspiel();
|
||||
});
|
||||
});
|
||||
|
||||
@ -181,6 +183,7 @@ document.querySelectorAll(".building").forEach((building) => {
|
||||
gaststaettePopup.style.transform = "translate(-50%, -50%) scale(1)";
|
||||
gaststaettePopup.classList.add("active");
|
||||
qmOverlay.classList.add("active");
|
||||
loadGlucksspiel();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -798,21 +798,15 @@
|
||||
<div class="gaststaette-body">
|
||||
<!-- Linke Tab-Sidebar -->
|
||||
<div class="gaststaette-tabs">
|
||||
<button class="gaststaette-tab active" data-tab="gs-tab1">Dummy 1</button>
|
||||
<button class="gaststaette-tab active" data-tab="gs-tab1">Glücksspiel</button>
|
||||
<button class="gaststaette-tab" data-tab="gs-tab2">Dummy 2</button>
|
||||
<button class="gaststaette-tab" data-tab="gs-tab3">Dummy 3</button>
|
||||
</div>
|
||||
<!-- Hauptinhalt -->
|
||||
<div class="gaststaette-content">
|
||||
<div class="gaststaette-tab-content active" id="gs-tab1">
|
||||
<p>Inhalt Dummy 1</p>
|
||||
</div>
|
||||
<div class="gaststaette-tab-content" id="gs-tab2">
|
||||
<p>Inhalt Dummy 2</p>
|
||||
</div>
|
||||
<div class="gaststaette-tab-content" id="gs-tab3">
|
||||
<p>Inhalt Dummy 3</p>
|
||||
</div>
|
||||
<div class="gaststaette-tab-content active" id="gs-tab1"></div>
|
||||
<div class="gaststaette-tab-content" id="gs-tab2"><p style="color:#5c3b20;font-family:'Cinzel',serif;">Inhalt folgt...</p></div>
|
||||
<div class="gaststaette-tab-content" id="gs-tab3"><p style="color:#5c3b20;font-family:'Cinzel',serif;">Inhalt folgt...</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user