Search in sources :

Example 1 with Emitter

use of de.gurkenlabs.litiengine.graphics.particles.Emitter in project litiengine by gurkenlabs.

the class EnvironmentTests method testLoading.

@Test
public void testLoading() {
    CollisionBox testCollider = new CollisionBox(true);
    testCollider.setMapId(1);
    testCollider.setName("test");
    this.testEnvironment.add(testCollider);
    Prop testProp = new Prop(0, 0, null);
    testProp.setMapId(1);
    testProp.setName("test");
    this.testEnvironment.add(testProp);
    Emitter testEmitter = new Emitter(1, 1) {

        @Override
        protected Particle createNewParticle() {
            return null;
        }
    };
    testEmitter.setMapId(1);
    testEmitter.setName("test");
    this.testEnvironment.add(testEmitter);
    this.testEnvironment.load();
    // load a second time to ensure nothing brakes
    this.testEnvironment.load();
    assertTrue(this.testEnvironment.isLoaded());
    CollisionBox testCollider2 = new CollisionBox(true);
    testCollider.setMapId(2);
    testCollider.setName("test2");
    this.testEnvironment.add(testCollider2);
    this.testEnvironment.unload();
    assertFalse(this.testEnvironment.isLoaded());
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) Prop(de.gurkenlabs.litiengine.entities.Prop) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Emitter

use of de.gurkenlabs.litiengine.graphics.particles.Emitter in project litiengine by gurkenlabs.

the class Environment method add.

