Removing all reference to 'Tiles' constant in code

This commit is contained in:
David Négrier 2020-04-15 19:39:26 +02:00
parent b7220a6724
commit 5f118c2a4a

View File

@ -8,8 +8,7 @@ import {ITiledMap} from "../Map/ITiledMap";
export enum Textures { export enum Textures {
Rock = 'rock', Rock = 'rock',
Player = 'playerModel', Player = 'playerModel',
Map = 'map', Map = 'map'
Tiles = 'tiles'
} }
export interface GameSceneInterface extends Phaser.Scene { export interface GameSceneInterface extends Phaser.Scene {
@ -21,21 +20,25 @@ export interface GameSceneInterface extends Phaser.Scene {
export class GameScene extends Phaser.Scene implements GameSceneInterface{ export class GameScene extends Phaser.Scene implements GameSceneInterface{
GameManager : GameManagerInterface; GameManager : GameManagerInterface;
RoomId : string; RoomId : string;
Terrain : Phaser.Tilemaps.Tileset; Terrains : Array<Phaser.Tilemaps.Tileset>;
CurrentPlayer: CurrentGamerInterface; CurrentPlayer: CurrentGamerInterface;
MapPlayers : Phaser.Physics.Arcade.Group; MapPlayers : Phaser.Physics.Arcade.Group;
Map: Phaser.Tilemaps.Tilemap; Map: Phaser.Tilemaps.Tilemap;
Layers : Array<Phaser.Tilemaps.StaticTilemapLayer>; Layers : Array<Phaser.Tilemaps.StaticTilemapLayer>;
Objects : Array<Phaser.Physics.Arcade.Sprite>; Objects : Array<Phaser.Physics.Arcade.Sprite>;
tilesetKeys : Array<string>;
startX = (window.innerWidth / 2) / RESOLUTION; startX = (window.innerWidth / 2) / RESOLUTION;
startY = (window.innerHeight / 2) / RESOLUTION; startY = (window.innerHeight / 2) / RESOLUTION;
constructor(RoomId : string, GameManager : GameManagerInterface) { constructor(RoomId : string, GameManager : GameManagerInterface) {
super({ super({
key: "GameScene" key: "GameScene"
}); });
this.RoomId = RoomId; this.RoomId = RoomId;
this.GameManager = GameManager; this.GameManager = GameManager;
this.tilesetKeys = [];
this.Terrains = [];
} }
//hook preload scene //hook preload scene
@ -48,6 +51,7 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
map.tilesets.forEach((tileset) => { map.tilesets.forEach((tileset) => {
let path = mapUrl.substr(0, mapUrl.lastIndexOf('/')); let path = mapUrl.substr(0, mapUrl.lastIndexOf('/'));
this.load.image(tileset.name, path + '/' + tileset.image); this.load.image(tileset.name, path + '/' + tileset.image);
this.tilesetKeys.push(tileset.name);
}) })
}); });
this.load.tilemapTiledJSON(Textures.Map, mapUrl); this.load.tilemapTiledJSON(Textures.Map, mapUrl);
@ -66,16 +70,17 @@ export class GameScene extends Phaser.Scene implements GameSceneInterface{
//initalise map //initalise map
this.Map = this.add.tilemap("map"); this.Map = this.add.tilemap("map");
this.Terrain = this.Map.addTilesetImage("tiles", "tiles"); this.tilesetKeys.forEach((key: string) => {
this.Map.createStaticLayer("tiles", "tiles"); this.Terrains.push(this.Map.addTilesetImage(key, key));
});
//permit to set bound collision //permit to set bound collision
this.physics.world.setBounds(0,0, this.Map.widthInPixels, this.Map.heightInPixels); this.physics.world.setBounds(0,0, this.Map.widthInPixels, this.Map.heightInPixels);
//add layer on map //add layer on map
this.Layers = new Array<Phaser.Tilemaps.StaticTilemapLayer>(); this.Layers = new Array<Phaser.Tilemaps.StaticTilemapLayer>();
this.addLayer( this.Map.createStaticLayer("Calque 1", [this.Terrain], 0, 0).setDepth(-2) ); this.addLayer( this.Map.createStaticLayer("Calque 1", this.Terrains, 0, 0).setDepth(-2) );
this.addLayer( this.Map.createStaticLayer("Calque 2", [this.Terrain], 0, 0).setDepth(-1) ); this.addLayer( this.Map.createStaticLayer("Calque 2", this.Terrains, 0, 0).setDepth(-1) );
//add entities //add entities
this.Objects = new Array<Phaser.Physics.Arcade.Sprite>(); this.Objects = new Array<Phaser.Physics.Arcade.Sprite>();