From f06abfae4c8edafee31304d3d9ef37823481cc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 16:51:51 +0200 Subject: [PATCH 01/10] Migrating to uuid v4 --- back/src/Controller/AuthenticateController.ts | 4 ++-- back/src/Controller/FileController.ts | 4 ++-- back/src/Controller/IoSocketController.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/back/src/Controller/AuthenticateController.ts b/back/src/Controller/AuthenticateController.ts index aa27a468..84cfd97f 100644 --- a/back/src/Controller/AuthenticateController.ts +++ b/back/src/Controller/AuthenticateController.ts @@ -1,6 +1,6 @@ import Jwt from "jsonwebtoken"; import {ADMIN_API_TOKEN, ADMIN_API_URL, SECRET_KEY, URL_ROOM_STARTED} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..." -import { uuid } from 'uuidv4'; +import { v4 } from 'uuid'; import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js"; import {BaseController} from "./BaseController"; import Axios from "axios"; @@ -63,7 +63,7 @@ export class AuthenticateController extends BaseController { mapUrlStart = data.mapUrlStart; newUrl = this.getNewUrlOnAdminAuth(data) } else { - userUuid = uuid(); + userUuid = v4(); mapUrlStart = host.replace('api.', 'maps.') + URL_ROOM_STARTED; newUrl = null; } diff --git a/back/src/Controller/FileController.ts b/back/src/Controller/FileController.ts index 889cfa61..87b72b80 100644 --- a/back/src/Controller/FileController.ts +++ b/back/src/Controller/FileController.ts @@ -1,6 +1,6 @@ import {App} from "../Server/sifrr.server"; -import {uuid} from "uuidv4"; +import {v4} from "uuid"; import {HttpRequest, HttpResponse} from "uWebSockets.js"; import {BaseController} from "./BaseController"; import { Readable } from 'stream' @@ -51,7 +51,7 @@ export class FileController extends BaseController { }) try { - const audioMessageId = uuid(); + const audioMessageId = v4(); const params = await res.formData({ onFile: (fieldname: string, diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index 9696748a..e9f97ea6 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -16,7 +16,7 @@ import {PointInterface} from "../Model/Websocket/PointInterface"; import {isWebRtcSignalMessageInterface} from "../Model/Websocket/WebRtcSignalMessage"; import {UserInGroupInterface} from "../Model/Websocket/UserInGroupInterface"; import {isItemEventMessageInterface} from "../Model/Websocket/ItemEventMessage"; -import {uuid} from 'uuidv4'; +import { v4 as uuidv4 } from 'uuid'; import {GroupUpdateInterface} from "_Model/Websocket/GroupUpdateInterface"; import {Movable} from "../Model/Movable"; import { @@ -135,7 +135,7 @@ export class IoSocketController { if (ALLOW_ARTILLERY) { return { token, - userUuid: uuid() + userUuid: uuidv4() } } else { throw new Error("In order to perform a load-testing test on this environment, you must set the ALLOW_ARTILLERY environment variable to 'true'"); From 8bc5832eac2651f2ca2a27c2393971edcb802296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 17:15:33 +0200 Subject: [PATCH 02/10] Removing warning on startup --- front/src/Connexion/ConnectionManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 4df45099..59a54510 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -10,7 +10,7 @@ interface LoginApiData { } class ConnectionManager { - private initPromise: Promise = Promise.reject(); + private initPromise!: Promise; private mapUrlStart: string|null = null; private authToken:string|null = null; From e1193ad95aa3c072ac4f45fa39f02d3d1cd637f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 17:16:36 +0200 Subject: [PATCH 03/10] Fixing console removal --- back/src/Model/Group.ts | 3 +-- front/src/Administration/ConsoleGlobalMessageManager.ts | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/back/src/Model/Group.ts b/back/src/Model/Group.ts index 16dd6cd5..a67383f0 100644 --- a/back/src/Model/Group.ts +++ b/back/src/Model/Group.ts @@ -1,7 +1,6 @@ -import { World, ConnectCallback, DisconnectCallback } from "./World"; +import { ConnectCallback, DisconnectCallback } from "./World"; import { User } from "./User"; import {PositionInterface} from "_Model/PositionInterface"; -import {uuid} from "uuidv4"; import {Movable} from "_Model/Movable"; import {PositionNotifier} from "_Model/PositionNotifier"; diff --git a/front/src/Administration/ConsoleGlobalMessageManager.ts b/front/src/Administration/ConsoleGlobalMessageManager.ts index e60b8a3d..135f1799 100644 --- a/front/src/Administration/ConsoleGlobalMessageManager.ts +++ b/front/src/Administration/ConsoleGlobalMessageManager.ts @@ -36,10 +36,8 @@ export class ConsoleGlobalMessageManager { } initialise() { - try { - HtmlUtils.removeElementByIdOrFail(CLASS_CONSOLE_MESSAGE); - }catch (err){ - console.error(err); + for (const elem of document.getElementsByClassName(CLASS_CONSOLE_MESSAGE)) { + elem.remove(); } const typeConsole = document.createElement('input'); From 1061c80f1ff66e9a3b68d61b45e76d9f7e8ded6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 17:16:49 +0200 Subject: [PATCH 04/10] Fixing connection closing --- front/src/Connexion/RoomConnection.ts | 5 +++++ front/src/Phaser/Game/GameScene.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 3492f0f9..a27bd323 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -43,6 +43,7 @@ export class RoomConnection implements RoomConnection { private userId: number|null = null; private listeners: Map = new Map(); private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any + private closed: boolean = false; public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any RoomConnection.websocketFactory = websocketFactory; @@ -157,6 +158,7 @@ export class RoomConnection implements RoomConnection { public closeConnection(): void { this.socket?.close(); + this.closed = true; } private resolveJoinRoom!: (value?: (RoomJoinedMessageInterface | PromiseLike | undefined)) => void; @@ -389,6 +391,9 @@ export class RoomConnection implements RoomConnection { public onServerDisconnected(callback: (event: CloseEvent) => void): void { this.socket.addEventListener('close', (event) => { + if (this.closed === true) { + return; + } console.log('Socket closed with code '+event.code+". Reason: "+event.reason); if (event.code === 1000) { // Normal closure case diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index bdaf3ac6..608d920b 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -951,7 +951,7 @@ export class GameScene extends Phaser.Scene implements CenterListener { }); const nextSceneKey = this.checkToExit(); - if(nextSceneKey){ + if (nextSceneKey) { // We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map. this.connection.closeConnection(); this.simplePeer.unregister(); From 79b5c5de93cd5e9e3d47da2403dd29638514b5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 7 Oct 2020 18:03:34 +0200 Subject: [PATCH 05/10] Making login scene responsive --- front/src/Phaser/Components/TextInput.ts | 12 ++++++++++++ front/src/Phaser/Login/LoginScene.ts | 23 +++++++++++++++++------ front/src/Phaser/Login/ResizableScene.ts | 5 +++++ front/src/index.ts | 8 ++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 front/src/Phaser/Login/ResizableScene.ts diff --git a/front/src/Phaser/Components/TextInput.ts b/front/src/Phaser/Components/TextInput.ts index 7a549d1f..47f713e0 100644 --- a/front/src/Phaser/Components/TextInput.ts +++ b/front/src/Phaser/Components/TextInput.ts @@ -38,4 +38,16 @@ export class TextInput extends Phaser.GameObjects.BitmapText { getText(): string { return this.text; } + + setX(x: number): this { + super.setX(x); + this.underLine.x = x; + return this; + } + + setY(y: number): this { + super.setY(y); + this.underLine.y = y+1; + return this; + } } diff --git a/front/src/Phaser/Login/LoginScene.ts b/front/src/Phaser/Login/LoginScene.ts index 308ba3ae..6e6bf291 100644 --- a/front/src/Phaser/Login/LoginScene.ts +++ b/front/src/Phaser/Login/LoginScene.ts @@ -7,6 +7,7 @@ import Rectangle = Phaser.GameObjects.Rectangle; import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Character"; import {cypressAsserter} from "../../Cypress/CypressAsserter"; import {SelectCharacterSceneName} from "./SelectCharacterScene"; +import {ResizableScene} from "./ResizableScene"; //todo: put this constants in a dedicated file export const LoginSceneName = "LoginScene"; @@ -15,12 +16,12 @@ enum LoginTextures { mainFont = "main_font" } -export class LoginScene extends Phaser.Scene { - private nameInput: TextInput|null = null; - private textField: TextField|null = null; - private infoTextField: TextField|null = null; - private pressReturnField: TextField|null = null; - private logo: Image|null = null; +export class LoginScene extends ResizableScene { + private nameInput!: TextInput; + private textField!: TextField; + private infoTextField!: TextField; + private pressReturnField!: TextField; + private logo!: Image; private name: string = ''; constructor() { @@ -93,4 +94,14 @@ export class LoginScene extends Phaser.Scene { this.scene.start(SelectCharacterSceneName); } + + public onResize(ev: UIEvent): void { + this.textField.x = this.game.renderer.width / 2; + this.nameInput.setX(this.game.renderer.width / 2 - 64); + this.pressReturnField.x = this.game.renderer.width / 2; + this.logo.x = this.game.renderer.width - 30; + this.logo.y = this.game.renderer.height - 20; + this.infoTextField.y = this.game.renderer.height - 35; + } + } diff --git a/front/src/Phaser/Login/ResizableScene.ts b/front/src/Phaser/Login/ResizableScene.ts new file mode 100644 index 00000000..82123e2b --- /dev/null +++ b/front/src/Phaser/Login/ResizableScene.ts @@ -0,0 +1,5 @@ +import {Scene} from "phaser"; + +export abstract class ResizableScene extends Scene { + public abstract onResize(ev: UIEvent): void; +} diff --git a/front/src/index.ts b/front/src/index.ts index 8e235c7a..177c56c0 100644 --- a/front/src/index.ts +++ b/front/src/index.ts @@ -12,6 +12,7 @@ import {OutlinePipeline} from "./Phaser/Shaders/OutlinePipeline"; import {CustomizeScene} from "./Phaser/Login/CustomizeScene"; import {CoWebsiteManager} from "./WebRtc/CoWebsiteManager"; import {connectionManager} from "./Connexion/ConnectionManager"; +import {ResizableScene} from "./Phaser/Login/ResizableScene"; //CoWebsiteManager.loadCoWebsite('https://thecodingmachine.com'); connectionManager.init(); @@ -55,6 +56,13 @@ window.addEventListener('resize', function (event) { const {width, height} = CoWebsiteManager.getGameSize(); game.scale.resize(width / RESOLUTION, height / RESOLUTION); + + // Let's trigger the onResize method of any active scene that is a ResizableScene + for (const scene of game.scene.getScenes(true)) { + if (scene instanceof ResizableScene) { + scene.onResize(event); + } + } }); CoWebsiteManager.onStateChange(() => { const {width, height} = CoWebsiteManager.getGameSize(); From 5ac208399507c63499f1fdfde101c6e3f9831872 Mon Sep 17 00:00:00 2001 From: arp Date: Thu, 8 Oct 2020 11:48:49 +0200 Subject: [PATCH 06/10] updated quill in front to 1.3.7 --- front/package.json | 2 +- front/yarn.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/front/package.json b/front/package.json index c3b9f880..4892eba1 100644 --- a/front/package.json +++ b/front/package.json @@ -27,7 +27,7 @@ "google-protobuf": "^3.13.0", "phaser": "^3.22.0", "queue-typescript": "^1.0.1", - "quill": "1.3.6", + "quill": "1.3.7", "simple-peer": "^9.6.2", "socket.io-client": "^2.3.0", "webpack-require-http": "^0.4.3" diff --git a/front/yarn.lock b/front/yarn.lock index c014d18d..933a02b4 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -1893,7 +1893,7 @@ extend-shallow@^3.0.0, extend-shallow@^3.0.2: assign-symbols "^1.0.0" is-extendable "^1.0.1" -extend@^3.0.1, extend@^3.0.2: +extend@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa" integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== @@ -3871,15 +3871,15 @@ quill-delta@^3.6.2: extend "^3.0.2" fast-diff "1.1.2" -quill@1.3.6: - version "1.3.6" - resolved "https://registry.yarnpkg.com/quill/-/quill-1.3.6.tgz#99f4de1fee85925a0d7d4163b6d8328f23317a4d" - integrity sha512-K0mvhimWZN6s+9OQ249CH2IEPZ9JmkFuCQeHAOQax3EZ2nDJ3wfGh59mnlQaZV2i7u8eFarx6wAtvQKgShojug== +quill@1.3.7: + version "1.3.7" + resolved "https://registry.yarnpkg.com/quill/-/quill-1.3.7.tgz#da5b2f3a2c470e932340cdbf3668c9f21f9286e8" + integrity sha512-hG/DVzh/TiknWtE6QmWAF/pxoZKYxfe3J/d/+ShUWkDvvkZQVTPeVmUJVu1uE6DDooC4fWTiCLh84ul89oNz5g== dependencies: clone "^2.1.1" deep-equal "^1.0.1" eventemitter3 "^2.0.3" - extend "^3.0.1" + extend "^3.0.2" parchment "^1.1.4" quill-delta "^3.6.2" From 78e7f481d559207046b7aa07ec0984557cb4c45c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:04:29 +0000 Subject: [PATCH 07/10] Bump elliptic from 6.4.1 to 6.5.3 in /website Bumps [elliptic](https://github.com/indutny/elliptic) from 6.4.1 to 6.5.3. - [Release notes](https://github.com/indutny/elliptic/releases) - [Commits](https://github.com/indutny/elliptic/compare/v6.4.1...v6.5.3) Signed-off-by: dependabot[bot] --- website/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/package-lock.json b/website/package-lock.json index 96ba750a..aec58f00 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -2287,9 +2287,9 @@ "dev": true }, "elliptic": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", - "integrity": "sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ==", + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", + "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", "dev": true, "requires": { "bn.js": "^4.4.0", From 607b495644d054460efe592a8918fb0a7cfaf94c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:04:31 +0000 Subject: [PATCH 08/10] Bump lodash from 4.17.15 to 4.17.20 in /website Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.20. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.20) Signed-off-by: dependabot[bot] --- website/package-lock.json | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/website/package-lock.json b/website/package-lock.json index 96ba750a..5d2a4c71 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -3487,13 +3487,6 @@ "glob": "~7.1.1", "lodash": "~4.17.12", "minimatch": "~3.0.2" - }, - "dependencies": { - "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" - } } }, "graceful-fs": { @@ -4234,9 +4227,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" }, "lodash.get": { "version": "4.4.2", @@ -4721,11 +4714,6 @@ "which": "^1.2.9" } }, - "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" - }, "lru-cache": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", From 66f33458617a99a51848731f4cd7695beb535a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 8 Oct 2020 15:10:46 +0200 Subject: [PATCH 09/10] Adding responsive to SelectCharacterScene --- .../src/Phaser/Login/SelectCharacterScene.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/front/src/Phaser/Login/SelectCharacterScene.ts b/front/src/Phaser/Login/SelectCharacterScene.ts index 8d3c7ab1..71b433b3 100644 --- a/front/src/Phaser/Login/SelectCharacterScene.ts +++ b/front/src/Phaser/Login/SelectCharacterScene.ts @@ -5,6 +5,7 @@ import Rectangle = Phaser.GameObjects.Rectangle; import {PLAYER_RESOURCES, PlayerResourceDescriptionInterface} from "../Entity/Character"; import {EnableCameraSceneName} from "./EnableCameraScene"; import {CustomizeSceneName} from "./CustomizeScene"; +import {ResizableScene} from "./ResizableScene"; //todo: put this constants in a dedicated file @@ -17,7 +18,7 @@ enum LoginTextures { customizeButtonSelected = "customize_button_selected" } -export class SelectCharacterScene extends Phaser.Scene { +export class SelectCharacterScene extends ResizableScene { private readonly nbCharactersPerRow = 4; private textField!: TextField; private pressReturnField!: TextField; @@ -242,4 +243,25 @@ export class SelectCharacterScene extends Phaser.Scene { window.localStorage.setItem('selectedPlayer', String(playerNumber)); } } + + public onResize(ev: UIEvent): void { + this.textField.x = this.game.renderer.width / 2; + this.pressReturnField.x = this.game.renderer.width / 2; + this.logo.x = this.game.renderer.width - 30; + this.logo.y = this.game.renderer.height - 20; + this.customizeButton.x = this.game.renderer.width / 2; + + for (let i = 0; i Date: Thu, 8 Oct 2020 16:00:29 +0200 Subject: [PATCH 10/10] Switching customizeScene and gameScene to new ResizableScene --- front/src/Phaser/Game/GameScene.ts | 10 +++------- front/src/Phaser/Login/CustomizeScene.ts | 11 +++-------- front/src/Phaser/Login/SelectCharacterScene.ts | 1 + 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 608d920b..f3381d5f 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -45,6 +45,7 @@ import {connectionManager} from "../../Connexion/ConnectionManager"; import {RoomConnection} from "../../Connexion/RoomConnection"; import {GlobalMessageManager} from "../../Administration/GlobalMessageManager"; import {ConsoleGlobalMessageManager} from "../../Administration/ConsoleGlobalMessageManager"; +import {ResizableScene} from "../Login/ResizableScene"; export enum Textures { @@ -86,7 +87,7 @@ interface DeleteGroupEventInterface { groupId: number } -export class GameScene extends Phaser.Scene implements CenterListener { +export class GameScene extends ResizableScene implements CenterListener { GameManager : GameManager; Terrains : Array; CurrentPlayer!: CurrentGamerInterface; @@ -132,7 +133,6 @@ export class GameScene extends Phaser.Scene implements CenterListener { private startLayerName: string|undefined; private presentationModeSprite!: Sprite; private chatModeSprite!: Sprite; - private onResizeCallback!: (this: Window, ev: UIEvent) => void; private gameMap!: GameMap; private actionableItems: Map = new Map(); // The item that can be selected by pressing the space key. @@ -271,7 +271,6 @@ export class GameScene extends Phaser.Scene implements CenterListener { this.scene.stop(this.scene.key); this.scene.remove(this.scene.key); - window.removeEventListener('resize', this.onResizeCallback); }) connection.onActionableEvent((message => { @@ -565,8 +564,6 @@ export class GameScene extends Phaser.Scene implements CenterListener { this.switchLayoutMode(); }); - this.onResizeCallback = this.onResize.bind(this); - window.addEventListener('resize', this.onResizeCallback); this.reposition(); // From now, this game scene will be notified of reposition events @@ -957,7 +954,6 @@ export class GameScene extends Phaser.Scene implements CenterListener { this.simplePeer.unregister(); this.scene.stop(); this.scene.remove(this.scene.key); - window.removeEventListener('resize', this.onResizeCallback); this.scene.start(nextSceneKey.key, { startLayerName: nextSceneKey.hash }); @@ -1156,7 +1152,7 @@ export class GameScene extends Phaser.Scene implements CenterListener { this.connection.emitActionableEvent(itemId, eventName, state, parameters); } - private onResize(): void { + public onResize(): void { this.reposition(); // Send new viewport to server diff --git a/front/src/Phaser/Login/CustomizeScene.ts b/front/src/Phaser/Login/CustomizeScene.ts index 50834bd1..4ada5026 100644 --- a/front/src/Phaser/Login/CustomizeScene.ts +++ b/front/src/Phaser/Login/CustomizeScene.ts @@ -6,6 +6,7 @@ import {LAYERS, loadAllLayers} from "../Entity/body_character"; import Sprite = Phaser.GameObjects.Sprite; import Container = Phaser.GameObjects.Container; import {gameManager} from "../Game/GameManager"; +import {ResizableScene} from "./ResizableScene"; export const CustomizeSceneName = "CustomizeScene"; @@ -16,7 +17,7 @@ enum CustomizeTextures{ arrowUp = "arrow_up", } -export class CustomizeScene extends Phaser.Scene { +export class CustomizeScene extends ResizableScene { private textField!: TextField; private enterField!: TextField; @@ -35,8 +36,6 @@ export class CustomizeScene extends Phaser.Scene { private containersRow: Array> = new Array>(); private activeRow = 0; - private repositionCallback!: (this: Window, ev: UIEvent) => void; - constructor() { super({ key: CustomizeSceneName @@ -144,10 +143,6 @@ export class CustomizeScene extends Phaser.Scene { this.moveLayers(); } }); - - this.repositionCallback = this.reposition.bind(this); - window.addEventListener('resize', this.repositionCallback); - } update(time: number, delta: number): void { super.update(time, delta); @@ -249,7 +244,7 @@ export class CustomizeScene extends Phaser.Scene { } } - private reposition() { + public onResize(): void { this.moveLayers(); this.Rectangle.x = this.cameras.main.worldView.x + this.cameras.main.width / 2; diff --git a/front/src/Phaser/Login/SelectCharacterScene.ts b/front/src/Phaser/Login/SelectCharacterScene.ts index 71b433b3..e5df0a0d 100644 --- a/front/src/Phaser/Login/SelectCharacterScene.ts +++ b/front/src/Phaser/Login/SelectCharacterScene.ts @@ -250,6 +250,7 @@ export class SelectCharacterScene extends ResizableScene { this.logo.x = this.game.renderer.width - 30; this.logo.y = this.game.renderer.height - 20; this.customizeButton.x = this.game.renderer.width / 2; + this.customizeButtonSelected.x = this.game.renderer.width / 2; for (let i = 0; i