use of de.gurkenlabs.litiengine.graphics.ImageFormat in project litiengine by gurkenlabs.
the class MapComponent method exportMap.
public void exportMap(Map map) {
// TODO: replace by XmlExportDialog call
JFileChooser chooser;
try {
String source = EditorScreen.instance().getProjectPath();
chooser = new JFileChooser(source != null ? source : new File(".").getCanonicalPath());
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
chooser.setDialogTitle("Export Map");
FileFilter filter = new FileNameExtensionFilter("tmx - Tilemap XML", Map.FILE_EXTENSION);
chooser.setFileFilter(filter);
chooser.addChoosableFileFilter(filter);
chooser.setSelectedFile(new File(map.getFileName() + "." + Map.FILE_EXTENSION));
int result = chooser.showSaveDialog(Game.getScreenManager().getRenderComponent());
if (result == JFileChooser.APPROVE_OPTION) {
String newFile = XmlUtilities.save(map, chooser.getSelectedFile().toString(), Map.FILE_EXTENSION);
// save all tilesets manually because a map has a relative reference to
// the tilesets
String dir = FileUtilities.getParentDirPath(newFile);
for (ITileset tileSet : map.getTilesets()) {
ImageFormat format = ImageFormat.get(FileUtilities.getExtension(tileSet.getImage().getSource()));
ImageSerializer.saveImage(Paths.get(dir, tileSet.getImage().getSource()).toString(), Spritesheet.find(tileSet.getImage().getSource()).getImage(), format);
Tileset tile = (Tileset) tileSet;
if (tile.isExternal()) {
tile.saveSource(dir);
}
}
log.log(Level.INFO, "exported {0} to {1}", new Object[] { map.getFileName(), newFile });
}
} catch (IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
}
use of de.gurkenlabs.litiengine.graphics.ImageFormat in project litiengine by gurkenlabs.
the class AssetPanelItem method exportSpritesheet.
private void exportSpritesheet() {
if (this.getOrigin() instanceof SpriteSheetInfo) {
SpriteSheetInfo spriteSheetInfo = (SpriteSheetInfo) this.getOrigin();
Spritesheet sprite = Spritesheet.find(spriteSheetInfo.getName());
if (sprite == null) {
return;
}
ImageFormat format = sprite.getImageFormat() != ImageFormat.UNDEFINED ? sprite.getImageFormat() : ImageFormat.PNG;
Object[] options = { ".xml", format.toExtension() };
int answer = JOptionPane.showOptionDialog(Game.getScreenManager().getRenderComponent(), "Select an export format:", "Export Spritesheet", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
try {
JFileChooser chooser;
String source = EditorScreen.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.toString() + " - Image", format.toString());
chooser.setFileFilter(filter);
chooser.addChoosableFileFilter(filter);
chooser.setSelectedFile(new File(spriteSheetInfo.getName() + format.toExtension()));
int result = chooser.showSaveDialog(Game.getScreenManager().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);
}
}
}
Aggregations