use of de.gurkenlabs.litiengine.environment.tilemap.IMapLoader in project litiengine by gurkenlabs.
the class MapComponent method loadMaps.
public void loadMaps(String projectPath) {
final List<String> files = FileUtilities.findFilesByExtension(new ArrayList<>(), Paths.get(projectPath), "tmx");
log.log(Level.INFO, "{0} maps found in folder {1}", new Object[] { files.size(), projectPath });
final List<Map> loadedMaps = new ArrayList<>();
for (final String mapFile : files) {
final IMapLoader tmxLoader = new TmxMapLoader();
Map map = (Map) tmxLoader.loadMap(mapFile);
loadedMaps.add(map);
log.log(Level.INFO, "map found: {0}", new Object[] { map.getFileName() });
}
this.loadMaps(loadedMaps);
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapLoader in project litiengine by gurkenlabs.
the class MapComponent method importMap.
public void importMap() {
if (this.getMaps() == null) {
return;
}
final IMapLoader tmxLoader = new TmxMapLoader();
XmlImportDialog.importXml("Tilemap", Map.FILE_EXTENSION, files -> {
for (File file : files) {
String mapPath = file.toString();
Map map = (Map) tmxLoader.loadMap(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(DEFAULT_MAPOBJECTLAYER_NAME);
map.addMapObjectLayer(layer);
}
Optional<Map> current = this.maps.stream().filter(x -> x.getFileName().equals(map.getFileName())).findFirst();
if (current.isPresent()) {
int n = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), Resources.get("input_replace_map", map.getFileName()), Resources.get("input_replace_map_title"), JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
this.getMaps().remove(current.get());
} else {
return;
}
}
this.getMaps().add(map);
Collections.sort(this.getMaps());
for (IImageLayer imageLayer : map.getImageLayers()) {
BufferedImage img = Resources.getImage(imageLayer.getImage().getAbsoluteSourcePath(), true);
Spritesheet sprite = Spritesheet.load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
this.screen.getGameFile().getSpriteSheets().add(new SpriteSheetInfo(sprite));
}
// remove old spritesheets
for (ITileset tileSet : map.getTilesets()) {
this.loadTileset(tileSet, true);
}
// remove old tilesets
for (ITileset tileset : map.getExternalTilesets()) {
this.loadTileset(tileset, false);
}
EditorScreen.instance().updateGameFileMaps();
ImageCache.clearAll();
if (this.environments.containsKey(map.getFileName())) {
this.environments.remove(map.getFileName());
}
EditorScreen.instance().getMapSelectionPanel().bind(this.getMaps(), true);
this.loadEnvironment(map);
log.log(Level.INFO, "imported map {0}", new Object[] { map.getFileName() });
}
});
}
Aggregations