use of com.gemserk.commons.artemis.components.OwnerComponent in project commons-gdx by gemserk.
the class RenderableComponentComparator method compare.
@Override
public int compare(Entity o1, Entity o2) {
EntityComponents entity1Components = factory.get(o1);
EntityComponents entity2Components = factory.get(o2);
RenderableComponent c1 = entity1Components.renderableComponent;
RenderableComponent c2 = entity2Components.renderableComponent;
if (c1.renderable.getLayer() != c2.renderable.getLayer())
return c1.renderable.getLayer() - c2.renderable.getLayer();
OwnerComponent ownerComponent1 = entity1Components.ownerComponent;
OwnerComponent ownerComponent2 = entity2Components.ownerComponent;
int id1 = o1.getId();
int id2 = o2.getId();
if (ownerComponent1 != null) {
Entity owner = ownerComponent1.getOwner();
if (owner != null)
id1 = owner.getId();
}
if (ownerComponent2 != null) {
Entity owner = ownerComponent2.getOwner();
if (owner != null)
id2 = owner.getId();
}
if (id1 != id2)
return id1 - id2;
return c1.renderable.getSubLayer() - c2.renderable.getSubLayer();
}
use of com.gemserk.commons.artemis.components.OwnerComponent in project commons-gdx by gemserk.
the class RenderableSystem method enabled.
@Override
protected void enabled(Entity e) {
RenderableComponent renderableComponent = RenderableComponent.get(e);
OwnerComponent ownerComponent = OwnerComponent.get(e);
Renderable renderable = renderableComponent.renderable;
// this could be set on construction time
renderable.setEntity(e);
renderable.setId(e.getId());
// if it has owner it uses the id of the owner... that was part of the original comparator
if (ownerComponent != null && ownerComponent.getOwner() != null)
renderable.setId(ownerComponent.getOwner().getId());
// order the entity in the Layer, probably the same inside the layer
for (int i = 0; i < renderLayers.size(); i++) {
RenderLayer renderLayer = renderLayers.get(i);
if (renderLayer.belongs(renderable)) {
renderLayer.add(renderable);
return;
}
}
}
use of com.gemserk.commons.artemis.components.OwnerComponent 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.OwnerComponent 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.OwnerComponent 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());
}
Aggregations