2019-08-20 17:59:26 +02:00
|
|
|
class Container {
|
2020-03-21 17:22:28 +01:00
|
|
|
constructor() {
|
|
|
|
this.pos = { x: 0, y: 0 };
|
|
|
|
this.children = [];
|
|
|
|
}
|
2019-08-20 17:59:26 +02:00
|
|
|
|
2020-03-21 17:22:28 +01:00
|
|
|
add(child) {
|
|
|
|
this.children.push(child);
|
|
|
|
return child;
|
|
|
|
}
|
2019-08-20 17:59:26 +02:00
|
|
|
|
2020-03-21 17:22:28 +01:00
|
|
|
remove(child) {
|
|
|
|
this.children = this.children.filter(c => c !== child);
|
|
|
|
return child;
|
|
|
|
}
|
2019-08-20 17:59:26 +02:00
|
|
|
|
2020-03-21 17:22:28 +01:00
|
|
|
map(f) {
|
|
|
|
return this.children.map(f);
|
|
|
|
}
|
2019-08-20 17:59:26 +02:00
|
|
|
|
2020-03-21 17:22:28 +01:00
|
|
|
update(dt, t) {
|
|
|
|
this.children = this.children.filter(child => {
|
|
|
|
if (child.update) {
|
|
|
|
child.update(dt, t, this);
|
|
|
|
}
|
|
|
|
return child.dead ? false : true;
|
|
|
|
});
|
|
|
|
}
|
2019-08-20 17:59:26 +02:00
|
|
|
}
|
2020-02-29 13:45:56 +01:00
|
|
|
module.exports = Container;
|