adventskalender/shared/js/save-progress.js aktualisiert

This commit is contained in:
2025-11-05 20:44:07 +00:00
parent d6458a6e49
commit 12219faa28

View File

@@ -1,10 +1,9 @@
// shared/js/save-progress.js
/** /**
* Bratonien Adventskalender Fortschritt speichern (shared) * Bratonien Adventskalender Fortschritt speichern (shared)
* ---------------------------------------------------------- * ----------------------------------------------------------
* - speichert geöffnete Türchen (Einzeltüren & Flügeltüren) * - speichert geöffnete Türchen (Einzeltüren & Flügeltüren)
* - stellt Zustand nach Neuladen wieder her * - stellt Zustand nach Neuladen wieder her
* - Dev-Modus (?dev): zeigt Reset-Button + deaktiviert Tagessperre * - Dev-Modus (?dev): zeigt Reset-Button + gemeinsames Panel für alle Dev-Elemente
*/ */
(function () { (function () {
@@ -12,11 +11,10 @@
const year = yearMatch ? yearMatch[0] : new Date().getFullYear(); const year = yearMatch ? yearMatch[0] : new Date().getFullYear();
const STORAGE_KEY = `bratonien_opened_${year}`; const STORAGE_KEY = `bratonien_opened_${year}`;
/** === DEV-FLAG === */
const isDev = window.location.search.includes("dev"); const isDev = window.location.search.includes("dev");
window.BRATONIEN_DEV = isDev; window.BRATONIEN_DEV = isDev;
/** === HELFER === */ // === Hilfsfunktionen ===
function getOpenedDays() { function getOpenedDays() {
try { try {
return JSON.parse(localStorage.getItem(STORAGE_KEY)) || []; return JSON.parse(localStorage.getItem(STORAGE_KEY)) || [];
@@ -29,17 +27,12 @@
localStorage.setItem(STORAGE_KEY, JSON.stringify([...new Set(days)])); localStorage.setItem(STORAGE_KEY, JSON.stringify([...new Set(days)]));
} }
/** === STATUS LADEN === */ // === Status laden ===
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
const openedDays = getOpenedDays(); const openedDays = getOpenedDays();
openedDays.forEach(day => { openedDays.forEach(day => {
// normale Tür document.querySelectorAll(`.door[data-day="${day}"]`).forEach(d => d.classList.add("open"));
document.querySelectorAll(`.door[data-day="${day}"]`).forEach(door => {
door.classList.add("open");
});
// Flügeltüren
const left = document.querySelector(`.fluegel.left[data-day="${day}"]`); const left = document.querySelector(`.fluegel.left[data-day="${day}"]`);
const right = document.querySelector(`.fluegel.right[data-day="${day}"]`); const right = document.querySelector(`.fluegel.right[data-day="${day}"]`);
if (left && right) { if (left && right) {
@@ -48,49 +41,49 @@
} }
}); });
// === DEV BUTTON === // === DEV-Bereich ===
if (isDev) { if (isDev) {
// zentrales Dev-Panel
let panel = document.getElementById("dev-panel");
if (!panel) {
panel = document.createElement("div");
panel.id = "dev-panel";
panel.style.cssText = `
position: fixed;
bottom: 10px;
right: 10px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 10px;
z-index: 9999;
`;
document.body.appendChild(panel);
}
// Reset-Button
const btn = document.createElement("button"); const btn = document.createElement("button");
btn.textContent = "Reset Kalender"; btn.textContent = "Reset Kalender";
btn.style.position = "fixed"; btn.style.cssText = `
btn.style.bottom = "15px"; padding: 8px 14px;
btn.style.right = "15px"; border: 2px solid gold;
btn.style.zIndex = "9999"; border-radius: 10px;
btn.style.padding = "8px 14px"; background: #1a1a1a;
btn.style.border = "2px solid gold"; color: gold;
btn.style.borderRadius = "10px"; cursor: pointer;
btn.style.background = "#1a1a1a"; font-family: sans-serif;
btn.style.color = "gold"; font-size: 14px;
btn.style.cursor = "pointer"; `;
btn.style.fontFamily = "sans-serif";
btn.style.fontSize = "14px";
btn.addEventListener("click", () => { btn.addEventListener("click", () => {
localStorage.removeItem(STORAGE_KEY); localStorage.removeItem(STORAGE_KEY);
location.reload(); location.reload();
}); });
const devPanel = document.getElementById("dev-panel");
if (devPanel) { panel.appendChild(btn);
devPanel.appendChild(btn);
} else {
const panel = document.createElement("div");
panel.id = "dev-panel";
panel.style.cssText = `
position: fixed;
bottom: 10px;
right: 10px;
display: flex;
flex-direction: column;
gap: 10px;
align-items: flex-end;
z-index: 9999;
`;
document.body.appendChild(panel);
panel.appendChild(btn);
}
} }
}); });
/** === STATUS SPEICHERN (auf Event hören) === */ // === Status speichern ===
document.addEventListener("doorOpened", e => { document.addEventListener("doorOpened", e => {
const day = e.detail?.day; const day = e.detail?.day;
if (!day) return; if (!day) return;