avocado-old/packages/entity/list/view.js

28 lines
633 B
JavaScript
Raw Normal View History

2019-04-13 20:48:52 -05:00
import {Container, Sprite} from '@avocado/graphics';
export class EntityListView extends Container {
constructor(entityList) {
super();
this.entityList = entityList;
entityList.on('entityAdded', this.onListEntityAdded, this);
entityList.on('entityRemoved', this.onListEntityRemoved, this);
for (const entity of entityList) {
this.onListEntityAdded(entity);
}
}
onListEntityAdded(entity) {
if (entity.is('graphical')) {
this.addChild(entity.container);
}
}
onListEntityRemoved(entity) {
if (entity.is('graphical')) {
this.removeChild(entity.container);
}
}
}