2020-04-26 17:54:56 +02:00
|
|
|
import {gameManager} from "../Game/GameManager";
|
|
|
|
import {TextField} from "../Components/TextField";
|
|
|
|
import {TextInput} from "../Components/TextInput";
|
|
|
|
import {ClickButton} from "../Components/ClickButton";
|
2020-04-30 19:18:35 +02:00
|
|
|
import {GameSceneName} from "../Game/GameScene";
|
2020-05-01 22:23:41 +02:00
|
|
|
import Image = Phaser.GameObjects.Image;
|
2020-04-26 17:54:56 +02:00
|
|
|
|
|
|
|
//todo: put this constants in a dedicated file
|
|
|
|
export const LoginSceneName = "LoginScene";
|
|
|
|
enum LoginTextures {
|
|
|
|
playButton = "play_button",
|
2020-05-01 22:23:41 +02:00
|
|
|
icon = "icon"
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
|
|
|
|
2020-04-30 19:18:35 +02:00
|
|
|
export class LogincScene extends Phaser.Scene {
|
2020-04-26 17:54:56 +02:00
|
|
|
private emailInput: TextInput;
|
|
|
|
private textField: TextField;
|
|
|
|
private playButton: ClickButton;
|
2020-04-26 18:48:41 +02:00
|
|
|
private infoTextField: TextField;
|
2020-05-01 22:23:41 +02:00
|
|
|
private logo: Image;
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
key: LoginSceneName
|
|
|
|
});
|
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
preload() {
|
|
|
|
this.load.image(LoginTextures.playButton, "resources/objects/play_button.png");
|
2020-05-01 22:23:41 +02:00
|
|
|
this.load.image(LoginTextures.icon, "resources/logos/tcm_full.png");
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
create() {
|
2020-05-01 22:23:41 +02:00
|
|
|
this.textField = new TextField(this, 10, 10, 'Enter your name:');
|
2020-04-26 17:54:56 +02:00
|
|
|
this.emailInput = new TextInput(this, 10, 50);
|
2020-04-26 18:48:41 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
let x = this.game.renderer.width / 2;
|
|
|
|
let y = this.game.renderer.height / 2;
|
|
|
|
this.playButton = new ClickButton(this, x, y, LoginTextures.playButton, this.login.bind(this));
|
2020-04-26 18:48:41 +02:00
|
|
|
|
2020-05-01 22:23:41 +02:00
|
|
|
this.logo = new Image(this, this.game.renderer.width - 30, this.game.renderer.height - 20, LoginTextures.icon);
|
|
|
|
this.add.existing(this.logo);
|
|
|
|
|
|
|
|
|
|
|
|
let infoText = "Commands: \n - Arrows or Z,Q,S,D to move\n - SHIFT to run";
|
|
|
|
this.infoTextField = new TextField(this, 10, this.game.renderer.height - 60, infoText);
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
update(time: number, delta: number): void {
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
async login() {
|
|
|
|
let email = this.emailInput.text;
|
|
|
|
if (!email) return;
|
2020-04-29 00:01:37 +02:00
|
|
|
gameManager.connect(email).then(() => {
|
2020-04-30 19:18:35 +02:00
|
|
|
this.scene.start(GameSceneName);
|
2020-04-29 00:01:37 +02:00
|
|
|
});
|
|
|
|
}
|
2020-05-01 22:23:41 +02:00
|
|
|
}
|