A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Map: touchscreens drag, pinch and tap the map (#999)
agamrafaeli-instinct6c78b41863b4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 98a3263a1..52aa29e21 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -121,6 +121,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBto 9 doubling from 1,000 people, at every zoom, at the start of the name and mirrored in Hebrew (owner, 18 October 2026,"Accept as shipped"). Rosh Pinna keeps tier 1 from its May 1948 figure of 350, which the data marks `wikipedia-only`("Keep tier 1 from 350"). Nothing changes in the game; EditMode tests pin both rulings (#710).+- Touchscreens play the map directly: one finger drags it, a pinch zooms it (100 px to the wheel notch, the touchpad's+ rate), and a tap selects its hex when the finger is released, so a drag never selects by accident. The mouse's controls+ are unchanged.- The 52 `owner_verify` flags on the 1948 localities are cleared (owner, 18 October 2026, "all defaults"), since #488checked every row against the Village Statistics 1945 scan and #490 applied the corrections. No other field changes.Open from #488, not touched here: the six split-or-merge rows, Dayr al-Qassi's landmark, 'Ilut. The localities arediff --git a/unity/Assets/Scripts/Map/CameraController.cs b/unity/Assets/Scripts/Map/CameraController.csindex ec9d77f01..8f7ebd32b 100644--- a/unity/Assets/Scripts/Map/CameraController.cs+++ b/unity/Assets/Scripts/Map/CameraController.cs@@ -16,7 +16,8 @@ namespace Statecraft.Game.Mappublic bool DragFromUi;}- /// <summary>Pans, zooms and orbits the diorama camera from the project-wide "Camera" action map (Input System only).+ /// <summary>Pans, zooms and orbits the diorama camera from the project-wide "Camera" action map (Input System only),+ /// and from the touchscreen: one finger drags like the right button, a pinch zooms like the wheel./// While the pointer is over the UI (IsOverUi, wired by the scene) the wheel and the drag belong to the UI; keyboard pan/// and orbit still move the camera (plan amendment A4). Pan speed scales with/// distance, zoom is clamped to [MinDistance, MaxDistance], and the view stays on the map (issue #174): the look-at@@ -96,8 +97,54 @@ namespace Statecraft.Game.Mapif (pan == null || dragPan == null || zoom == null || orbit == null) return;Vector2? pointer = Pointer.current != null ? Pointer.current.position.ReadValue() : (Vector2?)null;var down = Mouse.current != null && Mouse.current.rightButton.isPressed;- Step(rig, Gather(pan.ReadValue<Vector2>(), dragPan.ReadValue<Vector2>(), WheelOr(zoom.ReadValue<float>()),- orbit.ReadValue<float>(), down, pointer), ClampDt(Time.unscaledDeltaTime), Bounds, Ground, GroundTop);+ var drag = dragPan.ReadValue<Vector2>();+ var zoomRaw = WheelOr(zoom.ReadValue<float>());+ var ts = Touchscreen.current;+ if (ts != null)+ {+ switch (FingersDown(ts, out var a, out var b))+ {+ // one finger drags the map, like the right button: Gather's latch answers whether it started over the UI+ case 1:+ drag += a.delta.ReadValue();+ down = true;+ pointer = a.position.ReadValue();+ break;+ // a pinch zooms by how far the fingers move; the UI check follows the first finger+ case 2:+ zoomRaw += PinchNotches(a.position.ReadValue(), a.delta.ReadValue(), b.position.ReadValue(), b.delta.ReadValue());+ pointer = a.position.ReadValue();+ break;+ }+ }+ Step(rig, Gather(pan.ReadValue<Vector2>(), drag, zoomRaw, orbit.ReadValue<float>(), down, pointer),+ ClampDt(Time.unscaledDeltaTime), Bounds, Ground, GroundTop);+ }++ /// <summary>The first two touches down (2 stands for two or more), or fewer.</summary>+ static int FingersDown(Touchscreen ts, out UnityEngine.InputSystem.Controls.TouchControl a,+ out UnityEngine.InputSystem.Controls.TouchControl b)+ {+ a = null!; b = null!;+ int n = 0;+ foreach (var t in ts.touches)+ {+ if (!t.press.isPressed) continue;+ if (n == 0) a = t; else b = t;+ n++;+ if (n == 2) break;+ }+ return n;+ }++ /// <summary>A two-finger pinch in wheel notches, positive = in (the fingers spread): the change in the distance+ /// between them this frame, 100 px to the notch (PixelsPerNotch, the touchpad's rate). A finger's position one+ /// event ago is its position minus its delta.</summary>+ public static float PinchNotches(Vector2 now0, Vector2 delta0, Vector2 now1, Vector2 delta1)+ {+ var now = Vector2.Distance(now0, now1);+ var was = Vector2.Distance(now0 - delta0, now1 - delta1);+ return (now - was) / PixelsPerNotch;}/// <summary>Fits the rig's current pose with no input (review B-m3: a minimap jump goes through the same view fit anddiff --git a/unity/Assets/Scripts/Map/MapPointer.cs b/unity/Assets/Scripts/Map/MapPointer.csindex 9d317466f..7561c9ac7 100644--- a/unity/Assets/Scripts/Map/MapPointer.cs+++ b/unity/Assets/Scripts/Map/MapPointer.cs@@ -6,8 +6,35 @@ using UnityEngine.InputSystem;namespace Statecraft.Game.Map{+ /// <summary>The tap rule, with no devices: a finger becomes a tap only when it lifts within+ /// <see cref="SlopPixels"/> of where it landed and no second finger was down while it was held. A moved finger+ /// drags the camera and two fingers pinch (CameraController), so neither may also select a hex.</summary>+ public struct TapPress+ {+ /// <summary>How far the finger may wander, in screen pixels, before the press stops being a tap (about+ /// Android's 8 dp touch slop at 3x).</summary>+ public const float SlopPixels = 30f;++ Vector2 start;+ bool down, moved, pinched;++ /// <summary>One frame of the watched finger: its pressed and released edges, where it is, and whether any+ /// other finger is down. The tap's position on a release frame that still qualifies, otherwise null.</summary>+ public Vector2? Step(bool pressed, bool released, Vector2 position, bool otherFingerDown)+ {+ if (pressed) { start = position; down = true; moved = false; pinched = false; }+ if (!down) return null;+ if (otherFingerDown) pinched = true; // a pinch is never a tap, even a still thumb+ if ((position - start).sqrMagnitude > SlopPixels * SlopPixels) moved = true; // latched: coming back helps not+ if (!released) return null;+ down = false;+ return moved || pinched ? (Vector2?)null : start;+ }+ }+/// <summary>Left click on the map (not on the UI) selects the hex under the pointer: a ray from the camera hits the- /// terrain's collider, the hit becomes lon/lat (GeoFrame) and then a hex (HexPicker).</summary>+ /// terrain's collider, the hit becomes lon/lat (GeoFrame) and then a hex (HexPicker). On a touchscreen a tap (press and+ /// release inside TapPress.SlopPixels, with no second finger down) does the same, so a one-finger drag pans and a pinch zooms without selecting.</summary>public sealed class MapPointer : MonoBehaviour{public MapScene? Map;@@ -20,6 +47,8 @@ namespace Statecraft.Game.Mapreadonly Queue<Vector2> presses = new Queue<Vector2>();InputAction? press;+ TapPress tap;+void OnEnable(){press = new InputAction("map-press", InputActionType.Button, "<Mouse>/leftButton");@@ -47,7 +76,20 @@ namespace Statecraft.Game.Mapwhile (presses.Count > 0) HandleClick(presses.Dequeue());}- void Update() => ProcessPresses();+ void Update()+ {+ ProcessPresses();+ var ts = Touchscreen.current;+ if (ts == null) return;+ var t = ts.primaryTouch;+ var pressed = 0;+ foreach (var touch in ts.touches)+ if (touch.press.isPressed) pressed++;+ // any other finger down cancels the tap (TapPress): a releasing pinch's thumb is inside the slop, yet must not select+ var tapAt = tap.Step(t.press.wasPressedThisFrame, t.press.wasReleasedThisFrame,+ t.position.ReadValue(), pressed > (t.press.isPressed ? 1 : 0));+ if (tapAt.HasValue) OnPress(tapAt.Value); // a tap selects where the finger landed, like a click+ }/// <summary>A left click at <paramref name="pos"/> (screen pixels): ignored over the UI (the same IsOverUi the camera/// uses), otherwise the hex under the pointer is raised as HexClicked. Returns whether a hex was picked.</summary>diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.csindex 994a42f62..3de69b88e 100644--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs@@ -48,6 +48,18 @@ public class CameraInputTestsAssert.IsNotNull(asset.FindActionMap("UI", true).FindAction("Click"), "UI Toolkit needs the UI map's actions");}+ [Test]+ public void APinchZoomsByTheFingersDistanceAtTheTouchpadRate()+ {+ // the fingers spread 100 px in one frame: one notch in (PixelsPerNotch, the touchpad's rate)+ Assert.AreEqual(1f, CameraController.PinchNotches(new Vector2(0, 0), Vector2.zero, new Vector2(200, 0), new Vector2(100, 0)), 1e-4);+ // they close 100 px: one notch out+ Assert.AreEqual(-1f, CameraController.PinchNotches(new Vector2(0, 0), Vector2.zero, new Vector2(100, 0), new Vector2(-100, 0)), 1e-4);+ // both fingers still (or moving together, the distance unchanged): no zoom+ Assert.AreEqual(0f, CameraController.PinchNotches(new Vector2(0, 0), Vector2.zero, new Vector2(100, 0), Vector2.zero), 1e-4);+ Assert.AreEqual(0f, CameraController.PinchNotches(new Vector2(50, 0), new Vector2(10, 0), new Vector2(160, 0), new Vector2(10, 0)), 1e-4);+ }+[Test]public void PanMovesTheLookAtNorthAtYawZero(){diff --git a/unity/Assets/Tests/EditMode/MapPressTests.cs b/unity/Assets/Tests/EditMode/MapPressTests.csindex e777982d9..f13b034e7 100644--- a/unity/Assets/Tests/EditMode/MapPressTests.cs+++ b/unity/Assets/Tests/EditMode/MapPressTests.cs@@ -28,4 +28,43 @@ public class MapPressTests}finally { Object.DestroyImmediate(go); }}++ /// <summary>Review of the touchscreen tap rule: a press released inside the slop is a tap, at where the finger landed.</summary>+ [Test]+ public void ATapSelectsWhereTheFingerLanded()+ {+ var tap = new TapPress();+ Assert.IsNull(tap.Step(true, false, new Vector2(1150, 501), false), "nothing while the finger is down");+ Assert.AreEqual((Vector2?)new Vector2(1150, 501), tap.Step(false, true, new Vector2(1152, 500), false),+ "a 2-pixel wiggle is still a tap, and it selects where the finger landed");+ }++ /// <summary>A finger that wanders past the slop drags the camera and never selects - even if it comes back.</summary>+ [Test]+ public void ADragIsNeverATapEvenOneThatComesBack()+ {+ var tap = new TapPress();+ tap.Step(true, false, new Vector2(400, 400), false);+ tap.Step(false, false, new Vector2(600, 400), false); // far past the slop+ Assert.IsNull(tap.Step(false, true, new Vector2(401, 399), false), "back at the start is still a drag");+ }++ /// <summary>A pinch is never a tap: with the thumb held still, lifting it after the other finger spread must not select.</summary>+ [Test]+ public void APinchIsNeverATapEvenWithOneFingerHeldStill()+ {+ var tap = new TapPress();+ tap.Step(true, false, new Vector2(1150, 501), false); // the thumb lands+ tap.Step(false, false, new Vector2(1150, 501), true); // a second finger goes down; the thumb stays put+ Assert.IsNull(tap.Step(false, true, new Vector2(1150, 501), true), "lifting the thumb after a pinch is not a tap");+ }++ /// <summary>A finger that goes down only after the watched one lifted changes nothing.</summary>+ [Test]+ public void ASecondFingerAfterTheTapChangesNothing()+ {+ var tap = new TapPress();+ tap.Step(true, false, new Vector2(300, 300), false);+ Assert.AreEqual((Vector2?)new Vector2(300, 300), tap.Step(false, true, new Vector2(300, 300), false));+ }}