From 85f84517f6db2f3d89dd4a3862b5eda3d527211b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 May 2020 22:23:41 +0200 Subject: [PATCH 1/7] Adding logo in the bottom right corner and placing help text in function of height --- front/src/Phaser/Components/TextField.ts | 4 ++-- front/src/Phaser/Login/LogincScene.ts | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/front/src/Phaser/Components/TextField.ts b/front/src/Phaser/Components/TextField.ts index 427a25ab..61a6f096 100644 --- a/front/src/Phaser/Components/TextField.ts +++ b/front/src/Phaser/Components/TextField.ts @@ -1,7 +1,7 @@ export class TextField extends Phaser.GameObjects.Text { constructor(scene: Phaser.Scene, x: number, y: number, text: string | string[]) { - super(scene, x, y, text, { fontFamily: 'Arial', fontSize: "20px", color: '#ffffff'}); + super(scene, x, y, text, { fontFamily: 'Arial', fontSize: "15px", color: '#ffffff'}); this.scene.add.existing(this) } -} \ No newline at end of file +} diff --git a/front/src/Phaser/Login/LogincScene.ts b/front/src/Phaser/Login/LogincScene.ts index 15ead519..42d46766 100644 --- a/front/src/Phaser/Login/LogincScene.ts +++ b/front/src/Phaser/Login/LogincScene.ts @@ -3,11 +3,13 @@ import {TextField} from "../Components/TextField"; import {TextInput} from "../Components/TextInput"; import {ClickButton} from "../Components/ClickButton"; import {GameSceneName} from "../Game/GameScene"; +import Image = Phaser.GameObjects.Image; //todo: put this constants in a dedicated file export const LoginSceneName = "LoginScene"; enum LoginTextures { playButton = "play_button", + icon = "icon" } export class LogincScene extends Phaser.Scene { @@ -15,6 +17,7 @@ export class LogincScene extends Phaser.Scene { private textField: TextField; private playButton: ClickButton; private infoTextField: TextField; + private logo: Image; constructor() { super({ @@ -24,18 +27,23 @@ export class LogincScene extends Phaser.Scene { preload() { this.load.image(LoginTextures.playButton, "resources/objects/play_button.png"); + this.load.image(LoginTextures.icon, "resources/logos/tcm_full.png"); } create() { - this.textField = new TextField(this, 10, 10, 'Enter your email:'); + this.textField = new TextField(this, 10, 10, 'Enter your name:'); this.emailInput = new TextInput(this, 10, 50); 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)); - let infoText = "Commandes de base: \n - Z,Q,S,D (ou les flèches de direction) pour bouger\n - SHIFT pour accélerer"; - this.infoTextField = new TextField(this, 10, 300, infoText); + 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); } update(time: number, delta: number): void { @@ -49,4 +57,4 @@ export class LogincScene extends Phaser.Scene { this.scene.start(GameSceneName); }); } -} \ No newline at end of file +} From 42ddd8b8586d8db70b26f85a4f052dbda3dffd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 May 2020 23:19:51 +0200 Subject: [PATCH 2/7] Changed font from text Input name can only be 4 characters long Passing name to next scene --- front/dist/resources/fonts/arcade.png | Bin 0 -> 3892 bytes front/dist/resources/fonts/arcade.xml | 83 ++++++++++++++++++ front/src/Phaser/Components/TextField.ts | 4 +- front/src/Phaser/Components/TextInput.ts | 16 ++-- front/src/Phaser/Game/GameScene.ts | 6 +- .../Phaser/Game/GameSceneInitDataInterface.ts | 3 + front/src/Phaser/Login/LogincScene.ts | 57 ++++++++---- 7 files changed, 141 insertions(+), 28 deletions(-) create mode 100644 front/dist/resources/fonts/arcade.png create mode 100644 front/dist/resources/fonts/arcade.xml create mode 100644 front/src/Phaser/Game/GameSceneInitDataInterface.ts diff --git a/front/dist/resources/fonts/arcade.png b/front/dist/resources/fonts/arcade.png new file mode 100644 index 0000000000000000000000000000000000000000..5b953b666301cd3b2b0002f84b3654f68d57bfa6 GIT binary patch literal 3892 zcmeH~`&Uy}7ROKUgYSxMASKug}Zd<#HYhZ1mkM0N{4M&wGzY z%0DqY-jzrxRHs%^XV#x1RoOD2Nu#i5^a_NpBMK#XSVg(*C?8M$zN$jRBEHGOD5P|F zR0s{1~c*-7uPVpjT+leS1~DE96iEnqPC4=X!UE-@Q39` zFLy}8tO^`8=i|CObr@Cb;m8YAVOfAyX-$GAj}OpCkX#qG`aJ-@n`!2Pl!lcf^tgCB z`*eauI2SJ))YwdAkhTM@_mM3826J2n3KXwJ0q_nY&6%P)ly)R`AdIb}j|lPU8KF6} z6{+wH%Xw1PBk1Ar_1Z`#lsB1TgMD^qLajCg4tF5yyt@EMJP$zeH&Je&!^6I-wi;4f z-75J;il?$3`&r-h`JpC<*O*`~bDSt4jX6aLu*MxKkj36L+DTFEk(L}g$^3-T8-|GR zEb?^#tTkE+P~?36T=`xmQ|RoK$4ysGF2B*@b9e9Xjd@iD`FKI>=g~iZyb}rFe!s&3 z?QR{)<-x}aV&B9n(C%qTo?2>ga@}a?o-~XhRd>f(wAn>>F;!_(0~3=8y0@36B1b)2 z{lD-LDRnT>Uhy8#2JU^K03{ID$HF0Cjdp^TNP3uSyI4~(TiMds(*zaLpmQ{f_K%NM zn5xDjU0AyMY#5b8gA604b8=c?QY}Vt{M}de6+tgZo%?44ZcHyq7^*&5GGk_%V_+V0 zXi7!JUS^XSWF5XlGrmXNW*LxlMkCy4Angc;_|e^|9D6IP^Nu6jr{~TwTM_*i?(P{x zo>P&x`@cuh!ClMkVJvaa}NnDXB&N9?ZXNA;lcVskFAQj_1S>j&Fv($IS6A;BAw6NKoT5T#;$B-n|DtiAGa>@U-XRx zk+i3Y9j%&5kdA?E&Rc2`7^yfhux6vx&E6`by5fen7Z@k}b=qQ}u zx}&gN3eWcl<_6$72tMs^tN80nhcn=N!hHU%;FS5k858W;U=uVs(#5&tYcd#NOOm^b z;&CH}n%Xjlh7|A9hnm?=VH#d}seiG|KQ=CxCnv9;LOb>sjUDLQ0B*0Z`a7U5^;XFxeZc{LsCzbprtD7$M=4KDm>rzi_!QOhT3N>r=D7CoST`~Mz~94S zlUL(QR@sz1w}YVWu7Mz{*JE^ys9IVTn4ykd>yNA8&R!e$uES(x2G^6Jd-a0>K7&^m z57-3tV*K7sgJ=dTx^J=W$n3nSR8Ok^;8MdK4Z~&}e`sgg3Q|RUx`?gRFi!nVaL+;s+&bPSZ`@iWSbCOaFC)G){SsU22(-^f#T?Oc+pnZ+}4NrYTtzb)0b@qlIzgi zAyRwY-n7t|{382+!5UvuL(_$Rn=e7a+@hpmzmh^RqrS*!^(_s<8>O6|E`a?D<)� zAk{6`9`V{Uy4&@)1s+(Wh9q&XSuqN<{HkP2wS1H##+T4VjiUvVCOQL}cL@wnaed_~ zjNvJ@D?rY1x10B1nG`Wibg*B){*R+7n-<`tx;Czb$Q#CNf z5jWyh=KeV9yWdHvoK9nRC+&@|Dfp6bQEsomK%HgZukAU31pZ6IxOshPrgG)$7IAjo zm`T@HUh!%Aqk|_pcV}05JW_&W0!<~lFeGe9(jgII_MsIfAzn9yjYa@;Vmyxu#~C;M z;l`ycnnW{jBDJbnSQUGd8u5wpAH_8++0=hCeGs~FsM=}N7;*4i9-wdhLJ0&L(RB^vp8Y07oUIXp1_{gEn6heclZhD%w^DigP2DI~V&n$uZFkCx8zb z{-xFB@_G$3vzk0B!KO=+7|P(vDKVIQKj1v?4P@SO?hB|B2zS3w{F?{A{NUHI?D>57 zQm9{t+vi?-Hn%O1`VyFzI{43GFM0U?JlyAji + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/front/src/Phaser/Components/TextField.ts b/front/src/Phaser/Components/TextField.ts index 61a6f096..abdc0535 100644 --- a/front/src/Phaser/Components/TextField.ts +++ b/front/src/Phaser/Components/TextField.ts @@ -1,7 +1,7 @@ -export class TextField extends Phaser.GameObjects.Text { +export class TextField extends Phaser.GameObjects.BitmapText { constructor(scene: Phaser.Scene, x: number, y: number, text: string | string[]) { - super(scene, x, y, text, { fontFamily: 'Arial', fontSize: "15px", color: '#ffffff'}); + super(scene, x, y, 'main_font', text, 8); this.scene.add.existing(this) } } diff --git a/front/src/Phaser/Components/TextInput.ts b/front/src/Phaser/Components/TextInput.ts index b6cfd9f4..b92da1ff 100644 --- a/front/src/Phaser/Components/TextInput.ts +++ b/front/src/Phaser/Components/TextInput.ts @@ -1,25 +1,25 @@ -export class TextInput extends Phaser.GameObjects.Text { +export class TextInput extends Phaser.GameObjects.BitmapText { private underLineLength = 10; private underLine: Phaser.GameObjects.Text; - constructor(scene: Phaser.Scene, x: number, y: number) { - super(scene, x, y, '', { fontFamily: 'Arial', fontSize: "20px", color: '#ffffff'}); + constructor(scene: Phaser.Scene, x: number, y: number, maxLength: number) { + super(scene, x, y, 'main_font', '', 32); this.scene.add.existing(this); - this.underLine = this.scene.add.text(x, y+1, '__________', { fontFamily: 'Arial', fontSize: "20px", color: '#ffffff'}) + this.underLine = this.scene.add.text(x, y+1, '_______', { fontFamily: 'Arial', fontSize: "32px", color: '#ffffff'}) + - let keySpace = this.scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); let keyBackspace = this.scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.BACKSPACE); this.scene.input.keyboard.on('keydown', (event: any) => { if (event.keyCode === 8 && this.text.length > 0) { this.deleteLetter(); - } else if (event.keyCode === 32 || (event.keyCode >= 48 && event.keyCode < 90)) { + } else if ((event.keyCode === 32 || (event.keyCode >= 48 && event.keyCode <= 90)) && this.text.length < maxLength) { this.addLetter(event.key); } }); } - + private deleteLetter() { this.text = this.text.substr(0, this.text.length - 1); if (this.underLine.text.length > this.underLineLength) { @@ -40,4 +40,4 @@ export class TextInput extends Phaser.GameObjects.Text { } -} \ No newline at end of file +} diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index f7fbd7c3..904b2d06 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -5,6 +5,7 @@ import {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVa import Tile = Phaser.Tilemaps.Tile; import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap"; import {cypressAsserter} from "../../Cypress/CypressAsserter"; +import { GameSceneInitDataInterface } from "./GameSceneInitDataInterface"; export const GameSceneName = "GameScene"; export enum Textures { @@ -28,6 +29,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ map: ITiledMap; startX = (window.innerWidth / 2) / RESOLUTION; startY = (window.innerHeight / 2) / RESOLUTION; + playerName: string; constructor() { @@ -65,7 +67,9 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ } //hook initialisation - init(){} + init(data: GameSceneInitDataInterface) { + this.playerName = data.name; + } //hook create scene create(): void { diff --git a/front/src/Phaser/Game/GameSceneInitDataInterface.ts b/front/src/Phaser/Game/GameSceneInitDataInterface.ts new file mode 100644 index 00000000..0014e1b7 --- /dev/null +++ b/front/src/Phaser/Game/GameSceneInitDataInterface.ts @@ -0,0 +1,3 @@ +export interface GameSceneInitDataInterface { + name: string +} diff --git a/front/src/Phaser/Login/LogincScene.ts b/front/src/Phaser/Login/LogincScene.ts index 42d46766..24fee6c5 100644 --- a/front/src/Phaser/Login/LogincScene.ts +++ b/front/src/Phaser/Login/LogincScene.ts @@ -4,19 +4,22 @@ import {TextInput} from "../Components/TextInput"; import {ClickButton} from "../Components/ClickButton"; import {GameSceneName} from "../Game/GameScene"; import Image = Phaser.GameObjects.Image; +import Key = Phaser.Input.Keyboard.Key; //todo: put this constants in a dedicated file export const LoginSceneName = "LoginScene"; enum LoginTextures { - playButton = "play_button", - icon = "icon" + //playButton = "play_button", + icon = "icon", + mainFont = "main_font" } export class LogincScene extends Phaser.Scene { - private emailInput: TextInput; + private nameInput: TextInput; private textField: TextField; private playButton: ClickButton; private infoTextField: TextField; + private pressReturnField: TextField; private logo: Image; constructor() { @@ -26,35 +29,55 @@ export class LogincScene extends Phaser.Scene { } preload() { - this.load.image(LoginTextures.playButton, "resources/objects/play_button.png"); + //this.load.image(LoginTextures.playButton, "resources/objects/play_button.png"); this.load.image(LoginTextures.icon, "resources/logos/tcm_full.png"); + // 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'); } create() { - this.textField = new TextField(this, 10, 10, 'Enter your name:'); - this.emailInput = new TextInput(this, 10, 50); + 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); - 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)); + this.pressReturnField = new TextField(this, this.game.renderer.width / 2, 130, 'Press enter to start'); + this.pressReturnField.setOrigin(0.5).setCenterAlign() + + //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)); 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); + 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 === '') { + return + }; + gameManager.connect(name).then(() => { + this.scene.start(GameSceneName, { name }); + }); + }); + } update(time: number, delta: number): void { - + if (this.nameInput.getText() == '') { + this.pressReturnField.setVisible(false); + } else { + this.pressReturnField.setVisible(!!(Math.floor(time / 500) % 2)); + } } - async login() { - let email = this.emailInput.text; - if (!email) return; - gameManager.connect(email).then(() => { + /*async login() { + let name = this.nameInput.text; + if (!name) return; + gameManager.connect(name).then(() => { this.scene.start(GameSceneName); }); - } + }*/ } From 0c04d4305ba4456ef293f8251ae897a54627b925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 May 2020 23:38:09 +0200 Subject: [PATCH 3/7] Displaying the name of a player above its head (names are not passed through the network yet) --- front/src/Phaser/Entity/PlayableCaracter.ts | 10 +++++++++- front/src/Phaser/Game/GameScene.ts | 4 ++++ front/src/Phaser/NonPlayer/NonPlayer.ts | 18 +++++++++--------- front/src/Phaser/Player/Player.ts | 3 ++- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/front/src/Phaser/Entity/PlayableCaracter.ts b/front/src/Phaser/Entity/PlayableCaracter.ts index 987d6bd3..3b1442c6 100644 --- a/front/src/Phaser/Entity/PlayableCaracter.ts +++ b/front/src/Phaser/Entity/PlayableCaracter.ts @@ -1,13 +1,20 @@ import {getPlayerAnimations, playAnimation, PlayerAnimationNames} from "../Player/Animation"; import {ActiveEventList, UserInputEvent} from "../UserInput/UserInputManager"; import {SpeechBubble} from "./SpeechBubble"; +import BitmapText = Phaser.GameObjects.BitmapText; export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite { private bubble: SpeechBubble; + private playerName: BitmapText; - constructor(scene: Phaser.Scene, x: number, y: number, texture: string, frame?: string | number) { + constructor(scene: Phaser.Scene, x: number, y: number, texture: string, name: string, frame?: string | number) { super(scene, x, y, texture, frame); + // Yes, I know, I'm declaring a sprite inside a sprite. ARP, save me from this madness :) + this.playerName = new BitmapText(scene, x, y - 32, 'main_font', name, 8); + this.playerName.setOrigin(0.5).setCenterAlign(); + scene.add.existing(this.playerName); + this.scene.sys.updateList.add(this); this.scene.sys.displayList.add(this); //this.setScale(2); @@ -36,6 +43,7 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite { if(this.bubble) { this.bubble.moveBubble(this.x, this.y); } + this.playerName.setPosition(this.x, this.y - 32); } stop(){ diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 904b2d06..f5a7728a 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -63,6 +63,8 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ 'resources/characters/pipoya/Male 01-1.png', { frameWidth: 32, frameHeight: 32 } ); + this.load.bitmapFont('main_font', 'resources/fonts/arcade.png', 'resources/fonts/arcade.xml'); + cypressAsserter.preloadFinished(); } @@ -166,6 +168,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ this, this.startX, this.startY, + this.playerName ); this.CurrentPlayer.initAnimation(); @@ -253,6 +256,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ this, MessageUserPosition.position.x, MessageUserPosition.position.y, + 'Foo' ); player.initAnimation(); this.MapPlayers.add(player); diff --git a/front/src/Phaser/NonPlayer/NonPlayer.ts b/front/src/Phaser/NonPlayer/NonPlayer.ts index 63012e46..42917505 100644 --- a/front/src/Phaser/NonPlayer/NonPlayer.ts +++ b/front/src/Phaser/NonPlayer/NonPlayer.ts @@ -6,13 +6,13 @@ import {MessageUserPositionInterface} from "../../Connexion"; import {playAnimation} from "../Player/Animation"; export class NonPlayer extends PlayableCaracter { - + isFleeing: boolean = false; fleeingDirection:any = null //todo create a vector class - - constructor(scene: Phaser.Scene, x: number, y: number) { - super(scene, x, y, Textures.Player, 1); - this.setSize(32, 32); //edit the hitbox to better match the caracter model + + constructor(scene: Phaser.Scene, x: number, y: number, name: string) { + super(scene, x, y, Textures.Player, name, 1); + this.setSize(32, 32); //edit the hitbox to better match the character model } @@ -26,15 +26,15 @@ export class NonPlayer extends PlayableCaracter { if (this.isFleeing) return; this.say("Don't touch me!"); this.isFleeing = true; - + setTimeout(() => { this.say("Feww, I escaped."); this.isFleeing = false this.fleeingDirection = null }, 3000); - - let vectorX = this.x - player.x; + + let vectorX = this.x - player.x; let vectorY = this.y - player.y; this.fleeingDirection = {x: vectorX, y: vectorY} } -} \ No newline at end of file +} diff --git a/front/src/Phaser/Player/Player.ts b/front/src/Phaser/Player/Player.ts index 60326a27..3c7c404f 100644 --- a/front/src/Phaser/Player/Player.ts +++ b/front/src/Phaser/Player/Player.ts @@ -31,9 +31,10 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G Scene: GameSceneInterface, x: number, y: number, + name: string, PlayerValue: string = Textures.Player ) { - super(Scene, x, y, PlayerValue, 1); + super(Scene, x, y, PlayerValue, name, 1); //create input to move this.userInputManager = new UserInputManager(Scene); From d72741ce0ccc84489d55afb18328acd220206e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 May 2020 23:48:30 +0200 Subject: [PATCH 4/7] Fixing linting --- back/package.json | 2 +- front/package.json | 3 ++- front/src/Phaser/Entity/PlayableCaracter.ts | 6 +++--- front/src/Phaser/Login/LogincScene.ts | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/back/package.json b/back/package.json index 1ea43f30..9e735d7b 100644 --- a/back/package.json +++ b/back/package.json @@ -9,7 +9,7 @@ "prod": "tsc && node ./dist/server.js", "test": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json", "lint": "node_modules/.bin/eslint src/ . --ext .ts", - "fix": "node_modules/.bin/eslint src/ . --ext .ts" + "fix": "node_modules/.bin/eslint --fix src/ . --ext .ts" }, "repository": { "type": "git", diff --git a/front/package.json b/front/package.json index 17c08137..c0f223b2 100644 --- a/front/package.json +++ b/front/package.json @@ -24,6 +24,7 @@ "scripts": { "start": "webpack-dev-server --open", "build": "webpack", - "lint": "node_modules/.bin/eslint src/ . --ext .ts" + "lint": "node_modules/.bin/eslint src/ . --ext .ts", + "fix": "node_modules/.bin/eslint --fix src/ . --ext .ts" } } diff --git a/front/src/Phaser/Entity/PlayableCaracter.ts b/front/src/Phaser/Entity/PlayableCaracter.ts index 3b1442c6..839a15f2 100644 --- a/front/src/Phaser/Entity/PlayableCaracter.ts +++ b/front/src/Phaser/Entity/PlayableCaracter.ts @@ -11,7 +11,7 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite { super(scene, x, y, texture, frame); // Yes, I know, I'm declaring a sprite inside a sprite. ARP, save me from this madness :) - this.playerName = new BitmapText(scene, x, y - 32, 'main_font', name, 8); + this.playerName = new BitmapText(scene, x, y - 25, 'main_font', name, 8); this.playerName.setOrigin(0.5).setCenterAlign(); scene.add.existing(this.playerName); @@ -43,7 +43,7 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite { if(this.bubble) { this.bubble.moveBubble(this.x, this.y); } - this.playerName.setPosition(this.x, this.y - 32); + this.playerName.setPosition(this.x, this.y - 25); } stop(){ @@ -54,7 +54,7 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite { say(text: string) { if (this.bubble) return; this.bubble = new SpeechBubble(this.scene, this, text) - //todo make the buble destroy on player movement? + //todo make the bubble destroy on player movement? setTimeout(() => { this.bubble.destroy(); this.bubble = null; diff --git a/front/src/Phaser/Login/LogincScene.ts b/front/src/Phaser/Login/LogincScene.ts index 24fee6c5..8a4c1e9a 100644 --- a/front/src/Phaser/Login/LogincScene.ts +++ b/front/src/Phaser/Login/LogincScene.ts @@ -57,7 +57,7 @@ export class LogincScene extends Phaser.Scene { let name = this.nameInput.getText(); if (name === '') { return - }; + } gameManager.connect(name).then(() => { this.scene.start(GameSceneName, { name }); }); From 5601e5e134caf6ea9a3c3db994c8ab8004973826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sun, 3 May 2020 15:18:15 +0200 Subject: [PATCH 5/7] Adding login method back for future use in LogincScene --- front/src/Phaser/Login/LogincScene.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/front/src/Phaser/Login/LogincScene.ts b/front/src/Phaser/Login/LogincScene.ts index 8a4c1e9a..e160ca8f 100644 --- a/front/src/Phaser/Login/LogincScene.ts +++ b/front/src/Phaser/Login/LogincScene.ts @@ -58,9 +58,7 @@ export class LogincScene extends Phaser.Scene { if (name === '') { return } - gameManager.connect(name).then(() => { - this.scene.start(GameSceneName, { name }); - }); + return this.login(name); }); } @@ -73,11 +71,9 @@ export class LogincScene extends Phaser.Scene { } } - /*async login() { - let name = this.nameInput.text; - if (!name) return; + private async login(name: string) { gameManager.connect(name).then(() => { this.scene.start(GameSceneName); }); - }*/ + } } From 76b745ebeab53410be168b4ef31fd92698e867ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sun, 3 May 2020 15:29:40 +0200 Subject: [PATCH 6/7] Putting the name in GameManager rather than passing it from scene to scene. --- front/src/Phaser/Game/GameManager.ts | 14 ++++++++++---- front/src/Phaser/Game/GameScene.ts | 7 ++----- .../src/Phaser/Game/GameSceneInitDataInterface.ts | 3 --- 3 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 front/src/Phaser/Game/GameSceneInitDataInterface.ts diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 1877b29a..83e205ec 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -15,14 +15,16 @@ export class GameManager { status: number; private ConnexionInstance: Connexion; private currentGameScene: GameScene; + private playerName: string; SimplePeer : SimplePeerInterface; constructor() { this.status = StatusGameManagerEnum.IN_PROGRESS; } - - connect(email:string) { - this.ConnexionInstance = new Connexion(email, this); + + connect(name:string) { + this.playerName = name; + this.ConnexionInstance = new Connexion(name, this); ConnexionInstance = this.ConnexionInstance; return this.ConnexionInstance.createConnexion().then(() => { this.SimplePeer = new SimplePeer(ConnexionInstance); @@ -57,6 +59,10 @@ export class GameManager { console.error(e); } } + + getPlayerName(): string { + return this.playerName; + } } -export const gameManager = new GameManager(); \ No newline at end of file +export const gameManager = new GameManager(); diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index f5a7728a..47499da6 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -5,7 +5,6 @@ import {DEBUG_MODE, RESOLUTION, ROOM, ZOOM_LEVEL} from "../../Enum/EnvironmentVa import Tile = Phaser.Tilemaps.Tile; import {ITiledMap, ITiledTileSet} from "../Map/ITiledMap"; import {cypressAsserter} from "../../Cypress/CypressAsserter"; -import { GameSceneInitDataInterface } from "./GameSceneInitDataInterface"; export const GameSceneName = "GameScene"; export enum Textures { @@ -29,7 +28,6 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ map: ITiledMap; startX = (window.innerWidth / 2) / RESOLUTION; startY = (window.innerHeight / 2) / RESOLUTION; - playerName: string; constructor() { @@ -69,8 +67,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ } //hook initialisation - init(data: GameSceneInitDataInterface) { - this.playerName = data.name; + init() { } //hook create scene @@ -168,7 +165,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ this, this.startX, this.startY, - this.playerName + this.GameManager.getPlayerName() ); this.CurrentPlayer.initAnimation(); diff --git a/front/src/Phaser/Game/GameSceneInitDataInterface.ts b/front/src/Phaser/Game/GameSceneInitDataInterface.ts deleted file mode 100644 index 0014e1b7..00000000 --- a/front/src/Phaser/Game/GameSceneInitDataInterface.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface GameSceneInitDataInterface { - name: string -} From c4f1aa1811b73d1329c813f1b1ff2ab4dd7e15ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Sun, 3 May 2020 15:31:20 +0200 Subject: [PATCH 7/7] Removing comment --- front/src/Phaser/Entity/PlayableCaracter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/front/src/Phaser/Entity/PlayableCaracter.ts b/front/src/Phaser/Entity/PlayableCaracter.ts index 839a15f2..aaf53224 100644 --- a/front/src/Phaser/Entity/PlayableCaracter.ts +++ b/front/src/Phaser/Entity/PlayableCaracter.ts @@ -10,7 +10,6 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite { constructor(scene: Phaser.Scene, x: number, y: number, texture: string, name: string, frame?: string | number) { super(scene, x, y, texture, frame); - // Yes, I know, I'm declaring a sprite inside a sprite. ARP, save me from this madness :) this.playerName = new BitmapText(scene, x, y - 25, 'main_font', name, 8); this.playerName.setOrigin(0.5).setCenterAlign(); scene.add.existing(this.playerName);