use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class EnvironmentEventTests method testOnRemoved.
@Test
public void testOnRemoved() {
ICombatEntity combatEntity = mock(ICombatEntity.class);
when(combatEntity.getMapId()).thenReturn(123);
when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
Consumer<IEntity> removedConsumer = (Consumer<IEntity>) mock(Consumer.class);
this.testEnvironment.onEntityRemoved(removedConsumer);
this.testEnvironment.add(combatEntity);
this.testEnvironment.remove(combatEntity);
verify(removedConsumer, times(1)).accept(combatEntity);
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class EnvironmentTests method testFindEntitiesInShape.
@Test
public void testFindEntitiesInShape() {
MapArea entity = new MapArea(0, 0, 10, 10);
MapArea entity2 = new MapArea(10, 10, 10, 10);
this.testEnvironment.add(entity);
this.testEnvironment.add(entity2);
List<IEntity> found = this.testEnvironment.findEntities(new Rectangle2D.Double(0, 0, 10, 10));
List<IEntity> found2 = this.testEnvironment.findEntities(new Ellipse2D.Double(0, 0, 10, 10));
assertTrue(found.contains(entity));
assertFalse(found.contains(entity2));
assertTrue(found2.contains(entity));
assertFalse(found2.contains(entity2));
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class MapObjectLoaderTests method testEmitterMapObjectLoader.
@Test
public void testEmitterMapObjectLoader() {
EmitterMapObjectLoader loader = new EmitterMapObjectLoader();
IEnvironment environment = mock(IEnvironment.class);
IMapObject mapObject = mock(IMapObject.class);
when(mapObject.getType()).thenReturn(MapObjectType.EMITTER.name());
when(mapObject.getId()).thenReturn(111);
when(mapObject.getName()).thenReturn("testEmitter");
when(mapObject.getLocation()).thenReturn(new Point(100, 100));
when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
Collection<IEntity> entities = loader.load(environment, mapObject);
Optional<IEntity> opt = entities.stream().findFirst();
assertTrue(opt.isPresent());
IEntity entity = entities.stream().findFirst().get();
assertNotNull(entity);
assertEquals(entity.getMapId(), 111);
assertEquals(entity.getName(), "testEmitter");
assertEquals(entity.getLocation().getX(), 100, 0.0001);
assertEquals(entity.getLocation().getY(), 100, 0.0001);
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class MapObjectLoaderTests method testTriggerMapObjectLoader.
@Test
public void testTriggerMapObjectLoader() {
TriggerMapObjectLoader loader = new TriggerMapObjectLoader();
IEnvironment environment = mock(IEnvironment.class);
IMapObject mapObject = mock(IMapObject.class);
when(mapObject.getType()).thenReturn(MapObjectType.TRIGGER.name());
when(mapObject.getId()).thenReturn(111);
when(mapObject.getName()).thenReturn("testTrigger");
when(mapObject.getLocation()).thenReturn(new Point(100, 100));
when(mapObject.getWidth()).thenReturn(200);
when(mapObject.getHeight()).thenReturn(200);
when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_MESSAGE)).thenReturn("message");
when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION)).thenReturn(TriggerActivation.INTERACT.name());
when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_TARGETS)).thenReturn("1,2,3");
when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATORS)).thenReturn("4,5,6");
when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ONETIME)).thenReturn("false");
Collection<IEntity> entities = loader.load(environment, mapObject);
Optional<IEntity> opt = entities.stream().findFirst();
assertTrue(opt.isPresent());
IEntity entity = entities.stream().findFirst().get();
assertNotNull(entity);
assertEquals(entity.getMapId(), 111);
assertEquals(entity.getName(), "testTrigger");
assertEquals(entity.getLocation().getX(), 100, 0.0001);
assertEquals(entity.getLocation().getY(), 100, 0.0001);
Trigger trigger = (Trigger) entity;
assertFalse(trigger.isOneTimeTrigger());
assertEquals(TriggerActivation.INTERACT, trigger.getActivationType());
assertArrayEquals(new Integer[] { 1, 2, 3 }, trigger.getTargets().toArray());
assertArrayEquals(new Integer[] { 4, 5, 6 }, trigger.getActivators().toArray());
assertEquals(200.0, trigger.getCollisionBoxWidth(), 0.0001);
assertEquals(200.0, trigger.getCollisionBoxHeight(), 0.0001);
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class MapSelectionPanel method select.
private boolean select(DefaultMutableTreeNode parent, Predicate<IEntity> selectionPredicate) {
if (parent.getChildCount() == 0) {
return false;
}
Enumeration en = parent.depthFirstEnumeration();
while (en.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
IEntity ent = null;
if (node.getUserObject() instanceof IconTreeListItem) {
IconTreeListItem iconItem = (IconTreeListItem) node.getUserObject();
if (iconItem.getUserObject() instanceof IEntity) {
ent = (IEntity) iconItem.getUserObject();
}
} else if (node.getUserObject() instanceof IEntity) {
ent = (IEntity) node.getUserObject();
}
if (ent == null) {
continue;
}
if (selectionPredicate.test(ent)) {
final TreePath newSelection = new TreePath(node.getPath());
if (this.tree.getSelectionPath() != null && this.tree.getSelectionPath().equals(newSelection)) {
continue;
}
this.tree.setSelectionPath(newSelection);
TreePath path = this.tree.getSelectionPath();
if (path == null || !this.tree.isVisible()) {
return false;
}
Rectangle bounds = this.tree.getPathBounds(path);
if (bounds == null) {
return false;
}
// set the height to the visible height to force the node to top
bounds.height = this.tree.getVisibleRect().height;
this.tree.scrollRectToVisible(bounds);
return true;
}
}
return false;
}
Aggregations