Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Camera: the opening keeps Tel Aviv and Jaffa on screen at every aspect (Refs #2370) (#2407)

Eyal Golan898ff701fccf
diff --git a/changelog.d/opening-both-cities.md b/changelog.d/opening-both-cities.md
new file mode 100644
index 000000000..b3b6390cd
--- /dev/null
+++ b/changelog.d/opening-both-cities.md
@@ -0,0 +1 @@
+- On a phone held upright, the opening view now shows Jaffa as well as Tel Aviv (Refs #2370).
diff --git a/unity/Assets/Scripts/Map/CameraRig.cs b/unity/Assets/Scripts/Map/CameraRig.cs
index 56f8866bf..9b5b21290 100644
--- a/unity/Assets/Scripts/Map/CameraRig.cs
+++ b/unity/Assets/Scripts/Map/CameraRig.cs
@@ -18,13 +18,11 @@ namespace Statecraft.Game.Map
/// a 16:9 view grows wider than the map and CameraController centres it (issue #1062: at 120 km the map could not be
/// panned left or right). The whole country is the minimap's whole-map button (CameraController.MaxDistance).</summary>
public const float StartDistance = 31000f;
- /// <summary>The opening look-at (MapScene.Build): Tel Aviv and Jaffa near the middle of the view. The latitude is the
- /// midpoint of Tel Aviv (32.08N) and Jaffa (32.0522N), content/map/settlements_1948.yaml:32 and :46. The longitude is
- /// Jaffa's (34.7531E, :45) moved inland by a sixth of the 16:9 view's width at StartDistance (34.75 km / 6 = 5.79 km,
- /// 0.0614 degrees at this latitude), so Jaffa sits at the left edge of the middle third and Tel Aviv (34.78E, :31) about
- /// 3 km left of the middle, without half the view being sea. TopInset already puts the look-at in the middle of the
- /// map area below the top bar.</summary>
+ /// <summary>The 16:9 reference for the aspect-aware opening look-at (<see cref="OpeningLookAt"/>). Its latitude is the
+ /// midpoint of Tel Aviv and Jaffa; its longitude puts Jaffa at the left edge of the middle third without half the view
+ /// being sea. Both places themselves come from settlements_1948.yaml, rather than these reference coordinates.</summary>
public const double StartLon = 34.8145, StartLat = 32.0661;
+ public const float OpeningReferenceAspect = 16f / 9f;
public Vector3 LookAt; public float Distance = StartDistance; public float Yaw;
/// <summary>Share of the screen height (0..1) the UI covers at the top. The view is shifted so LookAt sits in the
/// middle of the map area below it (an off-centre frustum: picking rays and WorldToScreenPoint follow it).</summary>
@@ -46,6 +44,22 @@ namespace Statecraft.Game.Map
/// running). A seam: the integration test forces the web tier's answer in the editor.</summary>
internal static Func<bool> FallbackWanted = QualityFallback.Wanted;
+ /// <summary>Keeps the 16:9 opening unchanged and scales Jaffa's eastward look-at offset with the real viewport width,
+ /// so Tel Aviv and Jaffa remain in frame on portrait screens too. A WebGL page opened in a background tab can boot with a
+ /// 0-size canvas, so an aspect that is not a positive finite number falls back to today's 16:9 look-at instead of
+ /// failing the map boot.</summary>
+ public static Vector3 OpeningLookAt(GeoFrame frame, float aspect, Settlement telAviv, Settlement jaffa)
+ {
+ if (telAviv == null) throw new ArgumentNullException(nameof(telAviv));
+ if (jaffa == null) throw new ArgumentNullException(nameof(jaffa));
+ if (!(aspect > 0f) || !float.IsFinite(aspect)) return frame.ToWorld(StartLon, StartLat, 0f);
+ var telAvivWorld = frame.ToWorld(telAviv.Lon, telAviv.Lat, 0f);
+ var jaffaWorld = frame.ToWorld(jaffa.Lon, jaffa.Lat, 0f);
+ var reference = frame.ToWorld(StartLon, StartLat, 0f);
+ float x = jaffaWorld.x + (reference.x - jaffaWorld.x) * aspect / OpeningReferenceAspect;
+ return new Vector3(x, 0f, (telAvivWorld.z + jaffaWorld.z) * 0.5f);
+ }
+
public void Init()
{
// Undo actions an earlier Init left behind (Init called outside MapScene.Build) run now instead of piling up.
diff --git a/unity/Assets/Scripts/Map/FrameProfile.cs b/unity/Assets/Scripts/Map/FrameProfile.cs
index ec7a5cb4d..797148a30 100644
--- a/unity/Assets/Scripts/Map/FrameProfile.cs
+++ b/unity/Assets/Scripts/Map/FrameProfile.cs
@@ -94,8 +94,8 @@ namespace Statecraft.Game.Map
// meets the building models first.
if (CloseRequested())
{
- poses.AddRange(PromoPose.CloseUps);
poses.Add(new PromoPose("opening", CameraRig.StartLon, CameraRig.StartLat, CameraRig.StartDistance, 0f));
+ poses.AddRange(PromoPose.CloseUps);
}
foreach (var pose in poses)
{
diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.cs
index 1c2248744..5cf965d51 100644
--- a/unity/Assets/Scripts/Map/MapScene.cs
+++ b/unity/Assets/Scripts/Map/MapScene.cs
@@ -861,9 +861,10 @@ namespace Statecraft.Game.Map
}
if (!cam.TryGetComponent(out CameraRig rig)) rig = cam.gameObject.AddComponent<CameraRig>();
- // The opening: Tel Aviv and Jaffa near the middle (CameraRig.StartLon/StartLat) at CameraRig.StartDistance (owner,
- // 3 November 2026: "Open at ~30 km, like the promo").
- rig.LookAt = Frame.ToWorld(CameraRig.StartLon, CameraRig.StartLat, 0); rig.Init();
+ // The opening: Tel Aviv and Jaffa both in frame at CameraRig.StartDistance, including on a phone held upright
+ // (owner, 3 November 2026: "Open at ~30 km, like the promo").
+ var telAviv = list.Single(s => s.Id == "tel_aviv"); var jaffa = list.Single(s => s.Id == "jaffa");
+ rig.LookAt = CameraRig.OpeningLookAt(Frame, cam.aspect, telAviv, jaffa); rig.Init();
rig.Volume.transform.SetParent(transform, true);
// VolumeProfile's own teardown only releases its components, it does not destroy them (Core RP 17.3), so own both.
var assets = terrainGo.GetComponent<MapRuntimeAssets>();
diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.cs
index 05711fdf9..f5fccac51 100644
--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs
+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs
@@ -415,7 +415,9 @@ public class CameraInputTests
float start = CameraRig.StartDistance;
Assert.That(start, Is.InRange(25000f, 35000f), "about 30 km (owner, 3 November 2026)");
Assert.IsTrue(Statecraft.Game.Map.Kits.TownModelLayer.CloseAt(start, null), "the building models draw at the opening");
- Assert.GreaterOrEqual(Mathf.Abs(start - Statecraft.Game.Map.Routes.RoadVehicles.CloseEnterM), 500f, "not on the road vehicles' edge");
+ Assert.GreaterOrEqual(start, Statecraft.Game.Map.Routes.RoadVehicles.CloseEnterM + 1000f, "1 km beyond the road vehicles' enter edge");
+ Assert.GreaterOrEqual(start, Statecraft.Game.Map.Collection.ProductionResidency.Approved().Units.ViewEnterM + 1000f,
+ "1 km beyond the collection layers' enter edge");
Assert.Less(start, CameraController.MaxDistance, "the whole-map zoom is farther out");
}
diff --git a/unity/Assets/Tests/EditMode/OpeningTests.cs b/unity/Assets/Tests/EditMode/OpeningTests.cs
index 47943d423..de10b0793 100644
--- a/unity/Assets/Tests/EditMode/OpeningTests.cs
+++ b/unity/Assets/Tests/EditMode/OpeningTests.cs
@@ -33,6 +33,54 @@ public class OpeningTests
saveDirectory = null;
}
+ /// <summary>The map's real opening keeps both neighbouring cities at least 5% inside every supported phone and desktop
+ /// shape. The points come from the content MapScene just built, so this follows a sourced coordinate change.</summary>
+ [TestCase(390, 844)]
+ [TestCase(375, 667)]
+ [TestCase(900, 1600)]
+ [TestCase(1600, 900)]
+ [TestCase(2100, 900)]
+ public void TheOpeningKeepsTelAvivAndJaffaInsideTheScreen(int width, int height)
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ // A target of the screen's size gives the camera that pixel rect and aspect (pixelRect's setter divides by the editor's
+ // own screen size, which a batch run does not fix).
+ var camera = Camera.main; var target = new RenderTexture(width, height, 24);
+ try
+ {
+ camera.targetTexture = target; camera.aspect = (float)width / height;
+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build(Inputs.Map);
+ const float margin = 0.05f;
+ foreach (var id in new[] { "tel_aviv", "jaffa" })
+ {
+ var place = map.Settlements.Single(s => s.Id == id);
+ var screen = camera.WorldToScreenPoint(map.Frame.ToWorld(place.Lon, place.Lat, 0f));
+ Assert.Greater(screen.z, 0f, $"{width}x{height}: {id} is in front of the camera");
+ Assert.That(screen.x, Is.InRange(width * margin, width * (1f - margin)), $"{width}x{height}: {id} x");
+ Assert.That(screen.y, Is.InRange(height * margin, height * (1f - margin)), $"{width}x{height}: {id} y");
+ }
+ }
+ finally { camera.targetTexture = null; target.Release(); Object.DestroyImmediate(target); }
+ }
+
+ /// <summary>A 0-size canvas (a WebGL page booted in a background tab) gives no usable aspect: the opening falls back to
+ /// today's 16:9 look-at, the reference point itself, instead of throwing and failing the map boot.</summary>
+ [TestCase(0f)]
+ [TestCase(-1f)]
+ [TestCase(float.NaN)]
+ [TestCase(float.PositiveInfinity)]
+ [TestCase(float.NegativeInfinity)]
+ public void AnUnusableAspectFallsBackToTheSixteenByNineOpening(float aspect)
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>(); map.Build(Inputs.Map);
+ var telAviv = map.Settlements.Single(s => s.Id == "tel_aviv");
+ var jaffa = map.Settlements.Single(s => s.Id == "jaffa");
+ Vector3 lookAt = default;
+ Assert.DoesNotThrow(() => lookAt = CameraRig.OpeningLookAt(map.Frame, aspect, telAviv, jaffa), $"aspect {aspect}");
+ Assert.AreEqual(map.Frame.ToWorld(CameraRig.StartLon, CameraRig.StartLat, 0f), lookAt, $"aspect {aspect}");
+ }
+
[UnityTest]
public IEnumerator CanBeSkippedAndReplayed()
{