use of de.gurkenlabs.litiengine.environment.Environment in project litiengine by gurkenlabs.
the class MapComponent method loadEnvironment.
public void loadEnvironment(Map map) {
this.loading = true;
try {
if (Game.getEnvironment() != null && Game.getEnvironment().getMap() != null) {
final String mapName = Game.getEnvironment().getMap().getFileName();
double x = Game.getCamera().getFocus().getX();
double y = Game.getCamera().getFocus().getY();
Point2D newPoint = new Point2D.Double(x, y);
this.cameraFocus.put(mapName, newPoint);
this.selectedLayers.put(mapName, EditorScreen.instance().getMapSelectionPanel().getSelectedLayerIndex());
}
Point2D newFocus = null;
if (this.cameraFocus.containsKey(map.getFileName())) {
newFocus = this.cameraFocus.get(map.getFileName());
} else {
newFocus = new Point2D.Double(map.getSizeInPixels().getWidth() / 2, map.getSizeInPixels().getHeight() / 2);
this.cameraFocus.put(map.getFileName(), newFocus);
}
Game.getCamera().setFocus(new Point2D.Double(newFocus.getX(), newFocus.getY()));
this.ensureUniqueIds(map);
if (!this.environments.containsKey(map.getFileName())) {
Environment env = new Environment(map);
env.init();
this.environments.put(map.getFileName(), env);
}
Game.loadEnvironment(this.environments.get(map.getFileName()));
Program.updateScrollBars();
EditorScreen.instance().getMapSelectionPanel().setSelection(map.getFileName());
if (this.selectedLayers.containsKey(map.getFileName())) {
EditorScreen.instance().getMapSelectionPanel().selectLayer(this.selectedLayers.get(map.getFileName()));
}
EditorScreen.instance().getMapObjectPanel().bind(this.getFocusedMapObject());
for (Consumer<Map> cons : this.mapLoadedConsumer) {
cons.accept(map);
}
} finally {
this.loading = false;
}
}
Aggregations