Startpoint widget implemented

This commit is contained in:
Mal
2020-02-04 23:03:33 +01:00
parent d46b195269
commit fa648ae730
12 changed files with 231 additions and 12 deletions

View File

@@ -10,6 +10,8 @@ export default class Terrain
this.fields = [];
this.tilesX = tilesX;
this.tilesY = tilesY;
this.entranceTileX = undefined;
this.entranceTileY = undefined;
this.backgroundColor = backgroundColor;
this.htmlElement = document.createElement('table');
this.brushTileIndex = 0;
@@ -62,6 +64,38 @@ export default class Terrain
this.fields[y][x].setIndex(index);
}
setEntrancePoint(tileX, tileY)
{
if (this.fields[tileY][tileX].index === -1) {
if (this.entranceTileX !== undefined && this.entranceTileY !== undefined) {
this.fields[this.entranceTileY][this.entranceTileX].setEntrancePoint(false);
}
this.entranceTileX = tileX;
this.entranceTileY = tileY;
this.fields[tileY][tileX].setEntrancePoint(true);
}
}
getFieldCoordinates(field)
{
for (let y = 0; y < this.fields.length; y++) {
for (let x = 0; x < this.fields[y].length; x++) {
if (this.fields[y][x] === field) {
return {x: x, y: y};
}
}
}
return undefined;
}
hasEntrancePoint()
{
return this.entranceTileX !== undefined && this.entranceTileY !== undefined;
}
static createFromJson(json)
{
let terrainData = JSON.parse(json);