From 5f118c2a4a5eb13867f6f60735ef80442e74bbdf Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20N=C3=A9grier?= Date: Wed, 15 Apr 2020 19:39:26 +0200 Subject: [PATCH] Removing all reference to 'Tiles' constant in code --- front/src/Phaser/Game/GameScene.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index a089842..e8597d7 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -8,8 +8,7 @@ import {ITiledMap} from "../Map/ITiledMap"; export enum Textures { Rock = 'rock', Player = 'playerModel', - Map = 'map', - Tiles = 'tiles' + Map = 'map' } export interface GameSceneInterface extends Phaser.Scene { @@ -21,21 +20,25 @@ export interface GameSceneInterface extends Phaser.Scene { export class GameScene extends Phaser.Scene implements GameSceneInterface{ GameManager : GameManagerInterface; RoomId : string; - Terrain : Phaser.Tilemaps.Tileset; + Terrains : Array; CurrentPlayer: CurrentGamerInterface; MapPlayers : Phaser.Physics.Arcade.Group; Map: Phaser.Tilemaps.Tilemap; Layers : Array; Objects : Array; + tilesetKeys : Array; startX = (window.innerWidth / 2) / RESOLUTION; startY = (window.innerHeight / 2) / RESOLUTION; + constructor(RoomId : string, GameManager : GameManagerInterface) { super({ key: "GameScene" }); this.RoomId = RoomId; this.GameManager = GameManager; + this.tilesetKeys = []; + this.Terrains = []; } //hook preload scene @@ -48,6 +51,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ map.tilesets.forEach((tileset) => { let path = mapUrl.substr(0, mapUrl.lastIndexOf('/')); this.load.image(tileset.name, path + '/' + tileset.image); + this.tilesetKeys.push(tileset.name); }) }); this.load.tilemapTiledJSON(Textures.Map, mapUrl); @@ -66,16 +70,17 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{ //initalise map this.Map = this.add.tilemap("map"); - this.Terrain = this.Map.addTilesetImage("tiles", "tiles"); - this.Map.createStaticLayer("tiles", "tiles"); + this.tilesetKeys.forEach((key: string) => { + this.Terrains.push(this.Map.addTilesetImage(key, key)); + }); //permit to set bound collision this.physics.world.setBounds(0,0, this.Map.widthInPixels, this.Map.heightInPixels); //add layer on map this.Layers = new Array(); - this.addLayer( this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0).setDepth(-2) ); - this.addLayer( this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0).setDepth(-1) ); + this.addLayer( this.Map.createStaticLayer("Calque 1", this.Terrains, 0, 0).setDepth(-2) ); + this.addLayer( this.Map.createStaticLayer("Calque 2", this.Terrains, 0, 0).setDepth(-1) ); //add entities this.Objects = new Array(); -- 2.25.1