Removing any in the front

This commit is contained in:
David Négrier 2020-06-10 12:15:25 +02:00
parent 8348d13bfe
commit 39928b46f9
5 changed files with 52 additions and 46 deletions

View File

@ -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 //this class is used to communicate with cypress, our e2e testing client
//Since cypress cannot manipulate canvas, we notified it with console logs //Since cypress cannot manipulate canvas, we notified it with console logs
class CypressAsserter { class CypressAsserter {
constructor() { constructor() {
window.cypressAsserter = this window.cypressAsserter = this
} }
gameStarted() { gameStarted() {
console.log('Started the game') console.log('Started the game')
} }
@ -29,4 +33,4 @@ class CypressAsserter {
} }
} }
export const cypressAsserter = new CypressAsserter() export const cypressAsserter = new CypressAsserter()

View File

@ -1,6 +1,6 @@
import {GameScene} from "./GameScene"; import {GameScene} from "./GameScene";
import { import {
Connection, Connection, ConnectionInterface,
GroupCreatedUpdatedMessageInterface, GroupCreatedUpdatedMessageInterface,
ListMessageUserPositionInterface, ListMessageUserPositionInterface,
MessageUserJoined, MessageUserJoined,
@ -44,11 +44,11 @@ export class GameManager {
//this.status = StatusGameManagerEnum.IN_PROGRESS; //this.status = StatusGameManagerEnum.IN_PROGRESS;
} }
connect(name: string, characterUserSelected : string) { public connect(name: string, characterUserSelected : string): Promise<ConnectionInterface> {
this.playerName = name; this.playerName = name;
this.characterUserSelected = characterUserSelected; this.characterUserSelected = characterUserSelected;
this.ConnectionInstance = new Connection(this); 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); this.SimplePeer = new SimplePeer(this.ConnectionInstance);
return data; return data;
}).catch((err) => { }).catch((err) => {

View File

@ -58,7 +58,7 @@ export class GameScene extends Phaser.Scene {
y: -1000 y: -1000
} }
PositionNextScene: Array<any> = new Array<any>(); private PositionNextScene: Array<Array<{ key: string, hash: string }>> = new Array<Array<{ key: string, hash: string }>>();
private startLayerName: string|undefined; private startLayerName: string|undefined;
static createFromUrl(mapUrlFile: string, instance: string): GameScene { static createFromUrl(mapUrlFile: string, instance: string): GameScene {
@ -295,15 +295,13 @@ export class GameScene extends Phaser.Scene {
} }
//push and save switching case //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 if (this.PositionNextScene[y] === undefined) {
this.PositionNextScene.push({ this.PositionNextScene[y] = new Array<{key: string, hash: string}>();
xStart: (x * tileWidth), }
yStart: (y * tileWidth), this.PositionNextScene[y][x] = {
xEnd: ((x +1) * tileHeight),
yEnd: ((y + 1) * tileHeight),
key: exitSceneKey, key: exitSceneKey,
hash hash
}) }
} }
} }
@ -469,14 +467,15 @@ export class GameScene extends Phaser.Scene {
/** /**
* *
*/ */
checkToExit(){ checkToExit(): {key: string, hash: string} | null {
if(this.PositionNextScene.length === 0){ 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 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 { public initUsersPosition(usersPosition: MessageUserPositionInterface[]): void {

View File

@ -1,4 +1,3 @@
import Map = Phaser.Structs.Map;
import {GameScene} from "../Game/GameScene"; import {GameScene} from "../Game/GameScene";
interface UserInputManagerDatum { interface UserInputManagerDatum {
@ -18,15 +17,13 @@ export enum UserInputEvent {
//we cannot the map structure so we have to create a replacment //we cannot the map structure so we have to create a replacment
export class ActiveEventList { export class ActiveEventList {
private KeysCode : any; private KeysCode : Map<UserInputEvent, boolean> = new Map<UserInputEvent, boolean>();
constructor() {
this.KeysCode = {};
}
get(event: UserInputEvent): boolean { get(event: UserInputEvent): boolean {
return this.KeysCode[event] || false; return this.KeysCode.get(event) || false;
} }
set(event: UserInputEvent, value: boolean): boolean { set(event: UserInputEvent, value: boolean): void {
return this.KeysCode[event] = true; this.KeysCode.set(event, value);
} }
} }

View File

@ -1,18 +1,18 @@
const videoConstraint: {width : any, height: any, facingMode : string} = { const videoConstraint: boolean|MediaTrackConstraints = {
width: { ideal: 1280 }, width: { ideal: 1280 },
height: { ideal: 720 }, height: { ideal: 720 },
facingMode: "user" facingMode: "user"
}; };
export class MediaManager { export class MediaManager {
localStream: MediaStream|null = null; localStream: MediaStream|null = null;
remoteVideo: Array<any> = new Array<any>(); private remoteVideo: Map<string, HTMLVideoElement> = new Map<string, HTMLVideoElement>();
myCamVideo: HTMLVideoElement; myCamVideo: HTMLVideoElement;
cinemaClose: any = null; cinemaClose: HTMLImageElement;
cinema: any = null; cinema: HTMLImageElement;
microphoneClose: any = null; microphoneClose: HTMLImageElement;
microphone: any = null; microphone: HTMLImageElement;
webrtcInAudio: HTMLAudioElement; webrtcInAudio: HTMLAudioElement;
constraintsMedia : {audio : any, video : any} = { constraintsMedia : MediaStreamConstraints = {
audio: true, audio: true,
video: videoConstraint video: videoConstraint
}; };
@ -25,29 +25,29 @@ export class MediaManager {
this.webrtcInAudio = this.getElementByIdOrFail<HTMLAudioElement>('audio-webrtc-in'); this.webrtcInAudio = this.getElementByIdOrFail<HTMLAudioElement>('audio-webrtc-in');
this.webrtcInAudio.volume = 0.2; this.webrtcInAudio.volume = 0.2;
this.microphoneClose = document.getElementById('microphone-close'); this.microphoneClose = this.getElementByIdOrFail<HTMLImageElement>('microphone-close');
this.microphoneClose.style.display = "none"; this.microphoneClose.style.display = "none";
this.microphoneClose.addEventListener('click', (e: any) => { this.microphoneClose.addEventListener('click', (e: MouseEvent) => {
e.preventDefault(); e.preventDefault();
this.enabledMicrophone(); this.enabledMicrophone();
//update tracking //update tracking
}); });
this.microphone = document.getElementById('microphone'); this.microphone = this.getElementByIdOrFail<HTMLImageElement>('microphone');
this.microphone.addEventListener('click', (e: any) => { this.microphone.addEventListener('click', (e: MouseEvent) => {
e.preventDefault(); e.preventDefault();
this.disabledMicrophone(); this.disabledMicrophone();
//update tracking //update tracking
}); });
this.cinemaClose = document.getElementById('cinema-close'); this.cinemaClose = this.getElementByIdOrFail<HTMLImageElement>('cinema-close');
this.cinemaClose.style.display = "none"; this.cinemaClose.style.display = "none";
this.cinemaClose.addEventListener('click', (e: any) => { this.cinemaClose.addEventListener('click', (e: MouseEvent) => {
e.preventDefault(); e.preventDefault();
this.enabledCamera(); this.enabledCamera();
//update tracking //update tracking
}); });
this.cinema = document.getElementById('cinema'); this.cinema = this.getElementByIdOrFail<HTMLImageElement>('cinema');
this.cinema.addEventListener('click', (e: any) => { this.cinema.addEventListener('click', (e: MouseEvent) => {
e.preventDefault(); e.preventDefault();
this.disabledCamera(); this.disabledCamera();
//update tracking //update tracking
@ -150,7 +150,7 @@ export class MediaManager {
<video id="${userId}" autoplay></video> <video id="${userId}" autoplay></video>
</div> </div>
`); `);
this.remoteVideo[(userId as any)] = document.getElementById(userId); this.remoteVideo.set(userId, this.getElementByIdOrFail<HTMLVideoElement>(userId));
} }
/** /**
@ -215,7 +215,12 @@ export class MediaManager {
* @param stream * @param stream
*/ */
addStreamRemoteVideo(userId : string, stream : MediaStream){ 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; return;
} }
element.remove(); element.remove();
this.remoteVideo.delete(userId);
} }
isConnecting(userId : string): void { isConnecting(userId : string): void {