From 39928b46f9982d5db3e8916d917bb82c6e77e774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 10 Jun 2020 12:15:25 +0200 Subject: [PATCH] Removing any in the front --- front/src/Cypress/CypressAsserter.ts | 12 ++++-- front/src/Phaser/Game/GameManager.ts | 6 +-- front/src/Phaser/Game/GameScene.ts | 27 ++++++------- .../src/Phaser/UserInput/UserInputManager.ts | 13 +++--- front/src/WebRtc/MediaManager.ts | 40 +++++++++++-------- 5 files changed, 52 insertions(+), 46 deletions(-) diff --git a/front/src/Cypress/CypressAsserter.ts b/front/src/Cypress/CypressAsserter.ts index 95adb156..82eeab1f 100644 --- a/front/src/Cypress/CypressAsserter.ts +++ b/front/src/Cypress/CypressAsserter.ts @@ -1,13 +1,17 @@ -declare let window:any; +declare let window:WindowWithCypressAsserter; + +interface WindowWithCypressAsserter extends Window { + cypressAsserter: CypressAsserter; +} //this class is used to communicate with cypress, our e2e testing client //Since cypress cannot manipulate canvas, we notified it with console logs class CypressAsserter { - + constructor() { window.cypressAsserter = this } - + gameStarted() { console.log('Started the game') } @@ -29,4 +33,4 @@ class CypressAsserter { } } -export const cypressAsserter = new CypressAsserter() \ No newline at end of file +export const cypressAsserter = new CypressAsserter() diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index e4f77d8a..ec20411f 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -1,6 +1,6 @@ import {GameScene} from "./GameScene"; import { - Connection, + Connection, ConnectionInterface, GroupCreatedUpdatedMessageInterface, ListMessageUserPositionInterface, MessageUserJoined, @@ -44,11 +44,11 @@ export class GameManager { //this.status = StatusGameManagerEnum.IN_PROGRESS; } - connect(name: string, characterUserSelected : string) { + public connect(name: string, characterUserSelected : string): Promise { this.playerName = name; this.characterUserSelected = characterUserSelected; this.ConnectionInstance = new Connection(this); - return this.ConnectionInstance.createConnection(name, characterUserSelected).then((data : any) => { + return this.ConnectionInstance.createConnection(name, characterUserSelected).then((data : ConnectionInterface) => { this.SimplePeer = new SimplePeer(this.ConnectionInstance); return data; }).catch((err) => { diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index ed5d8956..42115915 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -58,7 +58,7 @@ export class GameScene extends Phaser.Scene { y: -1000 } - PositionNextScene: Array = new Array(); + private PositionNextScene: Array> = new Array>(); private startLayerName: string|undefined; static createFromUrl(mapUrlFile: string, instance: string): GameScene { @@ -295,15 +295,13 @@ export class GameScene extends Phaser.Scene { } //push and save switching case - // TODO: this is not efficient. We should refactor that to enable a search by key. For instance: this.PositionNextScene[y][x] = exitSceneKey - this.PositionNextScene.push({ - xStart: (x * tileWidth), - yStart: (y * tileWidth), - xEnd: ((x +1) * tileHeight), - yEnd: ((y + 1) * tileHeight), + if (this.PositionNextScene[y] === undefined) { + this.PositionNextScene[y] = new Array<{key: string, hash: string}>(); + } + this.PositionNextScene[y][x] = { key: exitSceneKey, hash - }) + } } } @@ -469,14 +467,15 @@ export class GameScene extends Phaser.Scene { /** * */ - checkToExit(){ - if(this.PositionNextScene.length === 0){ + checkToExit(): {key: string, hash: string} | null { + const x = Math.floor(this.CurrentPlayer.x / 32); + const y = Math.floor(this.CurrentPlayer.y / 32); + + if (this.PositionNextScene[y] !== undefined && this.PositionNextScene[y][x] !== undefined) { + return this.PositionNextScene[y][x]; + } else { return null; } - return this.PositionNextScene.find((position : any) => { - return position.xStart <= this.CurrentPlayer.x && this.CurrentPlayer.x <= position.xEnd - && position.yStart <= this.CurrentPlayer.y && this.CurrentPlayer.y <= position.yEnd - }) } public initUsersPosition(usersPosition: MessageUserPositionInterface[]): void { diff --git a/front/src/Phaser/UserInput/UserInputManager.ts b/front/src/Phaser/UserInput/UserInputManager.ts index 1b68feff..eddbbf74 100644 --- a/front/src/Phaser/UserInput/UserInputManager.ts +++ b/front/src/Phaser/UserInput/UserInputManager.ts @@ -1,4 +1,3 @@ -import Map = Phaser.Structs.Map; import {GameScene} from "../Game/GameScene"; interface UserInputManagerDatum { @@ -18,15 +17,13 @@ export enum UserInputEvent { //we cannot the map structure so we have to create a replacment export class ActiveEventList { - private KeysCode : any; - constructor() { - this.KeysCode = {}; - } + private KeysCode : Map = new Map(); + get(event: UserInputEvent): boolean { - return this.KeysCode[event] || false; + return this.KeysCode.get(event) || false; } - set(event: UserInputEvent, value: boolean): boolean { - return this.KeysCode[event] = true; + set(event: UserInputEvent, value: boolean): void { + this.KeysCode.set(event, value); } } diff --git a/front/src/WebRtc/MediaManager.ts b/front/src/WebRtc/MediaManager.ts index 80be3f47..b70ea9de 100644 --- a/front/src/WebRtc/MediaManager.ts +++ b/front/src/WebRtc/MediaManager.ts @@ -1,18 +1,18 @@ -const videoConstraint: {width : any, height: any, facingMode : string} = { +const videoConstraint: boolean|MediaTrackConstraints = { width: { ideal: 1280 }, height: { ideal: 720 }, facingMode: "user" }; export class MediaManager { localStream: MediaStream|null = null; - remoteVideo: Array = new Array(); + private remoteVideo: Map = new Map(); myCamVideo: HTMLVideoElement; - cinemaClose: any = null; - cinema: any = null; - microphoneClose: any = null; - microphone: any = null; + cinemaClose: HTMLImageElement; + cinema: HTMLImageElement; + microphoneClose: HTMLImageElement; + microphone: HTMLImageElement; webrtcInAudio: HTMLAudioElement; - constraintsMedia : {audio : any, video : any} = { + constraintsMedia : MediaStreamConstraints = { audio: true, video: videoConstraint }; @@ -25,29 +25,29 @@ export class MediaManager { this.webrtcInAudio = this.getElementByIdOrFail('audio-webrtc-in'); this.webrtcInAudio.volume = 0.2; - this.microphoneClose = document.getElementById('microphone-close'); + this.microphoneClose = this.getElementByIdOrFail('microphone-close'); this.microphoneClose.style.display = "none"; - this.microphoneClose.addEventListener('click', (e: any) => { + this.microphoneClose.addEventListener('click', (e: MouseEvent) => { e.preventDefault(); this.enabledMicrophone(); //update tracking }); - this.microphone = document.getElementById('microphone'); - this.microphone.addEventListener('click', (e: any) => { + this.microphone = this.getElementByIdOrFail('microphone'); + this.microphone.addEventListener('click', (e: MouseEvent) => { e.preventDefault(); this.disabledMicrophone(); //update tracking }); - this.cinemaClose = document.getElementById('cinema-close'); + this.cinemaClose = this.getElementByIdOrFail('cinema-close'); this.cinemaClose.style.display = "none"; - this.cinemaClose.addEventListener('click', (e: any) => { + this.cinemaClose.addEventListener('click', (e: MouseEvent) => { e.preventDefault(); this.enabledCamera(); //update tracking }); - this.cinema = document.getElementById('cinema'); - this.cinema.addEventListener('click', (e: any) => { + this.cinema = this.getElementByIdOrFail('cinema'); + this.cinema.addEventListener('click', (e: MouseEvent) => { e.preventDefault(); this.disabledCamera(); //update tracking @@ -150,7 +150,7 @@ export class MediaManager { `); - this.remoteVideo[(userId as any)] = document.getElementById(userId); + this.remoteVideo.set(userId, this.getElementByIdOrFail(userId)); } /** @@ -215,7 +215,12 @@ export class MediaManager { * @param stream */ addStreamRemoteVideo(userId : string, stream : MediaStream){ - this.remoteVideo[(userId as any)].srcObject = stream; + const remoteVideo = this.remoteVideo.get(userId); + if (remoteVideo === undefined) { + console.error('Unable to find video for ', userId); + return; + } + remoteVideo.srcObject = stream; } /** @@ -228,6 +233,7 @@ export class MediaManager { return; } element.remove(); + this.remoteVideo.delete(userId); } isConnecting(userId : string): void {