From d48d5b0285ef0729c2c86f4920cc0ac6a8adf562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 23 Jul 2020 18:47:28 +0200 Subject: [PATCH] Fix CS --- back/src/Controller/MapController.ts | 2 +- front/src/Phaser/Game/GameScene.ts | 23 +++++++++++---------- front/src/Phaser/Items/ActionableItem.ts | 2 +- front/src/Phaser/Items/Computer/computer.ts | 2 +- front/src/index.ts | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/back/src/Controller/MapController.ts b/back/src/Controller/MapController.ts index af2ba848..58ce40a9 100644 --- a/back/src/Controller/MapController.ts +++ b/back/src/Controller/MapController.ts @@ -19,7 +19,7 @@ export class MapController { // Returns a map mapping map name to file name of the map getStartMap() { this.App.get("/start-map", (req: Request, res: Response) => { - let url = req.headers.host?.replace('api.', 'maps.') + URL_ROOM_STARTED; + const url = req.headers.host?.replace('api.', 'maps.') + URL_ROOM_STARTED; res.status(OK).send({ mapUrlStart: url, startInstance: "global" diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 6d311e33..9ee54058 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -252,11 +252,11 @@ export class GameScene extends Phaser.Scene { }) // Scan the object layers for objects to load and load them. - let objects = new Map(); + const objects = new Map(); - for (let layer of this.mapFile.layers) { + for (const layer of this.mapFile.layers) { if (layer.type === 'objectgroup') { - for (let object of layer.objects) { + for (const object of layer.objects) { let objectsOfType: ITiledMapObject[]|undefined; if (!objects.has(object.type)) { objectsOfType = new Array(); @@ -272,16 +272,17 @@ export class GameScene extends Phaser.Scene { } } - for (let [itemType, objectsOfType] of objects) { + for (const [itemType, objectsOfType] of objects) { // FIXME: we would ideally need for the loader to WAIT for the import to be performed, which means writing our own loader plugin. let itemFactory: ItemFactoryInterface; switch (itemType) { - case 'computer': - let module = await import('../Items/Computer/computer'); - itemFactory = module.default as ItemFactoryInterface; + case 'computer': { + const module = await import('../Items/Computer/computer'); + itemFactory = module.default; break; + } default: throw new Error('Unsupported object type: "'+ itemType +'"'); } @@ -295,9 +296,9 @@ export class GameScene extends Phaser.Scene { this.createPromise.then(() => { itemFactory.create(this); - for (let object of objectsOfType) { + for (const object of objectsOfType) { // TODO: we should pass here a factory to create sprites (maybe?) - let actionableItem = itemFactory.factory(this, object); + const actionableItem = itemFactory.factory(this, object); this.actionableItems.push(actionableItem); } }); @@ -675,8 +676,8 @@ export class GameScene extends Phaser.Scene { let shortestDistance: number = Infinity; let selectedItem: ActionableItem|null = null; - for (let item of this.actionableItems) { - let distance = item.actionableDistance(x, y); + for (const item of this.actionableItems) { + const distance = item.actionableDistance(x, y); if (distance !== null && distance < shortestDistance) { shortestDistance = distance; selectedItem = item; diff --git a/front/src/Phaser/Items/ActionableItem.ts b/front/src/Phaser/Items/ActionableItem.ts index 229b0888..01e85c64 100644 --- a/front/src/Phaser/Items/ActionableItem.ts +++ b/front/src/Phaser/Items/ActionableItem.ts @@ -18,7 +18,7 @@ export class ActionableItem { * OR null if we are out of range. */ public actionableDistance(x: number, y: number): number|null { - let distanceSquared = (x - this.sprite.x)*(x - this.sprite.x) + (y - this.sprite.y)*(y - this.sprite.y); + const distanceSquared = (x - this.sprite.x)*(x - this.sprite.x) + (y - this.sprite.y)*(y - this.sprite.y); if (distanceSquared < this.activationRadiusSquared) { return distanceSquared; } else { diff --git a/front/src/Phaser/Items/Computer/computer.ts b/front/src/Phaser/Items/Computer/computer.ts index 7ea7b318..b979ebf6 100644 --- a/front/src/Phaser/Items/Computer/computer.ts +++ b/front/src/Phaser/Items/Computer/computer.ts @@ -15,7 +15,7 @@ export default { }, factory: (scene: GameScene, object: ITiledMapObject): ActionableItem => { // Idée: ESSAYER WebPack? https://paultavares.wordpress.com/2018/07/02/webpack-how-to-generate-an-es-module-bundle/ - let foo = new Sprite(scene, object.x, object.y, 'computer'); + const foo = new Sprite(scene, object.x, object.y, 'computer'); scene.add.existing(foo); return new ActionableItem(foo, 32); diff --git a/front/src/index.ts b/front/src/index.ts index b847fa74..bf744a36 100644 --- a/front/src/index.ts +++ b/front/src/index.ts @@ -27,7 +27,7 @@ const config: GameConfig = { callbacks: { postBoot: game => { // FIXME: we should fore WebGL in the config. - let renderer = game.renderer as WebGLRenderer; + const renderer = game.renderer as WebGLRenderer; renderer.addPipeline(OutlinePipeline.KEY, new OutlinePipeline(game)); } }