Search in sources :

Example 1 with StoreComponent

use of com.gemserk.commons.artemis.components.StoreComponent in project commons-gdx by gemserk.

the class AliveSystem method processEntities.

@Override
protected void processEntities() {
    RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = factory.entityComponents;
    int entitiesSize = allTheEntityComponents.size();
    for (int entityIndex = 0; entityIndex < entitiesSize; entityIndex++) {
        EntityComponents entityComponents = allTheEntityComponents.get(entityIndex);
        AliveComponent aliveComponent = entityComponents.aliveComponent;
        float aliveTime = aliveComponent.getTime() - GlobalTime.getDelta();
        aliveComponent.setTime(aliveTime);
        if (aliveTime <= 0) {
            Entity e = allTheEntityComponents.getKey(entityIndex);
            StoreComponent storeComponent = StoreComponent.get(e);
            if (storeComponent != null)
                storeComponent.store.free(e);
            else
                e.delete();
        }
    }
}
Also used : Entity(com.artemis.Entity) AliveComponent(com.gemserk.commons.artemis.components.AliveComponent) StoreComponent(com.gemserk.commons.artemis.components.StoreComponent)

Example 2 with StoreComponent

use of com.gemserk.commons.artemis.components.StoreComponent 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 3 with StoreComponent

use of com.gemserk.commons.artemis.components.StoreComponent in project commons-gdx by gemserk.

the class TemplateStoreFactory method createObject.

@Override
public Entity createObject() {
    if (entityStore == null)
        throw new RuntimeException("Can't set null EntityStore to the created entity");
    Entity entity = null;
    if (entityTemplate != null)
        entity = entityFactory.instantiate(entityTemplate);
    else
        entity = entityFactory.instantiate(injector.getInstance(entityTemplateClass));
    StoreComponent storeComponent = StoreComponent.get(entity);
    if (storeComponent == null)
        storeComponent = new StoreComponent(null);
    storeComponent.store = entityStore;
    entity.addComponent(storeComponent);
    return entity;
}
Also used : Entity(com.artemis.Entity) StoreComponent(com.gemserk.commons.artemis.components.StoreComponent)

Example 4 with StoreComponent

use of com.gemserk.commons.artemis.components.StoreComponent in project commons-gdx by gemserk.

the class ContainerSystemTest method shouldNotProcessDisabledChildrenEntity.

@SuppressWarnings("unchecked")
@Test
public void shouldNotProcessDisabledChildrenEntity() {
    World world = new World();
    WorldWrapper worldWrapper = new WorldWrapper(world);
    worldWrapper.addUpdateSystem(new ContainerSystem());
    worldWrapper.addUpdateSystem(new OwnerSystem());
    shouldBeDisabled = false;
    worldWrapper.addUpdateSystem(new EntityProcessingSystem(StoreComponent.class) {

        @Override
        protected void process(Entity e) {
            if (shouldBeDisabled)
                fail("should not process children");
            System.out.println("processing children");
            shouldBeDisabled = true;
        }
    });
    worldWrapper.init();
    Entity e1 = world.createEntity();
    e1.addComponent(new ContainerComponent());
    Entity e2 = world.createEntity();
    e2.addComponent(new OwnerComponent(e1));
    e2.addComponent(new StoreComponent(new EntityStore(null) {
    }));
    worldWrapper.update(1);
    assertTrue(e1.isEnabled());
    assertTrue(e2.isEnabled());
    e1.delete();
    worldWrapper.update(1);
    assertFalse(e1.isEnabled());
    assertFalse(e2.isEnabled());
    worldWrapper.update(1);
}
Also used : Entity(com.artemis.Entity) WorldWrapper(com.gemserk.commons.artemis.WorldWrapper) EntityProcessingSystem(com.artemis.EntityProcessingSystem) OwnerComponent(com.gemserk.commons.artemis.components.OwnerComponent) ContainerComponent(com.gemserk.commons.artemis.components.ContainerComponent) EntityStore(com.gemserk.commons.artemis.utils.EntityStore) World(com.artemis.World) StoreComponent(com.gemserk.commons.artemis.components.StoreComponent) Test(org.junit.Test)

Aggregations

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