Search in sources :

Example 1 with SpritesheetResource

use of de.gurkenlabs.litiengine.resources.SpritesheetResource in project litiengine by gurkenlabs.

the class Editor method loadTileset.

public void loadTileset(ITileset tileset, boolean embedded) {
    if (tileset == null) {
        return;
    }
    Spritesheet sprite = Resources.spritesheets().get(tileset.getImage().getSource());
    if (sprite != null) {
        Resources.spritesheets().remove(sprite.getName());
        getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(sprite.getName()));
    }
    Spritesheet newSprite = Resources.spritesheets().load(tileset);
    SpritesheetResource info = new SpritesheetResource(newSprite);
    getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
    getGameFile().getSpriteSheets().add(info);
    loadSpriteSheets(Arrays.asList(info), true);
    if (!embedded) {
        getGameFile().getTilesets().removeIf(x -> x.getName().equals(tileset.getName()));
        getGameFile().getTilesets().add((Tileset) tileset);
    }
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet)

Example 2 with SpritesheetResource

use of de.gurkenlabs.litiengine.resources.SpritesheetResource in project litiengine by gurkenlabs.

the class Editor method loadSpriteSheets.

private void loadSpriteSheets(TmxMap map) {
    List<SpritesheetResource> infos = new ArrayList<>();
    int cnt = 0;
    for (ITileset tileSet : map.getTilesets()) {
        if (tileSet.getImage() == null) {
            continue;
        }
        Spritesheet opt = Resources.spritesheets().get(tileSet.getImage().getSource());
        Spritesheet sprite = null;
        if (opt == null) {
            sprite = Resources.spritesheets().load(tileSet);
            if (sprite == null) {
                continue;
            }
        } else {
            sprite = opt;
        }
        infos.add(new SpritesheetResource(sprite));
        cnt++;
    }
    for (IImageLayer imageLayer : map.getImageLayers()) {
        Spritesheet opt = Resources.spritesheets().get(imageLayer.getImage().getSource());
        Spritesheet sprite = null;
        if (opt == null) {
            BufferedImage img = Resources.images().get(imageLayer.getImage().getAbsoluteSourcePath(), true);
            if (img == null) {
                continue;
            }
            sprite = Resources.spritesheets().load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
            if (sprite == null) {
                continue;
            }
        } else {
            sprite = opt;
        }
        SpritesheetResource info = new SpritesheetResource(sprite);
        infos.add(info);
        this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
        this.getGameFile().getSpriteSheets().add(info);
        cnt++;
    }
    this.loadSpriteSheets(infos, false);
    for (SpritesheetResource info : infos) {
        if (this.getGameFile().getSpriteSheets().stream().noneMatch(x -> x.getName().equals(info.getName()))) {
            this.getGameFile().getSpriteSheets().add(info);
        }
    }
    if (cnt > 0) {
        log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { cnt, map.getName() });
    }
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IImageLayer(de.gurkenlabs.litiengine.environment.tilemap.IImageLayer) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) BufferedImage(java.awt.image.BufferedImage)

Example 3 with SpritesheetResource

use of de.gurkenlabs.litiengine.resources.SpritesheetResource in project litiengine by gurkenlabs.

the class Editor method processSpritesheets.

private void processSpritesheets(SpritesheetImportPanel spritePanel) {
    int option = JOptionPane.showConfirmDialog(Game.window().getRenderComponent(), spritePanel, Resources.strings().get("menu_assets_editSprite"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (option != JOptionPane.OK_OPTION) {
        return;
    }
    // TODO: somehow improve this to allow keeping the animation frames and only
    // update the image
    Collection<SpritesheetResource> sprites = spritePanel.getSpriteSheets();
    for (SpritesheetResource info : sprites) {
        Resources.spritesheets().getAll().removeIf(x -> x.getName().equals(info.getName() + "-preview"));
        this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
        this.getGameFile().getSpriteSheets().add(info);
        log.log(Level.INFO, "imported spritesheet {0}", new Object[] { info.getName() });
    }
    this.loadSpriteSheets(sprites, true);
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)

Example 4 with SpritesheetResource

use of de.gurkenlabs.litiengine.resources.SpritesheetResource in project litiengine by gurkenlabs.

the class AssetPanelItem method getDetails.

private static Map<String, String> getDetails(Object origin) {
    Map<String, String> details = new ConcurrentHashMap<>();
    if (origin instanceof SpritesheetResource) {
        SpritesheetResource sprite = (SpritesheetResource) origin;
        details.put("Size", sprite.getWidth() + "x" + sprite.getHeight() + "px");
    }
    return details;
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with SpritesheetResource

use of de.gurkenlabs.litiengine.resources.SpritesheetResource in project litiengine by gurkenlabs.

the class Editor method importSpriteFile.

public void importSpriteFile() {
    if (EditorFileChooser.showFileDialog(SPRITE_FILE_NAME, Resources.strings().get(IMPORT_DIALOGUE, SPRITE_FILE_NAME), false, SpritesheetResource.PLAIN_TEXT_FILE_EXTENSION) == JFileChooser.APPROVE_OPTION) {
        File spriteFile = EditorFileChooser.instance().getSelectedFile();
        if (spriteFile == null) {
            return;
        }
        List<Spritesheet> loaded = Resources.spritesheets().loadFrom(spriteFile.toString());
        List<SpritesheetResource> infos = new ArrayList<>();
        for (Spritesheet sprite : loaded) {
            SpritesheetResource info = new SpritesheetResource(sprite);
            infos.add(info);
            this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
            this.getGameFile().getSpriteSheets().add(info);
        }
        this.loadSpriteSheets(infos, true);
    }
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

SpritesheetResource (de.gurkenlabs.litiengine.resources.SpritesheetResource)12 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)7 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)6 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)4 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)4 EmitterData (de.gurkenlabs.litiengine.graphics.emitters.xml.EmitterData)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 IImageLayer (de.gurkenlabs.litiengine.environment.tilemap.IImageLayer)2 ITileset (de.gurkenlabs.litiengine.environment.tilemap.ITileset)2 ImageFormat (de.gurkenlabs.litiengine.resources.ImageFormat)2 Game (de.gurkenlabs.litiengine.Game)1 EmitterMapObjectLoader (de.gurkenlabs.litiengine.environment.EmitterMapObjectLoader)1 Environment (de.gurkenlabs.litiengine.environment.Environment)1 IMapObjectLayer (de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer)1 MapObjectProperty (de.gurkenlabs.litiengine.environment.tilemap.MapObjectProperty)1 MapObjectType (de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)1 MapRenderer (de.gurkenlabs.litiengine.environment.tilemap.MapRenderer)1 MapObjectLayer (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObjectLayer)1