Skip to content
Snippets Groups Projects
Verified Commit b6bef85a authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Document game class

parent 080456f0
No related branches found
No related tags found
No related merge requests found
Pipeline #7397 passed
......@@ -18,8 +18,15 @@ import SplashScene from './scenes/splash';
import LoginScene from './scenes/login';
import './game.css';
/** Main game class serving as frontend. */
class Game extends Phaser.Game {
/**
* Construct a game instance linked to an already initialised backend.
*
* @param {object} backend - Reference to the backend instance
*/
constructor(backend) {
// Phaser configuration
const config = {
title: 'Aug[m]entile',
url: 'https://edugit.org/auglement/augmentile',
......@@ -29,7 +36,7 @@ class Game extends Phaser.Game {
height: window.innerHeight,
parent: 'phaser-container',
dom: {
createContainer: true,
createContainer: true, // Needed for Rex UI
},
scale: {
mode: Phaser.Scale.FIT,
......@@ -38,18 +45,32 @@ class Game extends Phaser.Game {
scene: [SplashScene, LoginScene],
};
// Pass config to parent class (Phaser itself)
super(config);
// Establish dual-link between game and backend
this.backend = backend;
this.backend.game = this;
}
/**
* Called by backend after successful login.
*
* @todo Use events or similar instead
*/
loggedIn() {
this.scene.start('splash', {
'message': 'Loading game state...',
});
}
/**
* Called by backend on login error.
*
* @param {string} error message from login
*
* @todo Use events or similar instead
*/
loginError(error) {
this.scene.start('login', {
'message': error,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment