Skip to content

Commit

Permalink
fix(game): Make restart button work (clear appDiv)
Browse files Browse the repository at this point in the history
  • Loading branch information
CaedenPH committed Apr 2, 2024
1 parent 160b2cf commit b8de5bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
75 changes: 38 additions & 37 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,45 +49,45 @@ async function loadConfig(): Promise<Config> {
* @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();
};
1 change: 1 addition & 0 deletions src/routes/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export class ProcessResultsPage {
);
restartTestButtonContainer.on("pointerdown", () => {
// TODO: Send back to home page
this.app.destroy();
startUp(config, true);
});

Expand Down

0 comments on commit b8de5bb

Please sign in to comment.