From ddb11527651f1498599a13fb5f17d4e226581647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 9 Jul 2017 18:31:18 +0200 Subject: [PATCH] map: Zoom-out now includes all next-jump accessible star systems --- src/ui/map/UniverseMapView.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ui/map/UniverseMapView.ts b/src/ui/map/UniverseMapView.ts index 3b7a5fc..18bb8be 100644 --- a/src/ui/map/UniverseMapView.ts +++ b/src/ui/map/UniverseMapView.ts @@ -204,6 +204,19 @@ module TS.SpaceTac.UI { this.tweens.create(this.layer_universe.scale).to({ x: scale, y: scale }, duration, easing).start(); } + /** + * Set the camera to include all direct-jump accessible stars + */ + setCameraOnAccessible(star: Star) { + let accessible = star.getNeighbors(); + let xmin = min(accessible.map(star => star.x)); + let xmax = max(accessible.map(star => star.x)); + let ymin = min(accessible.map(star => star.y)); + let ymax = max(accessible.map(star => star.y)); + let dmax = Math.max(xmax - xmin, ymax - ymin); + this.setCamera(xmin + (xmax - xmin) * 0.5, ymin + (ymax - ymin) * 0.5, dmax * 1.1); + } + /** * Set the alpha value for all links */ @@ -221,8 +234,7 @@ module TS.SpaceTac.UI { this.setLinksAlpha(1); this.zoom = 0; } else if (level == 1) { - // TODO Zoom to next-jump accessible - this.setCamera(current_star.x, current_star.y, this.universe.radius * 0.5); + this.setCameraOnAccessible(current_star); this.setLinksAlpha(0.6); this.zoom = 1; } else {