Spaces:
Running
Running
File size: 2,995 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
import * as tile from './tiles/';
import * as CONST from '../constants';
export default class tiles {
#cell;
constructor (options) {
this.#cell = options.cell;
this.list = options.list;
this.tiles = [];
this.sprites = [];
// initialize tiles
for (let i = 0; i < this.list.length; i++) {
if (this.list[i].id == 0) continue;
if (this.list[i].type == CONST.T_SUBWAY) continue;
if (this.list[i].type == CONST.T_PIPE) continue;
if (this.list[i].type == CONST.T_UNDERGROUND) continue;
//if (this.list[i].type == CONST.T_EDGE) continue;
if (this.list[i].type == CONST.T_HEIGHTMAP) continue;
//if (this.list[i].type == CONST.T_TERRAIN) continue;
//if (this.list[i].type == CONST.T_WATER) continue;
//if (this.list[i].type == CONST.T_ROAD) continue;
//if (this.list[i].type == CONST.T_RAIL) continue;
//if (this.list[i].type == CONST.T_POWER) continue;
//if (this.list[i].type == CONST.T_HIGHWAY) continue;
//if (this.list[i].type == CONST.T_ZONE) continue;
//if (this.list[i].type == CONST.T_BUILDING) continue;
this[this.list[i].type] = null;
this.set(this.list[i].type, this.list[i].id);
}
}
getId (type) {
return this.get(type, true);
}
get (type, id = false) {
if (!this[type])
if (!id)
return;
else
return 0;
if (this[type])
if (id)
return this[type].id;
else
return this[type];
}
addSprite (sprite, type) {
this.sprites.push(sprite);
this.#cell.scene.city.map.addSprite(sprite, type);
}
topSprite () {
this.sprites.sort((a, b) => {
return a._depth - b._depth;
});
return this.sprites[this.sprites.length - 1];
}
addTile (tile) {
this.tiles.push(tile);
}
get top () {
return this.topTile();
}
topTile () {
this.tiles.sort((a, b) => {
if (a.sprite && !a.sprite.visible) return -1;
if (b.sprite && !b.sprite.visible) return 1;
return a.depth - b.depth;
});
return this.tiles[this.tiles.length - 1];
}
hide () {
for (let i = 0; i < this.list.length; i++)
if (this[this.list[i].type])
this[this.list[i].type].hide();
}
show () {
for (let i = 0; i < this.list.length; i++)
if (this[this.list[i].type])
this[this.list[i].type].show();
}
has (type) {
if (this[type] && this[type].props.draw) return true;
return false;
}
set (type, id) {
if (id == 0) return;
if (this?.[type]?.sprite) this[type].sprite.destroy();
for (let i = 0; i < this.list.length; i++)
if (this.list[i].type == type)
this.list[i].id = id;
this[type] = new tile[type]({ cell: this.#cell, id: id });
}
create () {
for (let i = 0; i < this.list.length; i++)
if (this[this.list[i].type])
this[this.list[i].type].create();
}
} |