Search in sources :

Example 6 with LightSource

use of de.gurkenlabs.litiengine.graphics.LightSource 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)

Example 7 with LightSource

use of de.gurkenlabs.litiengine.graphics.LightSource in project litiengine by gurkenlabs.

the class Environment method remove.

@Override
public void remove(final IEntity entity) {
    if (entity == null) {
        return;
    }
    if (this.entities.get(entity.getRenderType()) != null) {
        this.entities.get(entity.getRenderType()).entrySet().removeIf(e -> e.getValue().getMapId() == entity.getMapId());
    }
    for (String tag : entity.getTags()) {
        if (this.entitiesByTag.containsKey(tag)) {
            this.entitiesByTag.get(tag).remove(entity);
            if (this.entitiesByTag.get(tag).isEmpty()) {
                this.entitiesByTag.remove(tag);
            }
        }
    }
    if (entity instanceof Emitter) {
        Emitter emitter = (Emitter) entity;
        this.groundRenderable.remove(emitter.getGroundRenderable());
        this.overlayRenderable.remove(emitter.getOverlayRenderable());
        this.emitters.remove(emitter);
    }
    if (entity instanceof MapArea) {
        this.mapAreas.remove(entity);
    }
    if (entity instanceof Prop) {
        this.props.remove(entity);
    }
    if (entity instanceof Creature) {
        this.creatures.remove(entity);
    }
    if (entity instanceof CollisionBox) {
        this.colliders.remove(entity);
        this.staticShadows.removeIf(x -> x.getOrigin() != null && x.getOrigin().equals(entity));
    }
    if (entity instanceof LightSource) {
        this.lightSources.remove(entity);
        this.updateColorLayers(entity);
    }
    if (entity instanceof Trigger) {
        this.triggers.remove(entity);
    }
    if (entity instanceof Spawnpoint) {
        this.spawnPoints.remove(entity);
    }
    if (entity instanceof StaticShadow) {
        this.staticShadows.remove(entity);
        this.updateColorLayers(entity);
    }
    if (entity instanceof IMobileEntity) {
        this.mobileEntities.values().remove(entity);
    }
    if (entity instanceof ICombatEntity) {
        this.combatEntities.values().remove(entity);
    }
    this.unload(entity);
    for (Consumer<IEntity> cons : this.entityRemovedConsumers) {
        cons.accept(entity);
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) Creature(de.gurkenlabs.litiengine.entities.Creature) ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Prop(de.gurkenlabs.litiengine.entities.Prop) IEntity(de.gurkenlabs.litiengine.entities.IEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) Trigger(de.gurkenlabs.litiengine.entities.Trigger) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Aggregations

LightSource (de.gurkenlabs.litiengine.graphics.LightSource)7 IEntity (de.gurkenlabs.litiengine.entities.IEntity)4 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)4 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)3 Creature (de.gurkenlabs.litiengine.entities.Creature)3 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)3 Prop (de.gurkenlabs.litiengine.entities.Prop)3 Trigger (de.gurkenlabs.litiengine.entities.Trigger)3 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)3 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)3 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)3 ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)2 Color (java.awt.Color)2 Test (org.junit.jupiter.api.Test)2 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)1 IAnimationController (de.gurkenlabs.litiengine.graphics.animation.IAnimationController)1 IconTreeListItem (de.gurkenlabs.utiliti.swing.IconTreeListItem)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1