adventskalender/shared/js/lock.js aktualisiert
This commit is contained in:
@@ -21,35 +21,51 @@ function getSimulatedDay() {
|
||||
function _checkDoorUnlocked(day) {
|
||||
day = parseInt(day, 10);
|
||||
|
||||
// Manuell entsperrt
|
||||
// Manuell entsperrt?
|
||||
const forceUnlock = localStorage.getItem(`${STORAGE_BASE}_unlocked`) === "true";
|
||||
if (forceUnlock) return true;
|
||||
|
||||
// Nach dem 24.12. immer offen
|
||||
// Nach dem 24.12. dieses Jahres alles offen
|
||||
const now = new Date();
|
||||
const after24 =
|
||||
now.getFullYear() > YEAR ||
|
||||
(now.getFullYear() === YEAR && now.getMonth() === 11 && now.getDate() > 24);
|
||||
(now.getFullYear() === YEAR &&
|
||||
now.getMonth() === 11 &&
|
||||
now.getDate() > 24);
|
||||
if (after24) return true;
|
||||
|
||||
// Dezember -> bis aktueller Tag
|
||||
// Im Dezember: bis heutigem Tag
|
||||
if (now.getFullYear() === YEAR && now.getMonth() === 11) {
|
||||
return day <= now.getDate();
|
||||
}
|
||||
|
||||
// Vor Dezember alles zu
|
||||
// Vor Dezember: alles zu
|
||||
return false;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Dev-Konsole
|
||||
// Dev-Konsole bauen
|
||||
// ============================================================
|
||||
|
||||
function createDevConsole() {
|
||||
const panel = document.getElementById("dev-panel");
|
||||
// versuchen, vorhandenes Panel zu nehmen
|
||||
let panel = document.getElementById("dev-panel");
|
||||
|
||||
// falls save-progress.js noch keins gebaut hat, hier wirklich EINS bauen
|
||||
if (!panel) {
|
||||
console.warn("⚠️ Kein #dev-panel gefunden. save-progress.js muss zuerst laden.");
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
||||
const box = document.createElement("div");
|
||||
@@ -69,7 +85,7 @@ function createDevConsole() {
|
||||
title.style.marginBottom = "6px";
|
||||
box.appendChild(title);
|
||||
|
||||
// Tag-Buttons
|
||||
// Grid 1–24
|
||||
const grid = document.createElement("div");
|
||||
grid.style.cssText = `
|
||||
display: grid;
|
||||
@@ -97,9 +113,9 @@ function createDevConsole() {
|
||||
}
|
||||
box.appendChild(grid);
|
||||
|
||||
// Steuer-Buttons
|
||||
// Steuerbuttons
|
||||
const actions = document.createElement("div");
|
||||
actions.style.cssText = "display:flex;gap:6px;";
|
||||
actions.style.cssText = `display:flex;gap:6px;`;
|
||||
|
||||
const unlock = document.createElement("button");
|
||||
unlock.textContent = "🚪 Sperre aufheben";
|
||||
@@ -145,13 +161,24 @@ function createDevConsole() {
|
||||
// Export + Init
|
||||
// ============================================================
|
||||
|
||||
// von door-open.js aufrufbar
|
||||
window.isDoorUnlocked = function (day) {
|
||||
if (DEV_MODE) {
|
||||
const sim = getSimulatedDay();
|
||||
if (sim !== null) return parseInt(day, 10) <= sim;
|
||||
if (sim !== null) {
|
||||
return parseInt(day, 10) <= sim;
|
||||
}
|
||||
// dev ohne sim: alles offen
|
||||
return true;
|
||||
}
|
||||
return _checkDoorUnlocked(day);
|
||||
};
|
||||
|
||||
if (DEV_MODE) createDevConsole();
|
||||
// Dev-Konsole erst bauen, wenn DOM fertig ist
|
||||
if (DEV_MODE) {
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", createDevConsole);
|
||||
} else {
|
||||
createDevConsole();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user