2020-05-06 01:50:01 +02:00
|
|
|
import {gameManager} from "../Game/GameManager";
|
2020-04-26 17:54:56 +02:00
|
|
|
import {TextField} from "../Components/TextField";
|
|
|
|
import {TextInput} from "../Components/TextInput";
|
|
|
|
import {ClickButton} from "../Components/ClickButton";
|
2020-05-01 22:23:41 +02:00
|
|
|
import Image = Phaser.GameObjects.Image;
|
2020-05-04 01:48:14 +02:00
|
|
|
import Rectangle = Phaser.GameObjects.Rectangle;
|
2020-05-06 01:50:01 +02:00
|
|
|
import {PLAYER_RESOURCES} from "../Entity/PlayableCaracter";
|
2020-05-04 18:38:04 +02:00
|
|
|
import {cypressAsserter} from "../../Cypress/CypressAsserter";
|
2020-05-26 17:25:29 +02:00
|
|
|
import {SelectCharacterSceneInitDataInterface, SelectCharacterSceneName} from "./SelectCharacterScene";
|
2020-04-26 17:54:56 +02:00
|
|
|
|
|
|
|
//todo: put this constants in a dedicated file
|
|
|
|
export const LoginSceneName = "LoginScene";
|
|
|
|
enum LoginTextures {
|
2020-05-01 23:19:51 +02:00
|
|
|
icon = "icon",
|
|
|
|
mainFont = "main_font"
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
|
|
|
|
2020-05-24 23:14:12 +02:00
|
|
|
export class LoginScene extends Phaser.Scene {
|
2020-05-01 23:19:51 +02:00
|
|
|
private nameInput: TextInput;
|
2020-04-26 17:54:56 +02:00
|
|
|
private textField: TextField;
|
2020-04-26 18:48:41 +02:00
|
|
|
private infoTextField: TextField;
|
2020-05-01 23:19:51 +02:00
|
|
|
private pressReturnField: TextField;
|
2020-05-01 22:23:41 +02:00
|
|
|
private logo: Image;
|
2020-05-26 22:17:00 +02:00
|
|
|
private name: string;
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
key: LoginSceneName
|
|
|
|
});
|
2020-05-26 22:17:00 +02:00
|
|
|
if (window.localStorage && window.localStorage.playerName) {
|
|
|
|
this.name = window.localStorage.getItem('playerName');
|
|
|
|
}
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-04-26 17:54:56 +02:00
|
|
|
preload() {
|
2020-05-04 18:38:04 +02:00
|
|
|
cypressAsserter.preloadStarted();
|
2020-05-01 23:19:51 +02:00
|
|
|
//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-05-01 23:19:51 +02:00
|
|
|
// Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
|
|
|
|
this.load.bitmapFont(LoginTextures.mainFont, 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
|
2020-05-04 18:38:04 +02:00
|
|
|
cypressAsserter.preloadFinished();
|
2020-05-04 01:48:14 +02:00
|
|
|
//add player png
|
2020-05-06 01:50:01 +02:00
|
|
|
PLAYER_RESOURCES.forEach((playerResource: any) => {
|
2020-05-04 01:48:14 +02:00
|
|
|
this.load.spritesheet(
|
|
|
|
playerResource.name,
|
|
|
|
playerResource.img,
|
|
|
|
{frameWidth: 32, frameHeight: 32}
|
|
|
|
);
|
|
|
|
});
|
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-04 18:38:04 +02:00
|
|
|
cypressAsserter.initStarted();
|
|
|
|
|
2020-05-01 23:19:51 +02:00
|
|
|
this.textField = new TextField(this, this.game.renderer.width / 2, 50, 'Enter your name:');
|
|
|
|
this.textField.setOrigin(0.5).setCenterAlign()
|
2020-05-26 22:17:00 +02:00
|
|
|
this.nameInput = new TextInput(this, this.game.renderer.width / 2 - 64, 70, 4, this.name,(text: string) => {
|
|
|
|
this.name = text;
|
|
|
|
if (window.localStorage) {
|
|
|
|
window.localStorage.setItem('playerName', text);
|
|
|
|
}
|
|
|
|
});
|
2020-04-26 18:48:41 +02:00
|
|
|
|
2020-05-01 23:19:51 +02:00
|
|
|
this.pressReturnField = new TextField(this, this.game.renderer.width / 2, 130, 'Press enter to start');
|
|
|
|
this.pressReturnField.setOrigin(0.5).setCenterAlign()
|
|
|
|
|
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";
|
2020-05-01 23:19:51 +02:00
|
|
|
this.infoTextField = new TextField(this, 10, this.game.renderer.height - 35, infoText);
|
|
|
|
|
|
|
|
this.input.keyboard.on('keyup-ENTER', () => {
|
2020-05-26 22:17:00 +02:00
|
|
|
if (this.name === '') {
|
2020-05-01 23:19:51 +02:00
|
|
|
return
|
2020-05-01 23:48:30 +02:00
|
|
|
}
|
2020-05-26 22:17:00 +02:00
|
|
|
this.login(this.name);
|
2020-05-01 23:19:51 +02:00
|
|
|
});
|
|
|
|
|
2020-05-04 18:38:04 +02:00
|
|
|
cypressAsserter.initFinished();
|
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-05-26 22:17:00 +02:00
|
|
|
if (this.name == '') {
|
2020-05-01 23:19:51 +02:00
|
|
|
this.pressReturnField.setVisible(false);
|
|
|
|
} else {
|
|
|
|
this.pressReturnField.setVisible(!!(Math.floor(time / 500) % 2));
|
|
|
|
}
|
2020-04-26 17:54:56 +02:00
|
|
|
}
|
2020-04-29 00:01:37 +02:00
|
|
|
|
2020-05-26 17:25:29 +02:00
|
|
|
private login(name: string): void {
|
|
|
|
this.scene.start(SelectCharacterSceneName, { name } as SelectCharacterSceneInitDataInterface);
|
2020-05-04 01:48:14 +02:00
|
|
|
}
|
2020-05-01 22:23:41 +02:00
|
|
|
}
|