-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'practice-test-incorporated' of https://github.com/graym…
…attermetrics/cogspeed into practice-test-incorporated
- Loading branch information
Showing
8 changed files
with
140 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,6 @@ | ||
import axios from "axios"; | ||
import { Application, Text } from "pixi.js"; | ||
import { CogSpeedGame } from "./routes/game"; | ||
import { StartPage } from "./routes/start"; | ||
import { Config } from "./types/Config"; | ||
import { CogSpeedGraphicsHandler } from "./ui/handler"; | ||
import { startUp } from "./main"; | ||
|
||
const gameWidth = window.innerWidth; | ||
const gameHeight = window.innerHeight; | ||
|
||
const app = new Application<HTMLCanvasElement>({ | ||
width: gameWidth, | ||
height: gameHeight, | ||
}); | ||
|
||
/** | ||
* Loads the config from the backend | ||
* NOTE: Increases load time | ||
*/ | ||
async function loadConfig(): Promise<Config> { | ||
let url = "https://t6pedjjwcb.execute-api.us-east-2.amazonaws.com/default/getCogspeedConfig"; | ||
const params = new URLSearchParams(window.location.search); | ||
|
||
const version = params.get("version"); | ||
const branch = params.get("branch"); | ||
|
||
// Either append version or branch | ||
if (version) url += `?version=${version}`; | ||
else if (branch) url += `?branch=${branch}`; | ||
|
||
const request = await axios.get(url); | ||
return await request.data; | ||
} | ||
|
||
|
||
/** | ||
* Loads initial page | ||
*/ | ||
async function main() { | ||
const config = await loadConfig(); | ||
if (config.error) throw new Error(config.reason); | ||
|
||
const appDiv = document.querySelector(".App"); | ||
if (!appDiv) throw new Error("No app div found"); | ||
appDiv.appendChild(app.view); | ||
|
||
// 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(gameWidth * 0.5, gameHeight * 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); | ||
await startPage.displayHomePage(); | ||
|
||
// Display start page | ||
const sleepData = await startPage.start(); | ||
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(); | ||
} | ||
|
||
window.onload = main; | ||
window.onload = () => {startUp()}; | ||
export default function App() { | ||
return <div className="App"></div>; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import axios from "axios"; | ||
import { Application, Text } from "pixi.js"; | ||
import { CogSpeedGame } from "./routes/game"; | ||
import { StartPage } from "./routes/start"; | ||
import { Config } from "./types/Config"; | ||
import { CogSpeedGraphicsHandler } from "./ui/handler"; | ||
|
||
|
||
function createApp(): Application { | ||
const gameWidth = window.innerWidth; | ||
const gameHeight = window.innerHeight; | ||
|
||
const app = new Application<HTMLCanvasElement>({ | ||
width: gameWidth, | ||
height: gameHeight, | ||
}); | ||
|
||
const appDiv = document.querySelector(".App"); | ||
if (!appDiv) throw new Error("No app div found"); | ||
appDiv.appendChild(app.view); | ||
|
||
return app; | ||
} | ||
|
||
|
||
/** | ||
* Loads the config from the backend | ||
* NOTE: Increases load time | ||
*/ | ||
async function loadConfig(): Promise<Config> { | ||
let url = "https://t6pedjjwcb.execute-api.us-east-2.amazonaws.com/default/getCogspeedConfig"; | ||
const params = new URLSearchParams(window.location.search); | ||
|
||
const version = params.get("version"); | ||
const branch = params.get("branch"); | ||
|
||
// Either append version or branch | ||
if (version) url += `?version=${version}`; | ||
else if (branch) url += `?branch=${branch}`; | ||
|
||
const request = await axios.get(url); | ||
return await request.data; | ||
} | ||
|
||
|
||
/** | ||
* | ||
* @param config | ||
* @param startNow Called from restart. Bypasses sleep data | ||
*/ | ||
export async function startUp (config: Config | null = null, startNow: boolean = false) { | ||
const app = createApp(); | ||
|
||
if (config === null) { | ||
config = await loadConfig(); | ||
if (config.error) throw new Error(config.reason); | ||
} | ||
|
||
// 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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters