feat: HMR!

This commit is contained in:
cha0s 2021-03-25 02:44:21 -05:00
parent 05a8c3a338
commit 64fb70d02a

View File

@ -4,6 +4,8 @@ import {Vector} from '@avocado/math';
import TilesRenderer from './tiles-renderer';
const views = new Set();
export default class LayerView extends Container {
constructor(layer, renderer) {
@ -12,20 +14,23 @@ export default class LayerView extends Container {
this.layer = layer;
this.layerContainer = new Container();
this.renderer = renderer;
this.tileGeometryContainer = new Container();
this.tileGeometryViews = [];
// Handle entity add/remove.
layer.on('tile-data-changed', this.onLayerTileDataChanged, this);
this.onLayerTileDataChanged();
layer.on('tilesetChanged', this.onLayerTilesetChanged, this);
this.onLayerTilesetChanged(layer.tileset, undefined);
this.addChild(this.layerContainer);
this.addChild(this.tileGeometryContainer);
this.addChild(this.entityListView);
if (module.hot) {
views.add(this);
}
}
destroy() {
super.destroy();
if (module.hot) {
views.delete(this);
}
this.layer.off('tile-data-changed', this.onLayerTileDataChanged);
this.layer.off('tilesetChanged', this.onLayerTilesetChanged);
}
@ -67,3 +72,13 @@ export default class LayerView extends Container {
}
}
if (module.hot) {
module.hot.accept('./tiles-renderer', () => {
const it = views.values();
for (let value = it.next(); value.done !== true; value = it.next()) {
const {value: view} = value;
view.render();
}
});
}