@Override
public void add(final IEntity entity) {
    if (entity == null) {
        return;
    }
    // set local map id if none is set for the entity
    if (entity.getMapId() == 0) {
        entity.setMapId(this.getLocalMapId());
    }
    if (entity instanceof Emitter) {
        Emitter emitter = (Emitter) entity;
        this.getGroundRenderables().add(emitter.getGroundRenderable());
        this.getOverlayRenderables().add(emitter.getOverlayRenderable());
        this.emitters.add(emitter);
    }
    if (entity instanceof ICombatEntity) {
        this.combatEntities.put(entity.getMapId(), (ICombatEntity) entity);
    }
    if (entity instanceof IMobileEntity) {
        this.mobileEntities.put(entity.getMapId(), (IMobileEntity) entity);
    }
    if (entity instanceof Prop) {
        this.props.add((Prop) entity);
    }
    if (entity instanceof Creature) {
        this.creatures.add((Creature) entity);
    }
    if (entity instanceof CollisionBox) {
        this.colliders.add((CollisionBox) entity);
    }
    if (entity instanceof LightSource) {
        this.lightSources.add((LightSource) entity);
    }
    if (entity instanceof Trigger) {
        this.triggers.add((Trigger) entity);
    }
    if (entity instanceof Spawnpoint) {
        this.spawnPoints.add((Spawnpoint) entity);
    }
    if (entity instanceof StaticShadow) {
        this.staticShadows.add((StaticShadow) entity);
    } else if (entity instanceof MapArea) {
        this.mapAreas.add((MapArea) entity);
    }
    for (String rawTag : entity.getTags()) {
        if (rawTag == null) {
            continue;
        }
        final String tag = rawTag.trim().toLowerCase();
        if (tag.isEmpty()) {
            continue;
        }
        if (this.entitiesByTag.containsKey(tag)) {
            this.entitiesByTag.get(tag).add(entity);
            continue;
        }
        this.entitiesByTag.put(tag, new CopyOnWriteArrayList<>());
        this.entitiesByTag.get(tag).add(entity);
    }
    // we need to load the new entity manually
    if (this.loaded) {
        this.load(entity);
    }
    this.entities.get(entity.getRenderType()).put(entity.getMapId(), entity);
    for (Consumer<IEntity> cons : this.entityAddedConsumers) {
        cons.accept(entity);
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Creature(de.gurkenlabs.litiengine.entities.Creature) 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)

Example 3 with Emitter

use of de.gurkenlabs.litiengine.graphics.particles.Emitter in project litiengine by gurkenlabs.

the class Environment method unload.

/**
 * Unload the specified entity by performing the following steps:
 * <ol>
 * <li>remove entities from physics engine</li>
 * <li>unregister units from update</li>
 * <li>unregister ai controller from update</li>
 * <li>unregister animation controller from update</li>
 * <li>unregister movement controller from update</li>
 * </ol>
 *
 * @param entity
 */
private void unload(final IEntity entity) {
    // 1. remove from physics engine
    if (entity instanceof CollisionBox) {
        final CollisionBox coll = (CollisionBox) entity;
        if (coll.isObstacle()) {
            Game.getPhysicsEngine().remove(coll.getBoundingBox());
        } else {
            Game.getPhysicsEngine().remove(coll);
        }
    } else if (entity instanceof ICollisionEntity) {
        final ICollisionEntity coll = (ICollisionEntity) entity;
        Game.getPhysicsEngine().remove(coll);
    }
    // 2. unregister from update
    if (entity instanceof IUpdateable) {
        Game.getLoop().detach((IUpdateable) entity);
    }
    // 3. unregister ai controller from update
    final IEntityController<? extends IEntity> controller = Game.getEntityControllerManager().getAIController(entity);
    if (controller != null) {
        Game.getLoop().detach(controller);
    }
    // 4. unregister animation controller from update
    final IAnimationController animation = Game.getEntityControllerManager().getAnimationController(entity);
    if (animation != null) {
        Game.getLoop().detach(animation);
    }
    // 5. unregister movement controller from update
    if (entity instanceof IMobileEntity) {
        final IMovementController<? extends IMobileEntity> movementController = Game.getEntityControllerManager().getMovementController((IMobileEntity) entity);
        if (movementController != null) {
            Game.getLoop().detach(movementController);
        }
    }
    if (entity instanceof Emitter) {
        Emitter em = (Emitter) entity;
        em.deactivate();
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) IUpdateable(de.gurkenlabs.litiengine.IUpdateable) ICollisionEntity(de.gurkenlabs.litiengine.entities.ICollisionEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Example 4 with Emitter

use of de.gurkenlabs.litiengine.graphics.particles.Emitter in project litiengine by gurkenlabs.

the class MapSelectionPanel method populateMapObjectTree.

private void populateMapObjectTree() {
    this.nodeRoot.setUserObject(new IconTreeListItem(Game.getEnvironment().getEntities().size() + " " + Resources.get("panel_mapselection_entities"), Icons.FOLDER));
    for (DefaultMutableTreeNode node : this.entityNodes) {
        node.removeAllChildren();
    }
    this.nodeLights.setUserObject(new IconTreeListItem(Game.getEnvironment().getLightSources().size() + " " + Resources.get("panel_mapselection_lights"), Icons.LIGHT));
    this.nodeProps.setUserObject(new IconTreeListItem(Game.getEnvironment().getProps().size() + " " + Resources.get("panel_mapselection_props"), Icons.PROP));
    this.nodeCreatures.setUserObject(new IconTreeListItem(Game.getEnvironment().getCreatures().size() + " " + Resources.get("panel_mapselection_creatures"), Icons.CREATURE));
    this.nodeTriggers.setUserObject(new IconTreeListItem(Game.getEnvironment().getTriggers().size() + " " + Resources.get("panel_mapselection_triggers"), Icons.TRIGGER));
    this.nodeSpawnpoints.setUserObject(new IconTreeListItem(Game.getEnvironment().getSpawnPoints().size() + " " + Resources.get("panel_mapselection_spawnpoints"), Icons.SPAWMPOINT));
    this.nodeCollisionBoxes.setUserObject(new IconTreeListItem(Game.getEnvironment().getCollisionBoxes().size() + " " + Resources.get("panel_mapselection_collboxes"), Icons.COLLISIONBOX));
    this.nodeMapAreas.setUserObject(new IconTreeListItem(Game.getEnvironment().getAreas().size() + " " + Resources.get("panel_mapselection_areas"), Icons.MAPAREA));
    this.nodeStaticShadows.setUserObject(new IconTreeListItem(Game.getEnvironment().getStaticShadows().size() + " " + Resources.get("panel_mapselection_shadow"), Icons.SHADOWBOX));
    this.nodeEmitter.setUserObject(new IconTreeListItem(Game.getEnvironment().getEmitters().size() + " " + Resources.get("panel_mapselection_emitter"), Icons.EMITTER));
    for (LightSource light : Game.getEnvironment().getLightSources()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(light));
        this.nodeLights.add(node);
    }
    for (Prop prop : Game.getEnvironment().getProps()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(prop));
        this.nodeProps.add(node);
    }
    for (Creature creature : Game.getEnvironment().getCreatures()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(creature));
        this.nodeCreatures.add(node);
    }
    for (Trigger trigger : Game.getEnvironment().getTriggers()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(trigger));
        this.nodeTriggers.add(node);
    }
    for (Spawnpoint spawn : Game.getEnvironment().getSpawnPoints()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(spawn));
        this.nodeSpawnpoints.add(node);
    }
    for (CollisionBox coll : Game.getEnvironment().getCollisionBoxes()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(coll));
        this.nodeCollisionBoxes.add(node);
    }
    for (MapArea area : Game.getEnvironment().getAreas()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(area));
        this.nodeMapAreas.add(node);
    }
    for (StaticShadow shadow : Game.getEnvironment().getStaticShadows()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(shadow));
        this.nodeStaticShadows.add(node);
    }
    for (Emitter emitter : Game.getEnvironment().getEmitters()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new IconTreeListItem(emitter));
        this.nodeEmitter.add(node);
    }
    this.entitiesTreeModel.reload();
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) Creature(de.gurkenlabs.litiengine.entities.Creature) Trigger(de.gurkenlabs.litiengine.entities.Trigger) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Prop(de.gurkenlabs.litiengine.entities.Prop) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) IconTreeListItem(de.gurkenlabs.utiliti.swing.IconTreeListItem) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Example 5 with Emitter

