Search in sources :

Example 1 with Group

use of ilargia.entitas.group.Group in project Entitas-Java by Rubentxu.

the class Collector method activate.

@Override
public void activate() {
    for (int i = 0; i < _groups.length; i++) {
        Group group = (Group) _groups[i];
        GroupEvent groupEvent = _groupEvents[i];
        switch(groupEvent) {
            case Added:
                group.OnEntityAdded(_addEntityCache);
                break;
            case Removed:
                group.OnEntityRemoved(_addEntityCache);
                break;
            case AddedOrRemoved:
                group.OnEntityAdded(_addEntityCache);
                group.OnEntityRemoved(_addEntityCache);
                break;
        }
    }
}
Also used : IGroup(ilargia.entitas.api.IGroup) Group(ilargia.entitas.group.Group) GroupEvent(ilargia.entitas.group.GroupEvent)

Example 2 with Group

use of ilargia.entitas.group.Group in project Entitas-Java by Rubentxu.

the class Collector method deactivate.

@Override
public void deactivate() {
    for (int i = 0; i < _groups.length; i++) {
        Group group = (Group) _groups[i];
        group.OnEntityAdded.remove(_addEntityCache);
        group.OnEntityRemoved.remove(_addEntityCache);
    }
    clearCollectedEntities();
}
Also used : IGroup(ilargia.entitas.api.IGroup) Group(ilargia.entitas.group.Group)

Example 3 with Group

use of ilargia.entitas.group.Group in project Entitas-Java by Rubentxu.

the class ContextTest method entityIndexTest.

@Test
public void entityIndexTest() {
    entity.addComponent(TestComponentIds.Position, new Position());
    Group group = context.getGroup(TestMatcher.Position());
    PrimaryEntityIndex<Entity, String> index = new PrimaryEntityIndex("", (e, c) -> "positionEntities", group);
    context.addEntityIndex("positions", index);
    index = (PrimaryEntityIndex<Entity, String>) context.getEntityIndex("positions");
    assertNotNull(index);
    assertNotNull(index.getEntity("positionEntities"));
}
Also used : IGroup(ilargia.entitas.api.IGroup) Group(ilargia.entitas.group.Group) IEntity(ilargia.entitas.api.entitas.IEntity) TestEntity(ilargia.entitas.utils.TestEntity) Position(ilargia.entitas.components.Position) PrimaryEntityIndex(ilargia.entitas.index.PrimaryEntityIndex) Test(org.junit.Test)

Example 4 with Group

use of ilargia.entitas.group.Group in project Entitas-Java by Rubentxu.

the class ContextTest method getGroupEntitiesTest.

@Test
public void getGroupEntitiesTest() {
    entity.addComponent(TestComponentIds.Position, new Position());
    Group group = context.getGroup(TestMatcher.Position());
    assertEquals(1, group.getEntities().length);
}
Also used : IGroup(ilargia.entitas.api.IGroup) Group(ilargia.entitas.group.Group) Position(ilargia.entitas.components.Position) Test(org.junit.Test)

Example 5 with Group

use of ilargia.entitas.group.Group in project Entitas-Java by Rubentxu.

the class ContextTest method duplicateEntityIndexTest.

@Test(expected = ContextEntityIndexDoesAlreadyExistException.class)
public void duplicateEntityIndexTest() {
    entity.addComponent(TestComponentIds.Position, new Position());
    Group group = context.getGroup(TestMatcher.Position());
    PrimaryEntityIndex<Entity, String> index = new PrimaryEntityIndex("", group, (e, c) -> new String[] { "positionEntities" });
    context.addEntityIndex("duplicate", index);
    context.addEntityIndex("duplicate", index);
}
Also used : IGroup(ilargia.entitas.api.IGroup) Group(ilargia.entitas.group.Group) IEntity(ilargia.entitas.api.entitas.IEntity) TestEntity(ilargia.entitas.utils.TestEntity) Position(ilargia.entitas.components.Position) PrimaryEntityIndex(ilargia.entitas.index.PrimaryEntityIndex) Test(org.junit.Test)

Aggregations

Group (ilargia.entitas.group.Group)7 IGroup (ilargia.entitas.api.IGroup)6 Position (ilargia.entitas.components.Position)5 Test (org.junit.Test)4 TestEntity (ilargia.entitas.utils.TestEntity)3 IEntity (ilargia.entitas.api.entitas.IEntity)2 PrimaryEntityIndex (ilargia.entitas.index.PrimaryEntityIndex)2 ContextInfo (ilargia.entitas.api.ContextInfo)1 View (ilargia.entitas.components.View)1 GroupEvent (ilargia.entitas.group.GroupEvent)1 Before (org.junit.Before)1