use of de.gurkenlabs.litiengine.graphics.emitters.Emitter in project litiengine by gurkenlabs.
the class EnvironmentTests method testLoading.
@Test
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());
}
use of de.gurkenlabs.litiengine.graphics.emitters.Emitter in project litiengine by gurkenlabs.
the class MapComponent method defineBlueprint.
public void defineBlueprint() {
if (this.getFocusedMapObject() == null) {
return;
}
Object name = JOptionPane.showInputDialog(Game.window().getRenderComponent(), Resources.strings().get("input_prompt_name"), Resources.strings().get("input_prompt_name_title"), JOptionPane.PLAIN_MESSAGE, null, null, this.getFocusedMapObject().getName());
if (name == null) {
return;
}
if (this.getFocusedMapObject().getType().equals(MapObjectType.EMITTER.toString())) {
Emitter emitter = Game.world().environment().getEmitter(this.getFocusedMapObject().getId());
final EmitterData data = emitter.data();
data.setName(name.toString());
Editor.instance().getGameFile().getEmitters().removeIf(x -> x.getName().equals(data.getName()));
Editor.instance().getGameFile().getEmitters().add(data);
}
Blueprint blueprint = new Blueprint(name.toString(), this.getSelectedMapObjects().toArray(new MapObject[this.getSelectedMapObjects().size()]));
Editor.instance().getGameFile().getBluePrints().add(blueprint);
}
use of de.gurkenlabs.litiengine.graphics.emitters.Emitter in project litiengine by gurkenlabs.
the class EmitterMapObjectLoader method load.
@Override
public Collection<IEntity> load(Environment environment, IMapObject mapObject) {
Collection<IEntity> entities = new ArrayList<>();
if (!this.isMatchingType(mapObject)) {
return entities;
}
EmitterData data = createEmitterData(mapObject);
Emitter emitter = new Emitter(data);
loadDefaultProperties(emitter, mapObject);
entities.add(emitter);
return entities;
}
use of de.gurkenlabs.litiengine.graphics.emitters.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 ICollisionEntity) {
Game.physics().remove((ICollisionEntity) entity);
}
// 2. unregister from update
if (entity instanceof IUpdateable) {
Game.loop().detach((IUpdateable) entity);
}
if (entity instanceof IMobileEntity) {
this.removeGravity((IMobileEntity) entity);
}
// 3. detach all controllers
entity.detachControllers();
if (entity instanceof Emitter) {
Emitter em = (Emitter) entity;
em.deactivate();
}
if (this.loaded && (entity instanceof LightSource || entity instanceof StaticShadow)) {
this.updateLighting(entity);
}
entity.removed(this);
}
use of de.gurkenlabs.litiengine.graphics.emitters.Emitter in project litiengine by gurkenlabs.
the class EnvironmentTests method testEmitter.
@Test
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.getEntities(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.getEntities(Emitter.class).size());
assertEquals(0, this.testEnvironment.getEntities().size());
}
Aggregations