use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.
the class EditorScreen method loadSpriteSheets.
private void loadSpriteSheets(Map map) {
List<SpriteSheetInfo> infos = new ArrayList<>();
int cnt = 0;
for (ITileset tileSet : map.getTilesets()) {
if (tileSet.getImage() == null || Spritesheet.find(tileSet.getName()) != null) {
continue;
}
Spritesheet sprite = Spritesheet.find(tileSet.getImage().getSource());
if (sprite == null) {
sprite = Spritesheet.load(tileSet);
if (sprite == null) {
continue;
}
}
infos.add(new SpriteSheetInfo(sprite));
cnt++;
}
for (IImageLayer imageLayer : map.getImageLayers()) {
Spritesheet sprite = Spritesheet.find(imageLayer.getImage().getSource());
if (sprite == null) {
BufferedImage img = Resources.getImage(imageLayer.getImage().getAbsoluteSourcePath(), true);
sprite = Spritesheet.load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
if (sprite == null) {
continue;
}
}
SpriteSheetInfo info = new SpriteSheetInfo(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 (SpriteSheetInfo info : infos) {
if (!this.getGameFile().getSpriteSheets().stream().anyMatch(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.getFileName() });
}
}
use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.
the class EditorScreen method importSpritesheets.
public void importSpritesheets() {
JFileChooser chooser;
try {
chooser = new JFileChooser(new File(this.getProjectPath()).getCanonicalPath());
FileFilter filter = new FileNameExtensionFilter(SPRITESHEET_FILE_NAME, ImageFormat.getAllExtensions());
chooser.setFileFilter(filter);
chooser.addChoosableFileFilter(filter);
chooser.setMultiSelectionEnabled(true);
if (chooser.showOpenDialog(Game.getScreenManager().getRenderComponent()) == JFileChooser.APPROVE_OPTION) {
SpritesheetImportPanel spritePanel = new SpritesheetImportPanel(chooser.getSelectedFiles());
int option = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), spritePanel, Resources.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<SpriteSheetInfo> sprites = spritePanel.getSpriteSheets();
for (SpriteSheetInfo info : sprites) {
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);
}
} catch (IOException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.
the class MapComponent method loadTileset.
public void loadTileset(ITileset tileset, boolean embedded) {
Spritesheet sprite = Spritesheet.find(tileset.getImage().getSource());
if (sprite != null) {
Spritesheet.remove(sprite.getName());
this.screen.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(sprite.getName()));
}
Spritesheet newSprite = Spritesheet.load(tileset);
SpriteSheetInfo info = new SpriteSheetInfo(newSprite);
EditorScreen.instance().getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
EditorScreen.instance().getGameFile().getSpriteSheets().add(info);
EditorScreen.instance().loadSpriteSheets(Arrays.asList(info), true);
if (!embedded) {
this.screen.getGameFile().getTilesets().removeIf(x -> x.getName().equals(tileset.getName()));
this.screen.getGameFile().getTilesets().add((Tileset) tileset);
}
}
use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.
the class AssetPanel method loadSprites.
public void loadSprites(List<SpriteSheetInfo> infos) {
this.load(infos, () -> {
Collections.sort(infos);
for (SpriteSheetInfo info : infos) {
Icon icon;
Spritesheet sprite = Spritesheet.find(info.getName());
if (sprite == null || sprite.getSprite(0) == null) {
icon = null;
} else {
icon = new ImageIcon(ImageProcessing.scaleImage(sprite.getSprite(0), 64, 64, true));
}
AssetPanelItem panelItem = new AssetPanelItem(icon, info.getName(), info);
this.add(panelItem);
panelItem.validate();
}
});
}
use of de.gurkenlabs.litiengine.SpriteSheetInfo in project litiengine by gurkenlabs.
the class EditorScreen method importSpriteFile.
public void importSpriteFile() {
JFileChooser chooser;
try {
chooser = new JFileChooser(new File(this.getProjectPath()).getCanonicalPath());
FileFilter filter = new FileNameExtensionFilter(SPRITE_FILE_NAME, SpriteSheetInfo.PLAIN_TEXT_FILE_EXTENSION);
chooser.setFileFilter(filter);
chooser.addChoosableFileFilter(filter);
if (chooser.showOpenDialog(Game.getScreenManager().getRenderComponent()) == JFileChooser.APPROVE_OPTION) {
File spriteFile = chooser.getSelectedFile();
if (spriteFile == null) {
return;
}
List<Spritesheet> loaded = Spritesheet.load(spriteFile.toString());
List<SpriteSheetInfo> infos = new ArrayList<>();
for (Spritesheet sprite : loaded) {
SpriteSheetInfo info = new SpriteSheetInfo(sprite);
infos.add(info);
this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
this.getGameFile().getSpriteSheets().add(info);
}
this.loadSpriteSheets(infos, true);
}
} catch (IOException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
Aggregations