Spaces:
Running
Running
File size: 1,227 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 |
import * as CONST from '../../constants';
export default class layer {
constructor (options) {
this.scene = options.scene;
this.type = options.type;
this.map = options.scene.city.map;
this.events = options.scene.events;
this.visible = options.visible || true;
this.list = [];
this.map.list.forEach((cell) => {
if (!cell || !cell.tiles)
return;
if (cell.tiles[this.type])
this.list.push(cell.tiles[this.type]);
});
this.events.on(CONST.E_MAP_LAYER_HIDE, this.onHide, this);
this.events.on(CONST.E_MAP_LAYER_SHOW, this.onShow, this);
}
toggle () {
if (this.visible)
this.hide();
else
this.show();
}
hide (emitEvents = true) {
this.visible = false;
this.list.forEach((tile) => {
tile.hide();
});
if (emitEvents) this.events.emit(CONST.E_MAP_LAYER_HIDE, this.type);
}
show (emitEvents = true) {
this.visible = true;
this.list.forEach((tile) => {
tile.show();
});
if (emitEvents) this.events.emit(CONST.E_MAP_LAYER_SHOW, this.type);
}
refresh () {
this.hide();
this.show();
}
onHide (type) {
return;
}
onShow (type) {
return;
}
} |