Spaces:
Running
Running
File size: 2,207 Bytes
4ee4376 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
export default class related {
#cell;
#map;
#tile;
#key = false;
#related = [];
constructor (options) {
this.#cell = options.cell;
this.#map = options.cell.scene.city.map;
this.#tile = options.cell.tiles?.top?.tile;
this.#key = options.cell.position.corners.key;
this.update();
return this.#related;
}
update () {
this.#related = [];
if (!this.#key) return;
let x = this.#cell.x;
let y = this.#cell.y;
// create a reference to self
this.#related.push(this.#cell);
if (this.#tile?.size == 2) {
this.#related.push(this.#map.cells[x][y-1]);
this.#related.push(this.#map.cells[x-1][y]);
this.#related.push(this.#map.cells[x-1][y-1]);
}
if (this.#tile?.size == 3){
this.#related.push(this.#map.cells[x][y-1]);
this.#related.push(this.#map.cells[x-1][y]);
this.#related.push(this.#map.cells[x-1][y-1]);
this.#related.push(this.#map.cells[x][y-2]);
this.#related.push(this.#map.cells[x-2][y]);
this.#related.push(this.#map.cells[x-2][y-1]);
this.#related.push(this.#map.cells[x-1][y-2]);
this.#related.push(this.#map.cells[x-2][y-2]);
}
if (this.#tile?.size == 4){
this.#related.push(this.#map.cells[x][y-1]);
this.#related.push(this.#map.cells[x-1][y]);
this.#related.push(this.#map.cells[x-1][y-1]);
this.#related.push(this.#map.cells[x][y-2]);
this.#related.push(this.#map.cells[x-2][y]);
this.#related.push(this.#map.cells[x-2][y-1]);
this.#related.push(this.#map.cells[x-1][y-2]);
this.#related.push(this.#map.cells[x-2][y-2]);
this.#related.push(this.#map.cells[x][y-3]);
this.#related.push(this.#map.cells[x-3][y]);
this.#related.push(this.#map.cells[x-3][y-1]);
this.#related.push(this.#map.cells[x-3][y-2]);
this.#related.push(this.#map.cells[x-1][y-3]);
this.#related.push(this.#map.cells[x-2][y-3]);
this.#related.push(this.#map.cells[x-3][y-3]);
}
this.#related.forEach((cell) => {
cell.related = this.#related;
cell.parent = this.#cell;
});
this.#cell.parent = null;
this.#cell.related = this.#related;
}
} |