use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.
the class AssetPanel method loadTilesets.
public void loadTilesets(List<Tileset> tilesets) {
this.load(tilesets, () -> {
Collections.sort(tilesets);
for (Tileset tileset : tilesets) {
AssetPanelItem panelItem = new AssetPanelItem(Icons.DOC_TILESET, tileset.getName(), tileset);
this.add(panelItem);
panelItem.validate();
}
});
}
use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.
the class AssetPanelItem method exportTileset.
private void exportTileset() {
if (!(this.getOrigin() instanceof Tileset)) {
return;
}
Tileset tileset = (Tileset) this.getOrigin();
XmlExportDialog.export(tileset, "Tileset", tileset.getName(), Tileset.FILE_EXTENSION);
}
use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset 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.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.
the class EditorScreen method importTilesets.
public void importTilesets() {
XmlImportDialog.importXml("Tilesets", Tileset.FILE_EXTENSION, files -> {
for (File file : files) {
Tileset tileset = XmlUtilities.readFromFile(Tileset.class, file.toString());
if (tileset == null) {
continue;
}
String path = FileUtilities.getParentDirPath(file.getPath());
tileset.setMapPath(path);
if (this.gameFile.getTilesets().stream().anyMatch(x -> x.getName().equals(tileset.getName()))) {
int result = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), Resources.get("import_tileset_title", tileset.getName()), Resources.get("import_tileset_title"), JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.NO_OPTION) {
continue;
}
this.getMapComponent().loadTileset(tileset, false);
}
log.log(Level.INFO, "imported tileset {0} from {1}", new Object[] { tileset.getName(), file });
}
});
}
use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.
the class GameData method load.
public static GameData load(final String file) {
try {
GameData gameFile = getGameFileFromFile(file);
if (gameFile == null) {
return null;
}
gameFile.getMaps().parallelStream().forEach(map -> {
for (final Tileset tileset : map.getRawTileSets()) {
tileset.load(gameFile.getTilesets());
}
map.updateTileTerrain();
});
return gameFile;
} catch (final JAXBException | IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
return null;
}
Aggregations