remove child components of entities (if anu)

beta.r3js.org
-=yb4f310 2017-09-08 11:42:11 +02:00
parent 01df4460a0
commit 9625c5a3b3
1 changed files with 24 additions and 0 deletions

View File

@ -61,6 +61,30 @@ GameLib.EntityManager.prototype.registerComponent = function(data) {
GameLib.EntityManager.prototype.removeComponent = function(data) {
if (data.component instanceof GameLib.Entity) {
/**
* if this is an entity - remove all its children components first
*/
data.component.components.map(
function(component) {
var index = this.register.indexOf(component);
if (index !== -1) {
this.register.splice(index, 1);
GameLib.Event.Emit(
GameLib.Event.REGISTER_UPDATE,
{
register : this.register
}
);
}
}.bind(this)
)
}
if (data.component.parentEntity instanceof GameLib.Entity) {
data.component.parentEntity.removeComponent(data.component);
}