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);
}
}
}
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);
}
}
});
}
Aggregations