Search in sources :

Example 16 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class MapAreaMapObjectLoader method load.

@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
    if (MapObjectType.get(mapObject.getType()) != MapObjectType.AREA) {
        throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + MapAreaMapObjectLoader.class);
    }
    Collection<IEntity> entities = super.load(environment, mapObject);
    MapArea mapArea = this.createMapArea(mapObject);
    loadDefaultProperties(mapArea, mapObject);
    entities.add(mapArea);
    return entities;
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea)

Example 17 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class TriggerMapObjectLoader method load.

@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
    if (MapObjectType.get(mapObject.getType()) != MapObjectType.TRIGGER) {
        throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + TriggerMapObjectLoader.class);
    }
    final String message = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_MESSAGE);
    final TriggerActivation act = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION) != null ? TriggerActivation.valueOf(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION)) : TriggerActivation.COLLISION;
    final boolean oneTime = mapObject.getCustomPropertyBool(MapObjectProperty.TRIGGER_ONETIME);
    final int coolDown = mapObject.getCustomPropertyInt(MapObjectProperty.TRIGGER_COOLDOWN);
    final Trigger trigger = this.createTrigger(mapObject, act, message, oneTime, coolDown, mapObject);
    loadDefaultProperties(trigger, mapObject);
    this.loadTargets(mapObject, trigger);
    this.loadActivators(mapObject, trigger);
    Collection<IEntity> entities = super.load(environment, mapObject);
    entities.add(trigger);
    return entities;
}
Also used : TriggerActivation(de.gurkenlabs.litiengine.entities.Trigger.TriggerActivation) Trigger(de.gurkenlabs.litiengine.entities.Trigger) IEntity(de.gurkenlabs.litiengine.entities.IEntity)

Example 18 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class MapComponent method handleEntityDrag.

private void handleEntityDrag(int snappedDeltaX, int snappedDeltaY) {
    for (IMapObject selected : this.getSelectedMapObjects()) {
        selected.setX(selected.getX() + snappedDeltaX);
        selected.setY(selected.getY() + snappedDeltaY);
        IEntity entity = Game.getEnvironment().get(selected.getId());
        if (entity != null) {
            entity.setX(selected.getLocation().getX());
            entity.setY(selected.getLocation().getY());
        } else {
            Game.getEnvironment().reloadFromMap(selected.getId());
        }
        if (selected.equals(this.getFocusedMapObject())) {
            EditorScreen.instance().getMapObjectPanel().bind(selected);
            this.updateTransformControls();
        }
    }
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 19 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class EnvironmentEventTests method testOnAdded.

@Test
public void testOnAdded() {
    ICombatEntity combatEntity = mock(ICombatEntity.class);
    when(combatEntity.getMapId()).thenReturn(123);
    when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
    Consumer<IEntity> addedConsumer = (Consumer<IEntity>) mock(Consumer.class);
    this.testEnvironment.onEntityAdded(addedConsumer);
    this.testEnvironment.add(combatEntity);
    verify(addedConsumer, 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 20 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class MapObjectLoaderTests method testLightSourceMapObjectLoader.

@Test
public void testLightSourceMapObjectLoader() {
    LightSourceMapObjectLoader loader = new LightSourceMapObjectLoader();
    IEnvironment environment = mock(IEnvironment.class);
    IMapObject mapObject = mock(IMapObject.class);
    when(mapObject.getType()).thenReturn(MapObjectType.LIGHTSOURCE.name());
    when(mapObject.getId()).thenReturn(111);
    when(mapObject.getName()).thenReturn("testLight");
    when(mapObject.getLocation()).thenReturn(new Point(100, 100));
    when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
    when(mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_ALPHA)).thenReturn(100);
    when(mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_INTENSITY, 100)).thenReturn(100);
    when(mapObject.getCustomPropertyColor(MapObjectProperty.LIGHT_COLOR)).thenReturn(Color.WHITE);
    when(mapObject.getCustomPropertyBool(MapObjectProperty.LIGHT_ACTIVE, true)).thenReturn(true);
    when(mapObject.getCustomProperty(MapObjectProperty.LIGHT_SHAPE)).thenReturn(LightSource.ELLIPSE);
    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(), "testLight");
    assertEquals(entity.getLocation().getX(), 100, 0.0001);
    assertEquals(entity.getLocation().getY(), 100, 0.0001);
    LightSource light = (LightSource) entity;
    assertTrue(light.isActive());
    assertEquals(Color.WHITE.getRed(), light.getColor().getRed());
    assertEquals(Color.WHITE.getBlue(), light.getColor().getBlue());
    assertEquals(Color.WHITE.getGreen(), light.getColor().getGreen());
    assertEquals(100, light.getColor().getAlpha());
    assertEquals(100, light.getIntensity());
    assertEquals(LightSource.ELLIPSE, light.getLightShapeType());
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Test(org.junit.jupiter.api.Test)

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