72 lines
1.6 KiB
JavaScript
72 lines
1.6 KiB
JavaScript
|
/**
|
||
|
* @file This file is the root of the website.
|
||
|
* @author Arlo Filley
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Loads any assets before the setup function.
|
||
|
* This allows p5.js to access these assets including: sprites,
|
||
|
* fonts, etc.
|
||
|
* @returns {void}
|
||
|
*/
|
||
|
function preload() {
|
||
|
roboto = loadFont('./assets/fonts/RobotoMono-Medium.ttf');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Defines variables and sets up the p5.js canvas
|
||
|
* ready to be drawn with using the draw() function.
|
||
|
* @returns {void}
|
||
|
*/
|
||
|
async function setup() {
|
||
|
canvas = new Canvas();
|
||
|
canvas.resize();
|
||
|
canvas.center();
|
||
|
|
||
|
frameRate(60);
|
||
|
|
||
|
api = new API();
|
||
|
screenManager = new ScreenManager();
|
||
|
/**
|
||
|
* @type {User}
|
||
|
*/
|
||
|
user = new User();
|
||
|
await api.getTest();
|
||
|
console.log(user.nextTest);
|
||
|
screenManager.setScreen(new TestScreen());
|
||
|
|
||
|
api.login(null, null, true);
|
||
|
textFont(roboto);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Called once per frame. Draws all other elements onto the canvas.
|
||
|
* Mostly will just call the screenManager.draw() method to make
|
||
|
* sure that the correct screen is being drawn.
|
||
|
* @returns {void}
|
||
|
*/
|
||
|
function draw() {
|
||
|
background(user.colorScheme.background);
|
||
|
screenManager.draw();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Called whenever a key is pressed. The variable key contains the
|
||
|
* key that the user last pressed.
|
||
|
* @returns {void}
|
||
|
*/
|
||
|
function keyPressed() {
|
||
|
screenManager.letterTyped(key);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Called whenever the user resizes the window. Uses methods from the canvas wrapper class
|
||
|
* to resize and center the canvas such that it displays correctly.
|
||
|
* @returns {void}
|
||
|
*/
|
||
|
function windowResized() {
|
||
|
canvas.resize();
|
||
|
canvas.center();
|
||
|
}
|