refactor: renderable

This commit is contained in:
cha0s 2021-05-09 23:48:17 -05:00
parent 4489d96d0a
commit 0f128bcc3a
4 changed files with 14 additions and 11 deletions

View File

@ -3,7 +3,6 @@ import {gatherWithLatus} from '@latus/core';
export {default as Room} from './components/room';
export {default as Camera} from './camera';
export {default as RoomView} from './room-view';
export default {
hooks: {

View File

@ -1,11 +1,11 @@
import {EntityListView} from '@avocado/entity';
import {Container} from '@avocado/graphics';
import TilesView from './tiles-view';
import TilesRenderable from './tiles';
const views = new Set();
export default class RoomView extends Container {
export default class RoomRenderable extends Container {
layers = [];
@ -14,8 +14,8 @@ export default class RoomView extends Container {
this.lastExtent = [0, 0, 0, 0];
this.renderer = renderer;
this.entityListView = new EntityListView(room.entityList);
this.tilesViews = room.tiles.map((tiles) => new TilesView(tiles, renderer));
this.addChildren(this.tilesViews);
this.tilesRenderables = room.tiles.map((tiles) => new TilesRenderable(tiles, renderer));
this.addChildren(this.tilesRenderables);
this.addChild(this.entityListView);
this.sort();
if (module.hot) {
@ -31,24 +31,24 @@ export default class RoomView extends Container {
}
renderChunksForExtent(extent) {
this.tilesViews.forEach((tilesView) => {
tilesView.renderChunksForExtent(extent);
this.tilesRenderables.forEach((tilesRenderable) => {
tilesRenderable.renderChunksForExtent(extent);
});
}
}
if (module.hot) {
module.hot.accept('./tiles-view', () => {
module.hot.accept('./tiles', () => {
const it = views.values();
for (let value = it.next(); value.done !== true; value = it.next()) {
const {value: view} = value;
const {lastExtent} = view;
view.removeChild(view.entityListView);
view.removeChild(view.tilesView);
view.tilesView = new TilesView(view.room.tiles, view.renderer);
view.removeChild(view.tilesRenderable);
view.tilesRenderable = new TilesRenderable(view.room.tiles, view.renderer);
view.renderChunksForExtent(lastExtent);
view.addChild(view.tilesView);
view.addChild(view.tilesRenderable);
view.addChild(view.entityListView);
}
});

View File

@ -3,6 +3,8 @@ import {JsonResource} from '@avocado/resource';
import {Synchronized} from '@avocado/s13n';
import {compose, EventEmitter} from '@latus/core';
import RoomRenderable from '../renderable/room';
let s13nId = 1;
export default (latus) => {
@ -17,6 +19,8 @@ export default (latus) => {
entityList;
static Renderable = RoomRenderable;
tiles = [];
constructor() {