Search in sources :

Example 1 with EmitterData

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);
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.emitters.Emitter) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 2 with EmitterData

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 });
    });
}
Also used : JAXBException(jakarta.xml.bind.JAXBException) IOException(java.io.IOException) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 3 with EmitterData

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 });
}
Also used : Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) Sound(de.gurkenlabs.litiengine.sound.Sound) Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) BufferedImage(java.awt.image.BufferedImage) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 4 with EmitterData

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;
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.emitters.Emitter) IEntity(de.gurkenlabs.litiengine.entities.IEntity) ArrayList(java.util.ArrayList) EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Example 5 with EmitterData

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);
}
Also used : EmitterData(de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)

Aggregations

EmitterData (de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)12 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)4 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)4 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)4 SpritesheetResource (de.gurkenlabs.litiengine.resources.SpritesheetResource)3 Emitter (de.gurkenlabs.litiengine.graphics.emitters.Emitter)2 Align (de.gurkenlabs.litiengine.Align)1 Valign (de.gurkenlabs.litiengine.Valign)1 Quality (de.gurkenlabs.litiengine.configuration.Quality)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 Tileset (de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)1 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)1 ParticleType (de.gurkenlabs.litiengine.graphics.emitters.particles.ParticleType)1 ParticleParameter (de.gurkenlabs.litiengine.graphics.emitters.xml.ParticleParameter)1 Collision (de.gurkenlabs.litiengine.physics.Collision)1 SoundResource (de.gurkenlabs.litiengine.resources.SoundResource)1 Sound (de.gurkenlabs.litiengine.sound.Sound)1 JAXBException (jakarta.xml.bind.JAXBException)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1