Search in sources :

Example 1 with World

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

the class ArtemisOutOfBoundsTest method shouldNotFailWhenAskingForComponentOutsideBounds.

@Test
public void shouldNotFailWhenAskingForComponentOutsideBounds() {
    World world = new World();
    Entity e = world.createEntity();
    e.addComponent(new Component1());
    e.addComponent(new Component2());
    e.addComponent(new Component3());
    e.addComponent(new Component4());
    e.addComponent(new Component5());
    e.addComponent(new Component6());
    // e.addComponent(new Component7());
    e.addComponent(new Component8());
    e.addComponent(new Component9());
    e.addComponent(new Component10());
    e.addComponent(new Component11());
    e.addComponent(new Component12());
    e.addComponent(new Component13());
    e.addComponent(new Component14());
    e.addComponent(new Component15());
    e.addComponent(new Component16());
    e.addComponent(new ComponentOutOfBounds());
    e.refresh();
    e.getComponent(Component1.class);
    e.getComponent(Component2.class);
    e.getComponent(Component3.class);
    e.getComponent(Component4.class);
    e.getComponent(Component5.class);
    e.getComponent(Component6.class);
    e.getComponent(Component7.class);
    e.getComponent(Component8.class);
    e.getComponent(Component9.class);
    e.getComponent(Component10.class);
    e.getComponent(Component11.class);
    e.getComponent(Component12.class);
    e.getComponent(Component13.class);
    e.getComponent(Component14.class);
    e.getComponent(Component15.class);
    e.getComponent(Component16.class);
    // e.getComponent(ComponentOutOfBounds.class);
    ComponentOutOfBounds component = e.getComponent(ComponentOutOfBounds.class);
    assertThat(component, IsNull.notNullValue());
    Component7 component7 = e.getComponent(Component7.class);
    assertThat(component7, IsNull.nullValue());
}
Also used : Entity(com.artemis.Entity) World(com.artemis.World) Test(org.junit.Test)

Example 2 with World

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

the class ArtemisOutOfBoundsTest method shouldGetComponent.

@Test
public void shouldGetComponent() {
    World world = new World();
    Entity e = world.createEntity();
    e.addComponent(new Component1());
    e.refresh();
    Component1 component = e.getComponent(Component1.class);
    assertThat(component, IsNull.notNullValue());
}
Also used : Entity(com.artemis.Entity) World(com.artemis.World) Test(org.junit.Test)

Example 3 with World

use of com.artemis.World 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 4 with World

use of com.artemis.World 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)

Example 5 with World

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

the class EntityTemplateTest method weaponInstantiateBullet.

@Deprecated
public void weaponInstantiateBullet() {
    EntityTemplate bulletTemplate = new BulletEntityTemplate();
    // modifies the template forever, if we are using the same template in different weapons or something similar, then they will be modified as well.
    // bulletTemplate.getDefaultParameters().put("damage", new Float(200f));
    EntityFactory entityFactory = new EntityFactoryImpl(new World());
    Entity bullet = entityFactory.instantiate(bulletTemplate);
    DamageComponent damageComponent = bullet.getComponent(DamageComponent.class);
    assertThat(damageComponent.getDamage(), IsEqual.equalTo(200f));
}
Also used : Entity(com.artemis.Entity) EntityFactoryImpl(com.gemserk.commons.artemis.templates.EntityFactoryImpl) EntityTemplate(com.gemserk.commons.artemis.templates.EntityTemplate) World(com.artemis.World) EntityFactory(com.gemserk.commons.artemis.templates.EntityFactory)

Aggregations

World (com.artemis.World)39 Entity (com.artemis.Entity)38 Test (org.junit.Test)31 RenderableComponent (com.gemserk.commons.artemis.components.RenderableComponent)15 OwnerComponent (com.gemserk.commons.artemis.components.OwnerComponent)14 WorldWrapper (com.gemserk.commons.artemis.WorldWrapper)8 EntityFactory (com.gemserk.commons.artemis.templates.EntityFactory)6 EntityFactoryImpl (com.gemserk.commons.artemis.templates.EntityFactoryImpl)6 EntityTemplate (com.gemserk.commons.artemis.templates.EntityTemplate)6 ContainerComponent (com.gemserk.commons.artemis.components.ContainerComponent)3 SpatialComponent (com.gemserk.commons.artemis.components.SpatialComponent)3 ParametersWrapper (com.gemserk.componentsengine.utils.ParametersWrapper)3 ComponentType (com.artemis.ComponentType)2 Spatial (com.gemserk.commons.gdx.games.Spatial)2 Container (com.gemserk.componentsengine.utils.Container)2 ComponentMapper (com.artemis.ComponentMapper)1 EntityProcessingSystem (com.artemis.EntityProcessingSystem)1 WorldConfigurationBuilder (com.artemis.WorldConfigurationBuilder)1 ScriptComponent (com.gemserk.commons.artemis.components.ScriptComponent)1 StoreComponent (com.gemserk.commons.artemis.components.StoreComponent)1