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