Search in sources :

Example 1 with IEntity

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);
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Consumer(java.util.function.Consumer) IEntity(de.gurkenlabs.litiengine.entities.IEntity) Test(org.junit.jupiter.api.Test)

Example 2 with IEntity

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));
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) Rectangle2D(java.awt.geom.Rectangle2D) Ellipse2D(java.awt.geom.Ellipse2D) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with IEntity

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);
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) Test(org.junit.jupiter.api.Test)

Example 4 with IEntity

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);
}
Also used : Trigger(de.gurkenlabs.litiengine.entities.Trigger) IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) Test(org.junit.jupiter.api.Test)

Example 5 with IEntity

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;
}
Also used : Enumeration(java.util.Enumeration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) IEntity(de.gurkenlabs.litiengine.entities.IEntity) IconTreeListItem(de.gurkenlabs.utiliti.swing.IconTreeListItem) Rectangle(java.awt.Rectangle)

Aggregations

IEntity (de.gurkenlabs.litiengine.entities.IEntity)26 Test (org.junit.jupiter.api.Test)9 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)6 Trigger (de.gurkenlabs.litiengine.entities.Trigger)5 Dimension (java.awt.Dimension)5 Point (java.awt.Point)5 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)4 ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)4 Prop (de.gurkenlabs.litiengine.entities.Prop)4 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)4 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)4 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)4 Creature (de.gurkenlabs.litiengine.entities.Creature)3 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)3 Direction (de.gurkenlabs.litiengine.entities.Direction)2 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)2 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Consumer (java.util.function.Consumer)2 AttributeModifier (de.gurkenlabs.litiengine.attributes.AttributeModifier)1