Intelligent graphics sets support removal of fields too

This commit is contained in:
Mal 2023-09-24 01:57:26 +02:00
parent e6c247c655
commit c5eef3c657
1 changed files with 29 additions and 13 deletions

View File

@ -199,24 +199,40 @@ export default class Tilorswift
this.level.terrain.getFieldNeighbourCode(field) this.level.terrain.getFieldNeighbourCode(field)
); );
field.setIndex(index % this.tileset.tiles); field.setIndex(index);
for (const neighbour of this.level.terrain.getFieldNeighbours(field)) { this.updateNeighbours(field);
if (neighbour.index === -1) {
continue;
}
const neighbourIndex = (neighbour.index % this.tileset.primaryTiles) + this.tileset.primaryTiles * this.tileset.getTileIndexFactor(
this.level.terrain.getFieldNeighbourCode(neighbour)
);
neighbour.setIndex(neighbourIndex);
}
} else { } else {
field.setIndex(this.level.terrain.brushTileIndex); field.setIndex(this.level.terrain.brushTileIndex);
} }
} }
updateNeighbours(field)
{
for (const neighbour of this.level.terrain.getFieldNeighbours(field)) {
if (neighbour.index === -1) {
continue;
}
const neighbourIndex = (neighbour.index % this.tileset.primaryTiles) + this.tileset.primaryTiles * this.tileset.getTileIndexFactor(
this.level.terrain.getFieldNeighbourCode(neighbour)
);
neighbour.setIndex(neighbourIndex);
}
}
removeTerrain(field)
{
field.setIndex(-1);
if (this.brush.isIntelligent) {
for (const neighbour of this.level.terrain.getFieldNeighbours(field)) {
this.updateNeighbours(field);
}
}
}
addEventListeners() addEventListeners()
{ {
window.addEventListener( window.addEventListener(
@ -228,7 +244,7 @@ export default class Tilorswift
this.addTerrain(event.getField()); this.addTerrain(event.getField());
break; break;
case 2: case 2:
event.getField().setIndex(-1); this.removeTerrain(event.getField());
break; break;
} }
} else if (this.brush.mode === BrushMode.ENTRANCE) { } else if (this.brush.mode === BrushMode.ENTRANCE) {