const loader = document.getElementById("loading-overlay"); const landingUI = document.getElementById("landing-ui"); const loadingMsg = document.getElementById("loading-message"); // --- 2. Accessibility Helper --- function announce(message) { const announcer = document.getElementById("a11y-announcer"); announcer.textContent = message; } // --- 3. New Descent Logic (Using Dynamic Import) --- // We attach listener inside the module script because module scope is local document.getElementById("btn-start").addEventListener("click", startNewDescent); async function startNewDescent() { landingUI.classList.add("hidden"); loader.classList.remove("hidden"); // B. Accessibility Updates announce("Starting new game. Entering the Team Builder."); loadingMsg.textContent = "LOADING TEAM BUILDER COMPONENT..."; // C. Lazy Load logic (Components registered via import above) try { initiateTeamBuilder(); } catch (error) { console.error("Failed to load team builder:", error); loadingMsg.textContent = "ERROR LOADING TEAM BUILDER. PLEASE REFRESH."; announce("Error loading team builder. Please refresh."); } // try { // // Simulate loading time // setTimeout(() => { // loadingMsg.textContent = "GENERATING VOXEL GRID..."; // initializeGameWorld(); // }, 1000); // } catch (error) { // console.error("Failed to load game:", error); // loadingMsg.textContent = "ERROR LOADING ENGINE. PLEASE REFRESH."; // announce("Error loading game engine. Please refresh."); // } } async function initiateTeamBuilder() { await import("./ui/team-builder.js"); const teamBuilder = document.querySelector("team-builder"); document.startViewTransition(() => { teamBuilder.classList.remove("hidden"); loader.classList.add("hidden"); }); announce("Team Builder loaded. Ready to build your team."); } // --- 4. Game Initialization --- async function initializeGameWorld() { const gameViewport = document.querySelector("game-viewport"); await import("./ui/game-viewport.js"); // D. Transition to Game loader.classList.add("hidden"); gameViewport.classList.remove("hidden"); announce("Game loaded. Tactical grid active."); }