use of de.gurkenlabs.litiengine.environment.tilemap.IImageLayer 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.IImageLayer 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.environment.tilemap.IImageLayer in project litiengine by gurkenlabs.
the class MapComponent method importMap.
public void importMap() {
if (this.getMaps() == null) {
return;
}
XmlImportDialog.importXml("Tilemap", file -> {
String mapPath = file.toURI().toString();
Resources.maps().clear();
TmxMap map = (TmxMap) Resources.maps().get(mapPath);
if (map == null) {
log.log(Level.WARNING, "could not load map from file {0}", new Object[] { mapPath });
return;
}
if (map.getMapObjectLayers().isEmpty()) {
// make sure there's a map object layer on the map because we need one
// to add any kind of entities
MapObjectLayer layer = new MapObjectLayer();
layer.setName(MapObjectLayer.DEFAULT_MAPOBJECTLAYER_NAME);
map.addLayer(layer);
}
Optional<TmxMap> current = this.maps.stream().filter(x -> x.getName().equals(map.getName())).findFirst();
if (current.isPresent()) {
if (ConfirmDialog.show(Resources.strings().get("input_replace_map_title"), Resources.strings().get("input_replace_map", map.getName()))) {
this.getMaps().remove(current.get());
} else {
return;
}
}
this.getMaps().add(map);
Collections.sort(this.getMaps());
for (IImageLayer imageLayer : map.getImageLayers()) {
BufferedImage img = Resources.images().get(imageLayer.getImage().getAbsoluteSourcePath(), true);
if (img == null) {
continue;
}
Spritesheet sprite = Resources.spritesheets().load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
Editor.instance().getGameFile().getSpriteSheets().add(new SpritesheetResource(sprite));
}
// remove old spritesheets
for (ITileset tileSet : map.getTilesets()) {
Editor.instance().loadTileset(tileSet, true);
}
// remove old tilesets
for (ITileset tileset : map.getExternalTilesets()) {
Editor.instance().loadTileset(tileset, false);
}
Editor.instance().updateGameFileMaps();
Resources.images().clear();
Renderers.get(GridRenderer.class).clearCache();
if (this.environments.containsKey(map.getName())) {
this.environments.remove(map.getName());
}
UI.getMapController().bind(this.getMaps(), true);
this.loadEnvironment(map);
log.log(Level.INFO, "imported map {0}", new Object[] { map.getName() });
}, TmxMap.FILE_EXTENSION);
}
Aggregations