use of de.gurkenlabs.litiengine.graphics.particles.Emitter in project litiengine by gurkenlabs.

the class EnvironmentTests method testEmitter.

@Test
public void testEmitter() {
    Emitter testEmitter = new Emitter(1, 1) {

        @Override
        protected Particle createNewParticle() {
            return null;
        }
    };
    testEmitter.setMapId(1);
    testEmitter.setName("test");
    this.testEnvironment.add(testEmitter);
    assertNotNull(this.testEnvironment.getEmitter(1));
    assertNotNull(this.testEnvironment.getEmitter("test"));
    assertEquals(1, this.testEnvironment.getByType(Emitter.class).size());
    assertEquals(1, this.testEnvironment.getEntities().size());
    this.testEnvironment.remove(testEmitter);
    assertNull(this.testEnvironment.getEmitter(1));
    assertNull(this.testEnvironment.getEmitter("test"));
    assertEquals(0, this.testEnvironment.getByType(Emitter.class).size());
    assertEquals(0, this.testEnvironment.getEntities().size());
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)6 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)5 Prop (de.gurkenlabs.litiengine.entities.Prop)4 Creature (de.gurkenlabs.litiengine.entities.Creature)3 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)3 Trigger (de.gurkenlabs.litiengine.entities.Trigger)3 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)3 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)3 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)3 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)3 ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)2 IEntity (de.gurkenlabs.litiengine.entities.IEntity)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 IUpdateable (de.gurkenlabs.litiengine.IUpdateable)1 ICollisionEntity (de.gurkenlabs.litiengine.entities.ICollisionEntity)1 IAnimationController (de.gurkenlabs.litiengine.graphics.animation.IAnimationController)1 IconTreeListItem (de.gurkenlabs.utiliti.swing.IconTreeListItem)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1