Search in sources :

Example 1 with ImageFormat

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

the class AssetPanelItem method exportSpritesheet.

private void exportSpritesheet() {
    if (this.getOrigin() instanceof SpritesheetResource) {
        SpritesheetResource spriteSheetInfo = (SpritesheetResource) this.getOrigin();
        Spritesheet sprite = Resources.spritesheets().get(spriteSheetInfo.getName());
        if (sprite == null) {
            return;
        }
        ImageFormat format = sprite.getImageFormat() != ImageFormat.UNSUPPORTED ? sprite.getImageFormat() : ImageFormat.PNG;
        Object[] options = { ".xml", format.toFileExtension() };
        int answer = JOptionPane.showOptionDialog(Game.window().getRenderComponent(), "Select an export format:", "Export Spritesheet", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
        try {
            JFileChooser chooser;
            String source = Editor.instance().getProjectPath();
            chooser = new JFileChooser(source != null ? source : new File(".").getCanonicalPath());
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setDialogType(JFileChooser.SAVE_DIALOG);
            chooser.setDialogTitle("Export Spritesheet");
            if (answer == 0) {
                XmlExportDialog.export(spriteSheetInfo, "Spritesheet", spriteSheetInfo.getName());
            } else if (answer == 1) {
                FileFilter filter = new FileNameExtensionFilter(format + " - Image", format.toString());
                chooser.setFileFilter(filter);
                chooser.addChoosableFileFilter(filter);
                chooser.setSelectedFile(new File(spriteSheetInfo.getName() + format.toFileExtension()));
                int result = chooser.showSaveDialog(Game.window().getRenderComponent());
                if (result == JFileChooser.APPROVE_OPTION) {
                    ImageSerializer.saveImage(chooser.getSelectedFile().toString(), sprite.getImage(), format);
                    log.log(Level.INFO, "exported spritesheet {0} to {1}", new Object[] { spriteSheetInfo.getName(), chooser.getSelectedFile() });
                }
            }
        } catch (IOException e) {
            log.log(Level.SEVERE, e.getMessage(), e);
        }
    }
}
Also used : SpritesheetResource(de.gurkenlabs.litiengine.resources.SpritesheetResource) JFileChooser(javax.swing.JFileChooser) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) ImageFormat(de.gurkenlabs.litiengine.resources.ImageFormat)

Example 2 with ImageFormat

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

the class MapComponent method exportMap.

public void exportMap() {
    if (this.getMaps() == null || this.getMaps().isEmpty()) {
        return;
    }
    TmxMap map = (TmxMap) Game.world().environment().getMap();
    if (map == null) {
        return;
    }
    XmlExportDialog.export(map, "Map", map.getName(), TmxMap.FILE_EXTENSION, dir -> {
        for (ITileset tileSet : map.getTilesets()) {
            ImageFormat format = ImageFormat.get(FileUtilities.getExtension(tileSet.getImage().getSource()));
            ImageSerializer.saveImage(Paths.get(dir, tileSet.getImage().getSource()).toString(), Resources.spritesheets().get(tileSet.getImage().getSource()).getImage(), format);
            Tileset tile = (Tileset) tileSet;
            if (tile.isExternal()) {
                tile.saveSource(dir);
            }
        }
    });
}
Also used : TmxMap(de.gurkenlabs.litiengine.environment.tilemap.xml.TmxMap) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) ImageFormat(de.gurkenlabs.litiengine.resources.ImageFormat)

Aggregations

ImageFormat (de.gurkenlabs.litiengine.resources.ImageFormat)2 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)1 ITileset (de.gurkenlabs.litiengine.environment.tilemap.ITileset)1 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)1 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)1 Tileset (de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)1 TmxMap (de.gurkenlabs.litiengine.environment.tilemap.xml.TmxMap)1 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)1 SpritesheetResource (de.gurkenlabs.litiengine.resources.SpritesheetResource)1 File (java.io.File)1 IOException (java.io.IOException)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1