use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData 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.xml.EmitterData in project litiengine by gurkenlabs.
the class Editor method importEmitters.
public void importEmitters() {
XmlImportDialog.importXml("Emitter", file -> {
EmitterData emitter;
try {
emitter = XmlUtilities.read(EmitterData.class, file.toURI().toURL());
} catch (IOException | JAXBException e) {
log.log(Level.SEVERE, String.format("could not load emitter data from %s", file), e);
return;
}
if (this.gameFile.getEmitters().stream().anyMatch(x -> x.getName().equals(emitter.getName()))) {
if (!ConfirmDialog.show(Resources.strings().get("import_emitter_title"), Resources.strings().get("import_emitter_question", emitter.getName()))) {
return;
}
this.gameFile.getEmitters().removeIf(x -> x.getName().equals(emitter.getName()));
}
this.gameFile.getEmitters().add(emitter);
log.log(Level.INFO, "imported emitter {0} from {1}", new Object[] { emitter.getName(), file });
});
}
use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData in project litiengine by gurkenlabs.
the class Resources method load.
/**
* Load {@code Spritesheets}, {@code Tilesets} and {@code Maps} from a game resource file created with the utiLITI
* editor. After loading, these resources can be accessed via this API (e.g. {@code Resources.maps().get("mapname")}.
*
* @param gameResourceFile
* The URL to the game resource file
*/
public static void load(final URL gameResourceFile) {
final long loadStart = System.nanoTime();
final ResourceBundle file = ResourceBundle.load(gameResourceFile);
if (file == null) {
return;
}
file.getMaps().parallelStream().forEach(m -> Resources.maps().add(m.getName(), m));
log.log(Level.INFO, "{0} maps loaded from {1}", new Object[] { file.getMaps().size(), gameResourceFile });
file.getBluePrints().parallelStream().forEach(m -> Resources.blueprints().add(m.getName(), m));
log.log(Level.INFO, "{0} blueprints loaded from {1}", new Object[] { file.getBluePrints().size(), gameResourceFile });
int tileCnt = 0;
for (final Tileset tileset : file.getTilesets()) {
if (Resources.tilesets().contains(tileset.getName())) {
continue;
}
Resources.tilesets().add(tileset.getName(), tileset);
tileCnt++;
}
log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { tileCnt, gameResourceFile });
final List<Spritesheet> loadedSprites = Collections.synchronizedList(new ArrayList<>());
file.getSpriteSheets().parallelStream().forEach(spriteSheetInfo -> {
final Spritesheet sprite = Resources.spritesheets().load(spriteSheetInfo);
loadedSprites.add(sprite);
});
log.log(Level.INFO, "{0} spritesheets loaded from {1}", new Object[] { loadedSprites.size(), gameResourceFile });
final List<Sound> loadedSounds = Collections.synchronizedList(new ArrayList<>());
file.getSounds().parallelStream().forEach(soundResource -> {
final Sound sound = Resources.sounds().load(soundResource);
loadedSounds.add(sound);
});
log.log(Level.INFO, "{0} sounds loaded from {1}", new Object[] { loadedSounds.size(), gameResourceFile });
int spriteload = 0;
for (final Spritesheet s : loadedSprites) {
for (int i = 0; i < s.getRows() * s.getColumns(); i++) {
BufferedImage sprite = s.getSprite(i);
if (sprite != null) {
spriteload++;
}
}
}
log.log(Level.INFO, "{0} sprites loaded to memory", new Object[] { spriteload });
for (final EmitterData emitter : file.getEmitters()) {
EmitterLoader.load(emitter);
}
final double loadTime = TimeUtilities.nanoToMs(System.nanoTime() - loadStart);
log.log(Level.INFO, "loading game resources from {0} took {1} ms", new Object[] { gameResourceFile, loadTime });
}
use of de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData 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.xml.EmitterData in project litiengine by gurkenlabs.
the class Emitter method setEmitterData.
public void setEmitterData(final String emitterXmlPath) {
EmitterData loaded = EmitterLoader.load(emitterXmlPath);
setEmitterData(loaded);
}
Aggregations