135 lines
4.1 KiB
JavaScript
135 lines
4.1 KiB
JavaScript
// ============================================================
|
||
// Bratonien Adventskalender – Türchen-Sperrlogik & Dev-Overlay
|
||
// ============================================================
|
||
// Autor: Thomas Dannenberg & GPT-5
|
||
// Pfad: shared/js/lock.js
|
||
// Zweck: Sperrt Türchen nach aktuellem Tag, mit Dev-Modus (?dev)
|
||
|
||
(() => {
|
||
const pathMatch = window.location.pathname.match(/\/(\d{4})\//);
|
||
const YEAR = pathMatch ? pathMatch[1] : new Date().getFullYear();
|
||
const PARAMS = new URLSearchParams(window.location.search);
|
||
const DEV_MODE = PARAMS.has("dev");
|
||
|
||
// Lokale Speicherkeys
|
||
const KEY_SIM_DAY = `bratonien_${YEAR}_sim_day`;
|
||
const KEY_UNLOCKED = `bratonien_${YEAR}_dev_unlock`;
|
||
|
||
// === Aktuellen Tag bestimmen ===
|
||
function getCurrentDay() {
|
||
if (DEV_MODE) {
|
||
const simDay = parseInt(localStorage.getItem(KEY_SIM_DAY), 10) || 1;
|
||
return simDay;
|
||
}
|
||
|
||
const now = new Date();
|
||
const month = now.getMonth() + 1; // Dez = 12
|
||
const day = now.getDate();
|
||
|
||
// Nur im Dezember relevant
|
||
if (month !== 12) return 0;
|
||
if (day >= 25) return 25; // Nach dem 24.12. alles offen
|
||
return day;
|
||
}
|
||
|
||
// === Türchen-Freigabe prüfen ===
|
||
window.isDoorUnlocked = function (day) {
|
||
const current = getCurrentDay();
|
||
const unlocked = localStorage.getItem(KEY_UNLOCKED) === "true";
|
||
|
||
if (unlocked) return true;
|
||
if (current >= 25) return true; // Nach 24. alles frei
|
||
return parseInt(day, 10) <= current;
|
||
};
|
||
|
||
// === Dev-Overlay aufbauen ===
|
||
if (DEV_MODE) {
|
||
const overlay = document.createElement("div");
|
||
overlay.id = "dev-overlay";
|
||
overlay.style.cssText = `
|
||
position: fixed;
|
||
bottom: 10px;
|
||
right: 10px;
|
||
background: rgba(0,0,0,0.7);
|
||
color: #fff;
|
||
font-family: monospace;
|
||
font-size: 13px;
|
||
padding: 10px;
|
||
border-radius: 8px;
|
||
z-index: 9999;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
align-items: center;
|
||
`;
|
||
|
||
// Infozeile
|
||
const info = document.createElement("div");
|
||
info.textContent = `DEV-MODUS: Simuliertag ${getCurrentDay()}`;
|
||
overlay.appendChild(info);
|
||
|
||
// Buttonleiste
|
||
const grid = document.createElement("div");
|
||
grid.style.cssText = `
|
||
display: grid;
|
||
grid-template-columns: repeat(8, 1fr);
|
||
gap: 4px;
|
||
`;
|
||
|
||
for (let i = 1; i <= 24; i++) {
|
||
const btn = document.createElement("button");
|
||
btn.textContent = i;
|
||
btn.style.cssText = `
|
||
padding: 3px 6px;
|
||
background: #444;
|
||
color: #fff;
|
||
border: 1px solid #777;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
`;
|
||
btn.onclick = () => {
|
||
localStorage.setItem(KEY_SIM_DAY, i);
|
||
info.textContent = `DEV-MODUS: Simuliertag ${i}`;
|
||
};
|
||
grid.appendChild(btn);
|
||
}
|
||
overlay.appendChild(grid);
|
||
|
||
// Unlock & Reset
|
||
const actions = document.createElement("div");
|
||
actions.style.cssText = "display:flex;gap:6px;margin-top:6px;";
|
||
|
||
const unlockBtn = document.createElement("button");
|
||
unlockBtn.textContent = "🔓 Sperre aufheben";
|
||
unlockBtn.style.cssText = `
|
||
background:#2c6e49;color:white;border:none;
|
||
padding:5px 10px;border-radius:4px;cursor:pointer;
|
||
`;
|
||
unlockBtn.onclick = () => {
|
||
localStorage.setItem(KEY_UNLOCKED, "true");
|
||
alert("Alle Türchen entsperrt.");
|
||
};
|
||
|
||
const resetBtn = document.createElement("button");
|
||
resetBtn.textContent = "⟳ Reset";
|
||
resetBtn.style.cssText = `
|
||
background:#8b0000;color:white;border:none;
|
||
padding:5px 10px;border-radius:4px;cursor:pointer;
|
||
`;
|
||
resetBtn.onclick = () => {
|
||
localStorage.removeItem(KEY_SIM_DAY);
|
||
localStorage.removeItem(KEY_UNLOCKED);
|
||
localStorage.removeItem(`bratonien_${YEAR}_progress`);
|
||
alert("Entwicklungseinstellungen & Fortschritt zurückgesetzt.");
|
||
location.reload();
|
||
};
|
||
|
||
actions.appendChild(unlockBtn);
|
||
actions.appendChild(resetBtn);
|
||
overlay.appendChild(actions);
|
||
|
||
document.body.appendChild(overlay);
|
||
}
|
||
|
||
console.log(`[Lock.js] Initialisiert – aktueller Tag: ${getCurrentDay()} (Dev=${DEV_MODE})`);
|
||
})(); |