adventskalender/shared/js/door-open.js aktualisiert
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
// shared/js/door-open.js
|
// shared/js/door-open.js
|
||||||
/**
|
// Öffnet Türen, Flügel und Openfields
|
||||||
* Bratonien Adventskalender – Türöffnung (2025)
|
// und sagt den anderen Skripten Bescheid (Popup, Save)
|
||||||
* ---------------------------------------------
|
|
||||||
* Öffnet normale Türen (.door) und Doppelflügeltüren (.fluegel)
|
|
||||||
* und triggert das Event für save-progress.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
document.querySelectorAll(".door, .fluegel, .openfield").forEach(elem => {
|
document.querySelectorAll(".door, .fluegel, .openfield").forEach(elem => {
|
||||||
elem.addEventListener("click", () => {
|
elem.addEventListener("click", () => {
|
||||||
@@ -13,40 +9,53 @@ document.querySelectorAll(".door, .fluegel, .openfield").forEach(elem => {
|
|||||||
|
|
||||||
const openfield = document.querySelector(`.openfield[data-day="${day}"]`);
|
const openfield = document.querySelector(`.openfield[data-day="${day}"]`);
|
||||||
const door = document.querySelector(`.door[data-day="${day}"]`);
|
const door = document.querySelector(`.door[data-day="${day}"]`);
|
||||||
const left = document.querySelector(`.fluegel.left[data-day="${day}"]`);
|
const flLeft = document.querySelector(`.fluegel.left[data-day="${day}"]`);
|
||||||
const right = document.querySelector(`.fluegel.right[data-day="${day}"]`);
|
const flRight = document.querySelector(`.fluegel.right[data-day="${day}"]`);
|
||||||
|
|
||||||
// === EINZELTÜR-LOGIK ===
|
|
||||||
if (elem.classList.contains("door") || (openfield && door && elem === openfield)) {
|
|
||||||
if (door.classList.contains("open")) {
|
|
||||||
console.log(`Tür ${day} erneut geöffnet`);
|
|
||||||
document.dispatchEvent(new CustomEvent("doorOpened", { detail: { day } }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 1) normale Tür
|
||||||
|
if (elem.classList.contains("door")) {
|
||||||
|
if (!door.classList.contains("open")) {
|
||||||
door.classList.add("open");
|
door.classList.add("open");
|
||||||
if (openfield) openfield.classList.add("open");
|
if (openfield) openfield.classList.add("open");
|
||||||
|
}
|
||||||
document.dispatchEvent(new CustomEvent("doorOpened", { detail: { day } }));
|
notifyDayOpened(day);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// === DOPPELFLÜGEL-LOGIK ===
|
// 2) Flügeltür
|
||||||
if (elem.classList.contains("fluegel") || (openfield && left && right && elem === openfield)) {
|
if (elem.classList.contains("fluegel")) {
|
||||||
const bothOpen =
|
const beideOffen =
|
||||||
left?.classList.contains("rota") && right?.classList.contains("rota");
|
flLeft?.classList.contains("rota") &&
|
||||||
|
flRight?.classList.contains("rota");
|
||||||
|
|
||||||
if (bothOpen) {
|
if (!beideOffen) {
|
||||||
console.log(`Flügeltür ${day} erneut geöffnet`);
|
if (flLeft) flLeft.classList.add("rota");
|
||||||
document.dispatchEvent(new CustomEvent("doorOpened", { detail: { day } }));
|
if (flRight) flRight.classList.add("rota");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (left) left.classList.add("rota");
|
|
||||||
if (right) right.classList.add("rota");
|
|
||||||
if (openfield) openfield.classList.add("open");
|
if (openfield) openfield.classList.add("open");
|
||||||
|
}
|
||||||
|
notifyDayOpened(day);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
document.dispatchEvent(new CustomEvent("doorOpened", { detail: { day } }));
|
// 3) openfield (erneut öffnen / nur Popup)
|
||||||
|
if (elem.classList.contains("openfield")) {
|
||||||
|
notifyDayOpened(day);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sagt allen anderen Skripten: „Tag X wurde geöffnet“
|
||||||
|
* popup.js kann window.openPopup(day) bereitstellen
|
||||||
|
* save-progress.js hört auf das CustomEvent
|
||||||
|
*/
|
||||||
|
function notifyDayOpened(day) {
|
||||||
|
// fürs Speichern
|
||||||
|
document.dispatchEvent(new CustomEvent("doorOpened", { detail: { day } }));
|
||||||
|
|
||||||
|
// fürs Popup (deine vorhandene popup.js)
|
||||||
|
if (typeof window.openPopup === "function") {
|
||||||
|
window.openPopup(day);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user