use of com.gemserk.commons.artemis.components.ContainerComponent in project commons-gdx by gemserk.
the class ContainerSystem method disabled.
@Override
protected void disabled(Entity e) {
ContainerComponent containerComponent = ContainerComponent.get(e);
for (int i = 0; i < containerComponent.getChildren().size(); i++) {
Entity child = containerComponent.getChildren().get(i);
// what about the stores?
StoreComponent storeComponent = StoreComponent.get(child);
if (storeComponent != null)
storeComponent.store.free(child);
else
child.delete();
}
}
use of com.gemserk.commons.artemis.components.ContainerComponent in project commons-gdx by gemserk.
the class OwnerSystem method disabled.
@Override
protected void disabled(Entity e) {
OwnerComponent ownerComponent = OwnerComponent.get(e);
if (ownerComponent.getOwner() == null)
return;
ContainerComponent containerComponent = ContainerComponent.get(ownerComponent.getOwner());
if (containerComponent == null)
return;
containerComponent.getChildren().remove(e);
}
use of com.gemserk.commons.artemis.components.ContainerComponent in project commons-gdx by gemserk.
the class OwnerSystem method enabled.
@Override
protected void enabled(Entity e) {
OwnerComponent ownerComponent = OwnerComponent.get(e);
if (ownerComponent.getOwner() == null)
return;
ContainerComponent containerComponent = ContainerComponent.get(ownerComponent.getOwner());
if (containerComponent == null)
return;
containerComponent.getChildren().add(e);
}
use of com.gemserk.commons.artemis.components.ContainerComponent in project commons-gdx by gemserk.
the class ContainerSystemTest method shouldRemoveChildrenIfParentRemoved.
@Test
public void shouldRemoveChildrenIfParentRemoved() {
World world = new World();
WorldWrapper worldWrapper = new WorldWrapper(world);
worldWrapper.addUpdateSystem(new ContainerSystem());
worldWrapper.addUpdateSystem(new OwnerSystem());
worldWrapper.init();
Entity e1 = world.createEntity();
e1.addComponent(new ContainerComponent());
e1.refresh();
Entity e2 = world.createEntity();
e2.addComponent(new OwnerComponent(e1));
e2.refresh();
worldWrapper.update(10);
world.deleteEntity(e1);
worldWrapper.update(1);
worldWrapper.update(1);
Entity e3 = world.getEntity(e2.getId());
assertThat(e3, IsNull.nullValue());
}
use of com.gemserk.commons.artemis.components.ContainerComponent in project commons-gdx by gemserk.
the class ContainerSystemTest method shouldBeAddedToParentContainer.
@Test
public void shouldBeAddedToParentContainer() {
World world = new World();
WorldWrapper worldWrapper = new WorldWrapper(world);
worldWrapper.addUpdateSystem(new ContainerSystem());
worldWrapper.addUpdateSystem(new OwnerSystem());
worldWrapper.init();
Entity e1 = world.createEntity();
e1.addComponent(new ContainerComponent());
e1.refresh();
Entity e2 = world.createEntity();
e2.addComponent(new OwnerComponent(e1));
e2.refresh();
worldWrapper.update(10);
ContainerComponent containerComponent = e1.getComponent(ContainerComponent.class);
assertThat(containerComponent.getChildren().contains(e2), IsEqual.equalTo(true));
}
Aggregations