remove child components of entities (if anu)
parent
01df4460a0
commit
9625c5a3b3
|
@ -61,6 +61,30 @@ GameLib.EntityManager.prototype.registerComponent = function(data) {
|
||||||
|
|
||||||
GameLib.EntityManager.prototype.removeComponent = 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) {
|
if (data.component.parentEntity instanceof GameLib.Entity) {
|
||||||
data.component.parentEntity.removeComponent(data.component);
|
data.component.parentEntity.removeComponent(data.component);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue