Search in sources :

Example 1 with ContainerComponent

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();
    }
}
Also used : Entity(com.artemis.Entity) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent) StoreComponent(com.gemserk.commons.artemis.components.StoreComponent)

Example 2 with ContainerComponent

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);
}
Also used : OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent)

Example 3 with ContainerComponent

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);
}
Also used : OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent)

Example 4 with ContainerComponent

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());
}
Also used : Entity(com.artemis.Entity) WorldWrapper(com.gemserk.commons.artemis.WorldWrapper) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent) World(com.artemis.World) Test(org.junit.Test)

Example 5 with ContainerComponent

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));
}
Also used : Entity(com.artemis.Entity) WorldWrapper(com.gemserk.commons.artemis.WorldWrapper) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent) World(com.artemis.World) Test(org.junit.Test)

Aggregations

ContainerComponent (com.gemserk.commons.artemis.components.ContainerComponent)6 OwnerComponent (com.gemserk.commons.artemis.components.OwnerComponent)5 Entity (com.artemis.Entity)4 World (com.artemis.World)3 WorldWrapper (com.gemserk.commons.artemis.WorldWrapper)3 Test (org.junit.Test)3 StoreComponent (com.gemserk.commons.artemis.components.StoreComponent)2 EntityProcessingSystem (com.artemis.EntityProcessingSystem)1 EntityStore (com.gemserk.commons.artemis.utils.EntityStore)1