avocado/packages/entity/src/entity-list-view.js
2021-02-12 13:32:57 -06:00

36 lines
870 B
JavaScript

import {Container} from '@avocado/graphics';
export default class EntityListView extends Container {
constructor(entityList) {
super();
this.entityList = entityList;
entityList.on('entityAdded', this.onListEntityAdded, this);
entityList.on('entityRemoved', this.onListEntityRemoved, this);
Object.values(entityList.entities).forEach((entity) => {
this.onListEntityAdded(entity);
});
}
onListEntityAdded(entity) {
if (entity.is('Rastered')) {
this.addChild(entity.container);
}
}
onListEntityRemoved(entity) {
if (entity.is('Rastered')) {
this.removeChild(entity.container);
}
}
renderTick(elapsed) {
const entities = Object.values(this.entityList.entities);
for (let i = 0; i < entities.length; i++) {
entities[i].renderTick(elapsed);
}
super.renderTick(elapsed);
}
}