From 24fb605f50c823ee8d9347d6c4dc8255d6bc6b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 7 Aug 2020 23:39:06 +0200 Subject: [PATCH] Switching to definitely assigned parameters This allows us to go in "full strict mode" (yeah!) See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#strict-class-initialization --- front/src/Phaser/Entity/RemotePlayer.ts | 2 -- front/src/Phaser/Game/GameManager.ts | 4 +-- front/src/Phaser/Game/GameScene.ts | 28 +++++++++---------- front/src/Phaser/Login/CustomizeScene.ts | 18 ++++++------ front/src/Phaser/Login/EnableCameraScene.ts | 22 +++++++-------- .../src/Phaser/Login/SelectCharacterScene.ts | 14 +++++----- front/src/Phaser/Player/Player.ts | 4 +-- .../src/Phaser/Reconnecting/FourOFourScene.ts | 12 ++++---- .../Phaser/Reconnecting/ReconnectingScene.ts | 5 ++-- front/tsconfig.json | 4 +-- 10 files changed, 55 insertions(+), 58 deletions(-) diff --git a/front/src/Phaser/Entity/RemotePlayer.ts b/front/src/Phaser/Entity/RemotePlayer.ts index 18785331..6764ff59 100644 --- a/front/src/Phaser/Entity/RemotePlayer.ts +++ b/front/src/Phaser/Entity/RemotePlayer.ts @@ -7,8 +7,6 @@ import {Character} from "../Entity/Character"; */ export class RemotePlayer extends Character { userId: string; - previousDirection: string; - wasMoving: boolean; constructor( userId: string, diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 3dcf3474..db119a13 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -13,8 +13,8 @@ export interface HasMovedEvent { } export class GameManager { - private playerName: string; - private characterLayers: string[]; + private playerName!: string; + private characterLayers!: string[]; public setPlayerName(name: string): void { this.playerName = name; diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 1a3cd9b7..487f3fb1 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -73,31 +73,31 @@ interface DeleteGroupEventInterface { export class GameScene extends Phaser.Scene { GameManager : GameManager; Terrains : Array; - CurrentPlayer: CurrentGamerInterface; - MapPlayers : Phaser.Physics.Arcade.Group; + CurrentPlayer!: CurrentGamerInterface; + MapPlayers!: Phaser.Physics.Arcade.Group; MapPlayersByKey : Map = new Map(); - Map: Phaser.Tilemaps.Tilemap; - Layers : Array; - Objects : Array; - mapFile: ITiledMap; + Map!: Phaser.Tilemaps.Tilemap; + Layers!: Array; + Objects!: Array; + mapFile!: ITiledMap; groups: Map; - startX: number; - startY: number; - circleTexture: CanvasTexture; + startX!: number; + startY!: number; + circleTexture!: CanvasTexture; pendingEvents: Queue = new Queue(); private initPosition: PositionInterface|null = null; private playersPositionInterpolator = new PlayersPositionInterpolator(); - private connection: Connection; - private simplePeer : SimplePeer; - private connectionPromise: Promise + private connection!: Connection; + private simplePeer!: SimplePeer; + private connectionPromise!: Promise MapKey: string; MapUrlFile: string; RoomId: string; instance: string; - currentTick: number; - lastSentTick: number; // The last tick at which a position was sent. + currentTick!: number; + lastSentTick!: number; // The last tick at which a position was sent. lastMoveEventSent: HasMovedEvent = { direction: '', moving: false, diff --git a/front/src/Phaser/Login/CustomizeScene.ts b/front/src/Phaser/Login/CustomizeScene.ts index a4c4282f..50834bd1 100644 --- a/front/src/Phaser/Login/CustomizeScene.ts +++ b/front/src/Phaser/Login/CustomizeScene.ts @@ -18,24 +18,24 @@ enum CustomizeTextures{ export class CustomizeScene extends Phaser.Scene { - private textField: TextField; - private enterField: TextField; + private textField!: TextField; + private enterField!: TextField; - private arrowRight: Image; - private arrowLeft: Image; + private arrowRight!: Image; + private arrowLeft!: Image; - private arrowDown: Image; - private arrowUp: Image; + private arrowDown!: Image; + private arrowUp!: Image; - private Rectangle: Rectangle; + private Rectangle!: Rectangle; - private logo: Image; + private logo!: Image; private selectedLayers: Array = [0]; private containersRow: Array> = new Array>(); private activeRow = 0; - private repositionCallback: (this: Window, ev: UIEvent) => void; + private repositionCallback!: (this: Window, ev: UIEvent) => void; constructor() { super({ diff --git a/front/src/Phaser/Login/EnableCameraScene.ts b/front/src/Phaser/Login/EnableCameraScene.ts index 6d96459e..7e631b6b 100644 --- a/front/src/Phaser/Login/EnableCameraScene.ts +++ b/front/src/Phaser/Login/EnableCameraScene.ts @@ -21,22 +21,22 @@ enum LoginTextures { } export class EnableCameraScene extends Phaser.Scene { - private textField: TextField; - private pressReturnField: TextField; - private cameraNameField: TextField; - private logo: Image; - private arrowLeft: Image; - private arrowRight: Image; - private arrowDown: Image; - private arrowUp: Image; + private textField!: TextField; + private pressReturnField!: TextField; + private cameraNameField!: TextField; + private logo!: Image; + private arrowLeft!: Image; + private arrowRight!: Image; + private arrowDown!: Image; + private arrowUp!: Image; private microphonesList: MediaDeviceInfo[] = new Array(); private camerasList: MediaDeviceInfo[] = new Array(); private cameraSelected: number = 0; private microphoneSelected: number = 0; private soundMeter: SoundMeter; - private soundMeterSprite: SoundMeterSprite; - private microphoneNameField: TextField; - private repositionCallback: (this: Window, ev: UIEvent) => void; + private soundMeterSprite!: SoundMeterSprite; + private microphoneNameField!: TextField; + private repositionCallback!: (this: Window, ev: UIEvent) => void; constructor() { super({ diff --git a/front/src/Phaser/Login/SelectCharacterScene.ts b/front/src/Phaser/Login/SelectCharacterScene.ts index 535529ee..64285766 100644 --- a/front/src/Phaser/Login/SelectCharacterScene.ts +++ b/front/src/Phaser/Login/SelectCharacterScene.ts @@ -21,16 +21,16 @@ enum LoginTextures { export class SelectCharacterScene extends Phaser.Scene { private readonly nbCharactersPerRow = 4; - private textField: TextField; - private pressReturnField: TextField; - private logo: Image; - private customizeButton: Image; - private customizeButtonSelected: Image; + private textField!: TextField; + private pressReturnField!: TextField; + private logo!: Image; + private customizeButton!: Image; + private customizeButtonSelected!: Image; - private selectedRectangle: Rectangle; + private selectedRectangle!: Rectangle; private selectedRectangleXPos = 0; // Number of the character selected in the rows private selectedRectangleYPos = 0; // Number of the character selected in the columns - private selectedPlayer: Phaser.Physics.Arcade.Sprite|null; // null if we are selecting the "customize" option + private selectedPlayer!: Phaser.Physics.Arcade.Sprite|null; // null if we are selecting the "customize" option private players: Array = new Array(); constructor() { diff --git a/front/src/Phaser/Player/Player.ts b/front/src/Phaser/Player/Player.ts index b9490c8d..cfd6cc6e 100644 --- a/front/src/Phaser/Player/Player.ts +++ b/front/src/Phaser/Player/Player.ts @@ -13,8 +13,8 @@ export interface CurrentGamerInterface extends Character{ export class Player extends Character implements CurrentGamerInterface { userInputManager: UserInputManager; - previousDirection: string; - wasMoving: boolean; + previousDirection: string = PlayerAnimationNames.WalkDown; + wasMoving: boolean = false; constructor( Scene: GameScene, diff --git a/front/src/Phaser/Reconnecting/FourOFourScene.ts b/front/src/Phaser/Reconnecting/FourOFourScene.ts index 8c71ae65..0c91a5bc 100644 --- a/front/src/Phaser/Reconnecting/FourOFourScene.ts +++ b/front/src/Phaser/Reconnecting/FourOFourScene.ts @@ -10,12 +10,12 @@ enum Textures { } export class FourOFourScene extends Phaser.Scene { - private mapNotFoundField: TextField; - private couldNotFindField: TextField; - private fileNameField: Text; - private logo: Image; - private cat: Sprite; - private file: string; + private mapNotFoundField!: TextField; + private couldNotFindField!: TextField; + private fileNameField!: Text; + private logo!: Image; + private cat!: Sprite; + private file!: string; constructor() { super({ diff --git a/front/src/Phaser/Reconnecting/ReconnectingScene.ts b/front/src/Phaser/Reconnecting/ReconnectingScene.ts index 7a377b66..07d2b858 100644 --- a/front/src/Phaser/Reconnecting/ReconnectingScene.ts +++ b/front/src/Phaser/Reconnecting/ReconnectingScene.ts @@ -9,9 +9,8 @@ enum ReconnectingTextures { } export class ReconnectingScene extends Phaser.Scene { - private reconnectingField: TextField; - private logo: Image; - private cat: Sprite; + private reconnectingField!: TextField; + private logo!: Image; constructor() { super({ diff --git a/front/tsconfig.json b/front/tsconfig.json index 1661efa2..e56a6ee7 100644 --- a/front/tsconfig.json +++ b/front/tsconfig.json @@ -10,12 +10,12 @@ "jsx": "react", "allowJs": true, - "strict": false, /* Enable all strict type-checking options. */ + "strict": true, /* Enable all strict type-checking options. */ "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ "strictNullChecks": true, /* Enable strict null checks. */ "strictFunctionTypes": true, /* Enable strict checking of function types. */ "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - "strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */ + "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */