Apply suggestions from code review

Co-authored-by: David Négrier <d.negrier@thecodingmachine.com>
This commit is contained in:
GRL78 2021-05-25 11:02:25 +02:00 committed by GitHub
parent d4bc999c54
commit 7c44d747de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 45 deletions

View file

@ -117,41 +117,14 @@ export class GameMap {
}
public findLayer(layerName: string): ITiledMapLayer | undefined {
let i = 0;
let found = false;
while (!found && i<this.flatLayers.length) {
if (this.flatLayers[i].name === layerName) {
found = true;
}
else {
i++;
}
}
if (found) {
return this.flatLayers[i];
}
return undefined;
return this.flatLayers.find((layer) => layer.name = layerName);
}
public findPhaserLayer(layerName: string): TilemapLayer | undefined {
let i = 0;
let found = false;
while (!found && i<this.phaserLayers.length) {
if (this.phaserLayers[i].layer.name === layerName) {
found = true;
}
else {
i++;
}
}
if (found) {
return this.phaserLayers[i];
}
return undefined;
return this.phaserLayers.find((layer) => layer.layer.name = layerName);
}
public addTerrain(terrain : Phaser.Tilemaps.Tileset): void {
console.log('Add');
for (const phaserLayer of this.phaserLayers) {
phaserLayer.tileset.push(terrain);
}