export class TextInput extends Phaser.GameObjects.BitmapText {
private underLineLength = 10;
private underLine: Phaser.GameObjects.Text;
- constructor(scene: Phaser.Scene, x: number, y: number, maxLength: number) {
- super(scene, x, y, 'main_font', '', 32);
+
+ constructor(scene: Phaser.Scene, x: number, y: number, maxLength: number, text: string, onChange: (text: string) => void) {
+ super(scene, x, y, 'main_font', text, 32);
this.scene.add.existing(this);
this.underLine = this.scene.add.text(x, y+1, '_______', { fontFamily: 'Arial', fontSize: "32px", color: '#ffffff'})
} else if ((event.keyCode === 32 || (event.keyCode >= 48 && event.keyCode <= 90)) && this.text.length < maxLength) {
this.addLetter(event.key);
}
+ onChange(this.text);
});
}
getText(): string {
return this.text;
}
-
-
}
private infoTextField: TextField;
private pressReturnField: TextField;
private logo: Image;
+ private name: string;
constructor() {
super({
key: LoginSceneName
});
+ if (window.localStorage && window.localStorage.playerName) {
+ this.name = window.localStorage.getItem('playerName');
+ }
}
preload() {
this.textField = new TextField(this, this.game.renderer.width / 2, 50, 'Enter your name:');
this.textField.setOrigin(0.5).setCenterAlign()
- this.nameInput = new TextInput(this, this.game.renderer.width / 2 - 64, 70, 4);
+ 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);
+ }
+ });
this.pressReturnField = new TextField(this, this.game.renderer.width / 2, 130, 'Press enter to start');
this.pressReturnField.setOrigin(0.5).setCenterAlign()
this.infoTextField = new TextField(this, 10, this.game.renderer.height - 35, infoText);
this.input.keyboard.on('keyup-ENTER', () => {
- let name = this.nameInput.getText();
- if (name === '') {
+ if (this.name === '') {
return
}
- this.login(name);
+ this.login(this.name);
});
cypressAsserter.initFinished();
}
update(time: number, delta: number): void {
- if (this.nameInput.getText() == '') {
+ if (this.name == '') {
this.pressReturnField.setVisible(false);
} else {
this.pressReturnField.setVisible(!!(Math.floor(time / 500) % 2));