1 import {gameManager} from "../Game/GameManager";
2 import {TextField} from "../Components/TextField";
3 import {TextInput} from "../Components/TextInput";
4 import {ClickButton} from "../Components/ClickButton";
5 import Image = Phaser.GameObjects.Image;
6 import Rectangle = Phaser.GameObjects.Rectangle;
7 import {PLAYER_RESOURCES} from "../Entity/Character";
8 import {cypressAsserter} from "../../Cypress/CypressAsserter";
9 import {SelectCharacterSceneInitDataInterface, SelectCharacterSceneName} from "./SelectCharacterScene";
11 //todo: put this constants in a dedicated file
12 export const LoginSceneName = "LoginScene";
15 mainFont = "main_font"
18 export class LoginScene extends Phaser.Scene {
19 private nameInput: TextInput|null = null;
20 private textField: TextField|null = null;
21 private infoTextField: TextField|null = null;
22 private pressReturnField: TextField|null = null;
23 private logo: Image|null = null;
24 private name: string = '';
30 if (window.localStorage) {
31 this.name = window.localStorage.getItem('playerName') ?? '';
36 cypressAsserter.preloadStarted();
37 //this.load.image(LoginTextures.playButton, "resources/objects/play_button.png");
38 this.load.image(LoginTextures.icon, "resources/logos/tcm_full.png");
39 // Note: arcade.png from the Phaser 3 examples at: https://github.com/photonstorm/phaser3-examples/tree/master/public/assets/fonts/bitmap
40 this.load.bitmapFont(LoginTextures.mainFont, 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml');
41 cypressAsserter.preloadFinished();
43 PLAYER_RESOURCES.forEach((playerResource: any) => {
44 this.load.spritesheet(
47 {frameWidth: 32, frameHeight: 32}
53 cypressAsserter.initStarted();
55 this.textField = new TextField(this, this.game.renderer.width / 2, 50, 'Enter your name:');
56 this.textField.setOrigin(0.5).setCenterAlign()
57 this.nameInput = new TextInput(this, this.game.renderer.width / 2 - 128, 70, 8, this.name,(text: string) => {
60 if (window.localStorage) {
61 window.localStorage.setItem('playerName', text);
65 this.pressReturnField = new TextField(this, this.game.renderer.width / 2, 130, 'Press enter to start');
66 this.pressReturnField.setOrigin(0.5).setCenterAlign()
68 //this.logo = new Image(this, this.game.renderer.width - 30, this.game.renderer.height - 20, LoginTextures.icon);
69 //this.add.existing(this.logo);
71 let infoText = "Commands: \n - Arrows or Z,Q,S,D to move\n - SHIFT to run";
72 this.infoTextField = new TextField(this, 10, this.game.renderer.height - 35, infoText);
74 this.input.keyboard.on('keyup-ENTER', () => {
75 if (this.name === '') {
78 this.login(this.name);
81 cypressAsserter.initFinished();
84 update(time: number, delta: number): void {
85 if (this.name == '') {
86 this.pressReturnField?.setVisible(false);
88 this.pressReturnField?.setVisible(!!(Math.floor(time / 500) % 2));
92 private login(name: string): void {
93 this.scene.start(SelectCharacterSceneName, { name } as SelectCharacterSceneInitDataInterface);