Search in sources :

Example 1 with Environment

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;
    }
}
Also used : Point2D(java.awt.geom.Point2D) IEnvironment(de.gurkenlabs.litiengine.environment.IEnvironment) Environment(de.gurkenlabs.litiengine.environment.Environment) Map(de.gurkenlabs.litiengine.environment.tilemap.xml.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IMap(de.gurkenlabs.litiengine.environment.tilemap.IMap)

Aggregations

Environment (de.gurkenlabs.litiengine.environment.Environment)1 IEnvironment (de.gurkenlabs.litiengine.environment.IEnvironment)1 IMap (de.gurkenlabs.litiengine.environment.tilemap.IMap)1 Map (de.gurkenlabs.litiengine.environment.tilemap.xml.Map)1 Point2D (java.awt.geom.Point2D)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1