diff --git a/src/main.ts b/src/main.ts index d93b73d..d5cdff4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,6 +17,7 @@ function createApp(): Application { const appDiv = document.querySelector(".App"); if (!appDiv) throw new Error("No app div found"); + appDiv.innerHTML = ""; // TODO: Fix(?) appDiv.appendChild(app.view); return app; @@ -48,45 +49,45 @@ async function loadConfig(): Promise { * @param config * @param startNow Called from restart. Bypasses sleep data */ -export async function startUp (config: Config | null = null, startNow: boolean = false) { +export async function startUp(config: Config | null = null, startNow: boolean = false) { if (config === null) { - config = await loadConfig(); - if (config.error) throw new Error(config.reason); + config = await loadConfig(); + if (config.error) throw new Error(config.reason); } const app = createApp(); - - // Show GMM Logo while loading all textures - // Temp text instead of logo for now - const loadingText = new Text("Loading", { - fontFamily: "Trebuchet", - fontSize: 24, - fill: 0xffffff, - align: "center", - }); - loadingText.anchor.set(0.5); - loadingText.position.set(app.screen.width * 0.5, app.screen.height * 0.5); - app.stage.addChild(loadingText); - app.ticker.add((delta) => { - loadingText.text = "Loading" + ".".repeat((Math.floor(app.ticker.lastTime / 1000) % 3) + 1); - }); - - const graphicsManager = new CogSpeedGraphicsHandler(app); - - // Load screen while displaying loading text - await graphicsManager.emulateLoadingTime(); - graphicsManager.setBackground("carbon"); - app.stage.removeChild(loadingText); - - // Display the home page - const startPage = new StartPage(config, app, graphicsManager); - if (!startNow) await startPage.displayHomePage(); - - // Display start page - const sleepData = await startPage.start(startNow); - if (!sleepData) throw new Error("No sleep data"); - - // Game phase - called after start button is clicked - const game = new CogSpeedGame(config, app, graphicsManager, sleepData); - game.start(); + + // Show GMM Logo while loading all textures + // Temp text instead of logo for now + const loadingText = new Text("Loading", { + fontFamily: "Trebuchet", + fontSize: 24, + fill: 0xffffff, + align: "center", + }); + loadingText.anchor.set(0.5); + loadingText.position.set(app.screen.width * 0.5, app.screen.height * 0.5); + app.stage.addChild(loadingText); + app.ticker.add((delta) => { + loadingText.text = "Loading" + ".".repeat((Math.floor(app.ticker.lastTime / 1000) % 3) + 1); + }); + + const graphicsManager = new CogSpeedGraphicsHandler(app); + + // Load screen while displaying loading text + await graphicsManager.emulateLoadingTime(); + graphicsManager.setBackground("carbon"); + app.stage.removeChild(loadingText); + + // Display the home page + const startPage = new StartPage(config, app, graphicsManager); + if (!startNow) await startPage.displayHomePage(); + + // Display start page + const sleepData = await startPage.start(startNow); + if (!sleepData) throw new Error("No sleep data"); + + // Game phase - called after start button is clicked + const game = new CogSpeedGame(config, app, graphicsManager, sleepData); + game.start(); }; diff --git a/src/routes/results.ts b/src/routes/results.ts index 23270ff..f81ba9b 100644 --- a/src/routes/results.ts +++ b/src/routes/results.ts @@ -247,6 +247,7 @@ export class ProcessResultsPage { ); restartTestButtonContainer.on("pointerdown", () => { // TODO: Send back to home page + this.app.destroy(); startUp(config, true); });