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.

feat(unity): wire the boot scene (map, UI, camera, saves) and a scripted 5-turn smoke test

eyalgolanbb86343ab730
diff --git a/unity/Assets/Editor/MapCapture.cs b/unity/Assets/Editor/MapCapture.cs
index 3e2ec1179..c4b47f43f 100644
--- a/unity/Assets/Editor/MapCapture.cs
+++ b/unity/Assets/Editor/MapCapture.cs
@@ -1,10 +1,13 @@
using System.IO;
using Statecraft.Game;
using Statecraft.Game.EditorTools;
+using Statecraft.Game.Boot;
using Statecraft.Game.Map;
+using Statecraft.Game.UI;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
+using UnityEngine.UIElements;
/// <summary>Editor capture tools. Run headless (with graphics, not -nographics):
/// Unity -batchmode -quit -projectPath unity -executeMethod MapCapture.TopDown (or MapCapture.Flythrough).
@@ -15,18 +18,38 @@ public static class MapCapture
static string CaptureDir => Path.Combine(Paths.RepoRoot, "captures");
- /// <summary>Creates and saves Assets/Map.unity: default camera and light, a MapScene wired to the material assets, and
- /// the GameBoot that loads the inputs and builds the map in play mode and in players.</summary>
+ /// <summary>Creates and saves Assets/Map.unity, the boot scene: the default camera (with CameraRig and
+ /// CameraController) and light, a MapScene wired to the material assets, the GameBoot that loads the inputs and builds
+ /// the map in play mode and in players, the placement layer, the map pointer, and the UI document with GameRoot wired
+ /// to all of them. No EventSystem: UI Toolkit reads the Input System directly.</summary>
public static void MakeScene()
{
MapMaterials.Create();
+ UiAssets.Create();
var scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
+ var controller = Camera.main.gameObject.AddComponent<CameraController>(); // adds the CameraRig it requires
var map = new GameObject("MapScene").AddComponent<MapScene>();
map.Configure(Load(MapMaterials.TerrainPath), Load(MapMaterials.OverlayPath), Load(MapMaterials.MarkerPath));
- new GameObject("Boot").AddComponent<Statecraft.Game.Boot.GameBoot>().Configure(map);
+ var boot = new GameObject("Boot").AddComponent<GameBoot>();
+ boot.Configure(map);
+ var placements = new GameObject("Placements").AddComponent<PlacementLayer>();
+ var pointer = new GameObject("MapPointer").AddComponent<MapPointer>();
+ var ui = new GameObject("UI");
+ var doc = ui.AddComponent<UIDocument>();
+ doc.panelSettings = Asset<PanelSettings>(UiPaths.Panel);
+ doc.visualTreeAsset = Asset<VisualTreeAsset>(UiPaths.GameUxml);
+ ui.AddComponent<GameRoot>().Configure(boot, doc, Asset<TextAsset>(UiPaths.Strings),
+ Asset<PortraitCatalog>(PortraitImport.CatalogPath), map, placements, pointer, controller);
EditorSceneManager.SaveScene(scene, ScenePath);
}
+ static T Asset<T>(string path) where T : Object
+ {
+ var a = AssetDatabase.LoadAssetAtPath<T>(path);
+ if (a == null) throw new FileNotFoundException($"{typeof(T).Name} asset missing", path);
+ return a;
+ }
+
/// <summary>Opens Assets/Map.unity (creating it only when missing) and builds the map in memory. The scene is not
/// saved, so captures leave it unchanged.</summary>
static MapScene OpenAndBuild()
diff --git a/unity/Assets/Map.unity b/unity/Assets/Map.unity
index 911034c94..d62ebe13f 100644
--- a/unity/Assets/Map.unity
+++ b/unity/Assets/Map.unity
@@ -119,7 +119,7 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
---- !u!1 &1171856989
+--- !u!1 &25003449
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -127,8 +127,105 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- - component: {fileID: 1171856991}
- - component: {fileID: 1171856990}
+ - component: {fileID: 25003451}
+ - component: {fileID: 25003450}
+ m_Layer: 0
+ m_Name: Directional Light
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!108 &25003450
+Light:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 25003449}
+ m_Enabled: 1
+ serializedVersion: 12
+ m_Type: 1
+ m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
+ m_Intensity: 1
+ m_Range: 10
+ m_SpotAngle: 30
+ m_InnerSpotAngle: 21.80208
+ m_CookieSize2D: {x: 0.5, y: 0.5}
+ m_Shadows:
+ m_Type: 2
+ m_Resolution: -1
+ m_CustomResolution: -1
+ m_Strength: 1
+ m_Bias: 0.05
+ m_NormalBias: 0.4
+ m_NearPlane: 0.2
+ m_CullingMatrixOverride:
+ e00: 1
+ e01: 0
+ e02: 0
+ e03: 0
+ e10: 0
+ e11: 1
+ e12: 0
+ e13: 0
+ e20: 0
+ e21: 0
+ e22: 1
+ e23: 0
+ e30: 0
+ e31: 0
+ e32: 0
+ e33: 1
+ m_UseCullingMatrixOverride: 0
+ m_Cookie: {fileID: 0}
+ m_DrawHalo: 0
+ m_Flare: {fileID: 0}
+ m_RenderMode: 0
+ m_CullingMask:
+ serializedVersion: 2
+ m_Bits: 4294967295
+ m_RenderingLayerMask: 1
+ m_Lightmapping: 4
+ m_LightShadowCasterMode: 0
+ m_AreaSize: {x: 1, y: 1}
+ m_BounceIntensity: 1
+ m_ColorTemperature: 6570
+ m_UseColorTemperature: 0
+ m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
+ m_UseBoundingSphereOverride: 0
+ m_UseViewFrustumForShadowCasterCull: 1
+ m_ForceVisible: 0
+ m_ShadowRadius: 0
+ m_ShadowAngle: 0
+ m_LightUnit: 1
+ m_LuxAtDistance: 1
+ m_EnableSpotReflector: 1
+--- !u!4 &25003451
+Transform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 25003449}
+ serializedVersion: 2
+ m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
+ m_LocalPosition: {x: 0, y: 3, z: 0}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_ConstrainProportionsScale: 0
+ m_Children: []
+ m_Father: {fileID: 0}
+ m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
+--- !u!1 &309119766
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 309119768}
+ - component: {fileID: 309119767}
m_Layer: 0
m_Name: Boot
m_TagString: Untagged
@@ -136,26 +233,26 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
---- !u!114 &1171856990
+--- !u!114 &309119767
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1171856989}
+ m_GameObject: {fileID: 309119766}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9dba4dacfc46b405a9260a42b3b83be4, type: 3}
m_Name:
m_EditorClassIdentifier: Statecraft.Game::Statecraft.Game.Boot.GameBoot
- map: {fileID: 1239438371}
---- !u!4 &1171856991
+ map: {fileID: 1195372452}
+--- !u!4 &309119768
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1171856989}
+ m_GameObject: {fileID: 309119766}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
@@ -164,7 +261,7 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
---- !u!1 &1239438370
+--- !u!1 &1128708371
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -172,8 +269,97 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- - component: {fileID: 1239438372}
- - component: {fileID: 1239438371}
+ - component: {fileID: 1128708373}
+ - component: {fileID: 1128708372}
+ m_Layer: 0
+ m_Name: Placements
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!114 &1128708372
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1128708371}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 694c57321f1ae42bfb78c05a3a7bfec4, type: 3}
+ m_Name:
+ m_EditorClassIdentifier: Statecraft.Game::Statecraft.Game.Map.PlacementLayer
+--- !u!4 &1128708373
+Transform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1128708371}
+ serializedVersion: 2
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalPosition: {x: 0, y: 0, z: 0}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_ConstrainProportionsScale: 0
+ m_Children: []
+ m_Father: {fileID: 0}
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &1139850907
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 1139850909}
+ - component: {fileID: 1139850908}
+ m_Layer: 0
+ m_Name: MapPointer
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!114 &1139850908
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1139850907}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 8a2034f54e4284ead9e1f04deab25e8d, type: 3}
+ m_Name:
+ m_EditorClassIdentifier: Statecraft.Game::Statecraft.Game.Map.MapPointer
+ Map: {fileID: 0}
+--- !u!4 &1139850909
+Transform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1139850907}
+ serializedVersion: 2
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalPosition: {x: 0, y: 0, z: 0}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_ConstrainProportionsScale: 0
+ m_Children: []
+ m_Father: {fileID: 0}
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &1195372451
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 1195372453}
+ - component: {fileID: 1195372452}
m_Layer: 0
m_Name: MapScene
m_TagString: Untagged
@@ -181,13 +367,13 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
---- !u!114 &1239438371
+--- !u!114 &1195372452
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1239438370}
+ m_GameObject: {fileID: 1195372451}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f7b27c26d62c5400c99c12b492a87a6d, type: 3}
@@ -196,13 +382,13 @@ MonoBehaviour:
terrainMaterial: {fileID: 2100000, guid: fc63b910005e64adaaa42ba488bcc248, type: 2}
overlayMaterial: {fileID: 2100000, guid: 29dd83b7b3b1f4a4aa5a710be0078164, type: 2}
markerMaterial: {fileID: 2100000, guid: 7c65bbd4355344f1990495c458323a4e, type: 2}
---- !u!4 &1239438372
+--- !u!4 &1195372453
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1239438370}
+ m_GameObject: {fileID: 1195372451}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
@@ -211,7 +397,7 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
---- !u!1 &1924070566
+--- !u!1 &1912926280
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -219,9 +405,87 @@ GameObject:
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- - component: {fileID: 1924070569}
- - component: {fileID: 1924070568}
- - component: {fileID: 1924070567}
+ - component: {fileID: 1912926283}
+ - component: {fileID: 1912926282}
+ - component: {fileID: 1912926281}
+ m_Layer: 0
+ m_Name: UI
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!114 &1912926281
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1912926280}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 63fdca1f33b5645bf903ae90525be959, type: 3}
+ m_Name:
+ m_EditorClassIdentifier: Statecraft.Game::Statecraft.Game.UI.GameRoot
+ boot: {fileID: 309119767}
+ document: {fileID: 1912926282}
+ strings: {fileID: 4900000, guid: 1c2724b5422584e3dbeef4ab44d2e9da, type: 3}
+ portraits: {fileID: 11400000, guid: 57539449dae8640c6b6848f8c1e433ff, type: 2}
+ map: {fileID: 1195372452}
+ placements: {fileID: 1128708372}
+ pointer: {fileID: 1139850908}
+ cameraController: {fileID: 1996827301}
+--- !u!114 &1912926282
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1912926280}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
+ m_Name:
+ m_EditorClassIdentifier: UnityEngine.dll::UnityEngine.UIElements.UIDocument
+ m_PanelSettings: {fileID: 11400000, guid: dab47673b21ed48abbc80a9747465d73, type: 2}
+ m_ParentUI: {fileID: 0}
+ sourceAsset: {fileID: 9197481963319205126, guid: 40f0d74d627394577981d9875ae6489f, type: 3}
+ m_SortingOrder: 0
+ m_Position: 0
+ m_WorldSpaceSizeMode: 1
+ m_WorldSpaceWidth: 1920
+ m_WorldSpaceHeight: 1080
+ m_PivotReferenceSize: 0
+ m_Pivot: 0
+ m_WorldSpaceCollider: {fileID: 0}
+--- !u!4 &1912926283
+Transform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1912926280}
+ serializedVersion: 2
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalPosition: {x: 0, y: 0, z: 0}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_ConstrainProportionsScale: 0
+ m_Children: []
+ m_Father: {fileID: 0}
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &1996827300
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 1996827305}
+ - component: {fileID: 1996827304}
+ - component: {fileID: 1996827303}
+ - component: {fileID: 1996827302}
+ - component: {fileID: 1996827301}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@@ -229,21 +493,54 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
---- !u!81 &1924070567
+--- !u!114 &1996827301
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1996827300}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 882f31929dee34cf59c6f172c5f87054, type: 3}
+ m_Name:
+ m_EditorClassIdentifier: Statecraft.Game::Statecraft.Game.Map.CameraController
+ Bounds:
+ serializedVersion: 2
+ x: 0
+ y: 0
+ width: 3.4028235e+38
+ height: 3.4028235e+38
+--- !u!114 &1996827302
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 1996827300}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 301a816b1ac0344ff8b1506f93e21ed7, type: 3}
+ m_Name:
+ m_EditorClassIdentifier: Statecraft.Game::Statecraft.Game.Map.CameraRig
+ LookAt: {x: 0, y: 0, z: 0}
+ Distance: 120000
+ Yaw: 0
+--- !u!81 &1996827303
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1924070566}
+ m_GameObject: {fileID: 1996827300}
m_Enabled: 1
---- !u!20 &1924070568
+--- !u!20 &1996827304
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1924070566}
+ m_GameObject: {fileID: 1996827300}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
@@ -288,13 +585,13 @@ Camera:
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
---- !u!4 &1924070569
+--- !u!4 &1996827305
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1924070566}
+ m_GameObject: {fileID: 1996827300}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
@@ -303,108 +600,14 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
---- !u!1 &1964867373
-GameObject:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- serializedVersion: 6
- m_Component:
- - component: {fileID: 1964867375}
- - component: {fileID: 1964867374}
- m_Layer: 0
- m_Name: Directional Light
- m_TagString: Untagged
- m_Icon: {fileID: 0}
- m_NavMeshLayer: 0
- m_StaticEditorFlags: 0
- m_IsActive: 1
---- !u!108 &1964867374
-Light:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1964867373}
- m_Enabled: 1
- serializedVersion: 12
- m_Type: 1
- m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
- m_Intensity: 1
- m_Range: 10
- m_SpotAngle: 30
- m_InnerSpotAngle: 21.80208
- m_CookieSize2D: {x: 0.5, y: 0.5}
- m_Shadows:
- m_Type: 2
- m_Resolution: -1
- m_CustomResolution: -1
- m_Strength: 1
- m_Bias: 0.05
- m_NormalBias: 0.4
- m_NearPlane: 0.2
- m_CullingMatrixOverride:
- e00: 1
- e01: 0
- e02: 0
- e03: 0
- e10: 0
- e11: 1
- e12: 0
- e13: 0
- e20: 0
- e21: 0
- e22: 1
- e23: 0
- e30: 0
- e31: 0
- e32: 0
- e33: 1
- m_UseCullingMatrixOverride: 0
- m_Cookie: {fileID: 0}
- m_DrawHalo: 0
- m_Flare: {fileID: 0}
- m_RenderMode: 0
- m_CullingMask:
- serializedVersion: 2
- m_Bits: 4294967295
- m_RenderingLayerMask: 1
- m_Lightmapping: 4
- m_LightShadowCasterMode: 0
- m_AreaSize: {x: 1, y: 1}
- m_BounceIntensity: 1
- m_ColorTemperature: 6570
- m_UseColorTemperature: 0
- m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
- m_UseBoundingSphereOverride: 0
- m_UseViewFrustumForShadowCasterCull: 1
- m_ForceVisible: 0
- m_ShadowRadius: 0
- m_ShadowAngle: 0
- m_LightUnit: 1
- m_LuxAtDistance: 1
- m_EnableSpotReflector: 1
---- !u!4 &1964867375
-Transform:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 1964867373}
- serializedVersion: 2
- m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
- m_LocalPosition: {x: 0, y: 3, z: 0}
- m_LocalScale: {x: 1, y: 1, z: 1}
- m_ConstrainProportionsScale: 0
- m_Children: []
- m_Father: {fileID: 0}
- m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- - {fileID: 1924070569}
- - {fileID: 1964867375}
- - {fileID: 1239438372}
- - {fileID: 1171856991}
+ - {fileID: 1996827305}
+ - {fileID: 25003451}
+ - {fileID: 1195372453}
+ - {fileID: 309119768}
+ - {fileID: 1128708373}
+ - {fileID: 1139850909}
+ - {fileID: 1912926283}
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
new file mode 100644
index 000000000..3b72b66e2
--- /dev/null
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -0,0 +1,233 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using Statecraft.Game.Boot;
+using Statecraft.Game.Map;
+using Statecraft.Sim;
+using UnityEngine;
+using UnityEngine.UIElements;
+
+namespace Statecraft.Game.UI
+{
+ /// <summary>Starts the game once GameBoot has loaded the inputs and built the map (GameBoot.Ready): continues the
+ /// autosave or starts a new game (GameStart.Begin, with its notes in the toast), creates every screen, autosaves each
+ /// turn, and wires the camera and the map pointer to the game panel (UiPointer.IsOverUi), map clicks to the info panel,
+ /// the minimap to the camera, and State.Placements to the placement layer. Disabling it disposes all of that.
+ /// With "smoke" in the page URL (WebGL, e.g. ?smoke=5) or -smoke N (desktop) it starts a fresh game with the golden
+ /// seed (the player's autosave is neither read nor written), plays N turns through the UI's own buttons and logs
+ /// "SMOKE OK ..." (or "SMOKE FAIL ...").
+ /// ExecuteAlways only so that disabling it disposes the presenters in edit mode too (tests); GameBoot raises Ready
+ /// in play mode and players only.</summary>
+ [ExecuteAlways]
+ public sealed class GameRoot : MonoBehaviour
+ {
+ public const int DefaultSmokeTurns = 5;
+
+ [SerializeField] GameBoot boot = null!;
+ [SerializeField] UIDocument document = null!;
+ [SerializeField] TextAsset strings = null!;
+ [SerializeField] PortraitCatalog portraits = null!;
+ [SerializeField] MapScene map = null!;
+ [SerializeField] PlacementLayer placements = null!;
+ [SerializeField] MapPointer pointer = null!;
+ [SerializeField] CameraController cameraController = null!;
+
+ /// <summary>Everything Begin created that must be undone, disposed in reverse order.</summary>
+ readonly List<IDisposable> owned = new List<IDisposable>();
+ MinimapPresenter? minimap;
+ CameraRig? rig;
+ List<(string, int, int, DateTime)>? drawn;
+
+ public SimBridge? Bridge { get; private set; }
+ /// <summary>Where the autosave lives; null (the default) = SaveStore.ForPlatform(). Tests set a temporary folder.</summary>
+ public SaveStore? Store { get; set; }
+
+ public void Configure(GameBoot boot, UIDocument document, TextAsset strings, PortraitCatalog portraits, MapScene map,
+ PlacementLayer placements, MapPointer pointer, CameraController cameraController)
+ {
+ this.boot = boot; this.document = document; this.strings = strings; this.portraits = portraits; this.map = map;
+ this.placements = placements; this.pointer = pointer; this.cameraController = cameraController;
+ }
+
+ void OnEnable() { if (boot != null) boot.Ready += Begin; }
+
+ void OnDisable()
+ {
+ if (boot != null) boot.Ready -= Begin;
+ Shutdown();
+ }
+
+ /// <summary>Smoke-test turn count: from the page URL on WebGL ("?smoke=N", or "?smoke" for DefaultSmokeTurns; the flag
+ /// must start a query parameter and end at a word boundary, UrlFlags), else from the command line ("-smoke N").
+ /// 0 when not asked.</summary>
+ public static int SmokeTurns(string? url, string[] args, bool webgl)
+ {
+ if (webgl)
+ {
+ if (!UrlFlags.Has(url, "smoke")) return 0;
+ var n = UrlFlags.Int(url, "smoke");
+ return n > 0 ? n : DefaultSmokeTurns;
+ }
+ var i = Array.IndexOf(args, "-smoke");
+ return i >= 0 && i + 1 < args.Length && int.TryParse(args[i + 1], NumberStyles.None, CultureInfo.InvariantCulture, out var t) ? t : 0;
+ }
+
+ public static int SmokeTurns() =>
+ SmokeTurns(Application.absoluteURL, Environment.GetCommandLineArgs(), Application.platform == RuntimePlatform.WebGLPlayer);
+
+ /// <summary>GameBoot.Ready: starts the game, smoke-testing when the URL or command line asks.</summary>
+ public void Begin(GameInputs inputs) => Begin(inputs, SmokeTurns());
+
+ /// <summary>Starts (or restarts) the game over the built map. <paramref name="smoke"/> &gt; 0 plays that many turns.</summary>
+ public void Begin(GameInputs inputs, int smoke)
+ {
+ if (inputs == null) throw new ArgumentNullException(nameof(inputs));
+ foreach (var (value, field) in new (UnityEngine.Object?, string)[] { (document, nameof(document)), (strings, nameof(strings)),
+ (map, nameof(map)), (placements, nameof(placements)), (pointer, nameof(pointer)), (cameraController, nameof(cameraController)) })
+ if (value == null) throw new InvalidOperationException($"GameRoot: {field} is not assigned (run MapCapture.MakeScene)");
+ if (map.Terrain == null) throw new InvalidOperationException("GameRoot: the map is not built (GameBoot builds it before Ready)");
+ Shutdown();
+
+ var text = UiText.Parse(strings.text);
+ var store = Store ?? SaveStore.ForPlatform();
+ var notes = new List<string>();
+ // A smoke run is reproducible: a fresh game with the golden seed, never the player's autosave.
+ var session = smoke > 0
+ ? GameStart.Begin(inputs.Content, store, () => GoldenRun.Seed, notes, text, fresh: true)
+ : GameStart.Begin(inputs.Content, store, GameStart.NewSeed, notes, text);
+ var bridge = Bridge = new SimBridge(session, text);
+ var root = document.rootVisualElement;
+
+ // The toast first: the autosave (below) must report a failed write after the toast has shown the turn's refusals.
+ var toast = Own(new ToastPresenter(root, bridge, text));
+ Own(new HudPresenter(root, bridge, text));
+ Own(new ScreenNav(root)); // hides every screen: the USS has no display:none for them
+ var card = Own(new EventCardPresenter(root, bridge, text, portraits));
+ Own(new DefencePresenter(root, bridge, text));
+ Own(new BudgetPresenter(root, bridge, text));
+ Own(new WhyPresenter(root, bridge, text));
+ Own(new CabinetPresenter(root, bridge, text, portraits));
+ var names = SettlementPlacer.Parse(inputs.Map.SettlementsYaml).ToDictionary(s => s.Id, s => s.Name);
+ var info = Own(new InfoPanelPresenter(root, bridge, text, names));
+ Own(new NewGamePresenter(root, bridge, store, toast, text, GameStart.NewSeed));
+ if (smoke == 0) Own(GameStart.Autosave(bridge, store, text, toast.Show));
+
+ Func<Vector2, bool> overUi = p => UiPointer.IsOverUi(root.panel, p, Screen.height);
+ var terrain = map.Terrain;
+ var size = terrain.terrainData.size;
+ cameraController.IsOverUi = overUi;
+ cameraController.Bounds = new Rect(terrain.transform.position.x, terrain.transform.position.z, size.x, size.z);
+ pointer.Map = map;
+ pointer.IsOverUi = overUi;
+ Action<int, int> onHex = info.Show;
+ pointer.HexClicked += onHex;
+ var camRig = rig = cameraController.GetComponent<CameraRig>();
+ var mini = minimap = Own(new MinimapPresenter(root, map.Hexes));
+ mini.Clicked += (lon, lat) => { camRig.LookAt = map.Frame.ToWorld(lon, lat, 0); camRig.Apply(); SyncMinimap(); };
+ Action onChanged = RenderPlacementsIfChanged;
+ bridge.Changed += onChanged;
+ owned.Add(new Undo(() =>
+ {
+ bridge.Changed -= onChanged;
+ pointer.HexClicked -= onHex;
+ if (pointer.IsOverUi == overUi) pointer.IsOverUi = null;
+ if (cameraController.IsOverUi == overUi) cameraController.IsOverUi = null;
+ }));
+ drawn = null;
+ RenderPlacementsIfChanged();
+ SyncMinimap();
+
+ if (notes.Count > 0) toast.Show(notes);
+ Debug.Log(FormattableString.Invariant($"GAME OK {bridge.State.Date:yyyy-MM-dd} turn {bridge.State.Turn}"));
+ if (smoke > 0)
+ {
+ if (Application.isPlaying) StartCoroutine(Smoke(root, bridge, card, smoke, Debug.Log));
+ else Debug.LogWarning("SMOKE FAIL the smoke run needs play mode or a player");
+ }
+ }
+
+ T Own<T>(T d) where T : IDisposable { owned.Add(d); return d; }
+
+ /// <summary>Disposes every presenter, the autosave and the camera/pointer hooks (newest first). Safe to call twice.</summary>
+ void Shutdown()
+ {
+ StopAllCoroutines();
+ for (int i = owned.Count - 1; i >= 0; i--) owned[i].Dispose();
+ owned.Clear();
+ minimap = null; rig = null; drawn = null;
+ }
+
+ /// <summary>Draws the placements only when State.Placements differs from what was drawn (every order and every turn
+ /// raises Changed; rebuilding the markers each time would be wasted work).</summary>
+ void RenderPlacementsIfChanged()
+ {
+ if (Bridge == null) return;
+ var now = Bridge.State.Placements.Select(p => (p.Action, p.Q, p.R, p.Date)).ToList();
+ if (drawn != null && drawn.SequenceEqual(now)) return;
+ drawn = now;
+ placements.Render(Bridge.State.Placements, Bridge.Content, map);
+ }
+
+ void SyncMinimap()
+ {
+ if (minimap == null || rig == null) return;
+ minimap.SetView(map.Frame, rig.LookAt, rig.Distance);
+ }
+
+ void Update() => SyncMinimap();
+
+ /// <summary>Plays turns the way a player does: answers each open event by pressing the card's first option button,
+ /// then presses End Turn. Logs "SMOKE turn &lt;n&gt; &lt;date&gt; refused &lt;k&gt;" per turn through <paramref name="log"/>,
+ /// then "SMOKE OK &lt;n&gt; turns &lt;date&gt; &lt;hash&gt;", or "SMOKE FAIL &lt;reason&gt;" when a press does not take effect.
+ /// Static, so an edit-mode test can drive it step by step.</summary>
+ public static IEnumerator Smoke(VisualElement root, SimBridge bridge, EventCardPresenter card, int turns, Action<string> log)
+ {
+ for (int t = 0; t < turns; t++)
+ {
+ yield return null;
+ for (int guard = 0; card.Shown != null; guard++)
+ {
+ var shown = card.Shown;
+ var option = root.Q<VisualElement>("event-options")?.Q<Button>();
+ if (option == null || guard >= 50) { log($"SMOKE FAIL event {shown.Id} has no option to press"); yield break; }
+ if (!Press(option, log)) yield break;
+ if (card.Shown == shown) { log($"SMOKE FAIL the option '{option.text}' for event {shown.Id} was not taken"); yield break; }
+ yield return null;
+ }
+ var turn = bridge.State.Turn;
+ int refused = 0;
+ Action<IReadOnlyList<Rejection>> count = r => refused = r.Count;
+ bridge.TurnEnded += count;
+ bool pressed;
+ try { pressed = Press(root.Q<Button>("end-turn"), log); }
+ finally { bridge.TurnEnded -= count; }
+ if (!pressed) yield break;
+ if (bridge.State.Turn != turn + 1) { log($"SMOKE FAIL End Turn did not end turn {turn}"); yield break; }
+ var s = bridge.State;
+ log(FormattableString.Invariant($"SMOKE turn {s.Turn} {s.Date:yyyy-MM-dd} refused {refused}"));
+ }
+ log(FormattableString.Invariant($"SMOKE OK {turns} turns {bridge.State.Date:yyyy-MM-dd} {bridge.State.Hash()}"));
+ }
+
+ static bool Press(Button? b, Action<string> log)
+ {
+ if (b == null) { log("SMOKE FAIL button missing"); return false; }
+ try
+ {
+ using (var e = NavigationSubmitEvent.GetPooled()) { e.target = b; b.SendEvent(e); }
+ return true;
+ }
+ catch (Exception e) { log("SMOKE FAIL " + e.Message); return false; }
+ }
+
+ sealed class Undo : IDisposable
+ {
+ readonly Action undo;
+ public Undo(Action undo) { this.undo = undo; }
+ public void Dispose() => undo();
+ }
+ }
+}
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs.meta b/unity/Assets/Scripts/UI/GameRoot.cs.meta
new file mode 100644
index 000000000..932088265
--- /dev/null
+++ b/unity/Assets/Scripts/UI/GameRoot.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 63fdca1f33b5645bf903ae90525be959
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.cs
new file mode 100644
index 000000000..66dbfc5d8
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs
@@ -0,0 +1,321 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Boot;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+using Object = UnityEngine.Object;
+
+/// <summary>Map.unity as the player gets it: GameRoot wired to the boot, the map, the camera, the pointer, the placement
+/// layer and the UI document, every presenter created and disposed with it, and the scripted smoke run (plan Task 23 and
+/// the carry list to Task 23).</summary>
+public class GameSceneTests
+{
+ static GameInputs? inputs;
+ static GameInputs Inputs => inputs ??= GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);
+ static UiText Text => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
+
+ string saveDir = "";
+
+ [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-scene-" + Guid.NewGuid().ToString("N"));
+
+ [TearDown]
+ public void DiscardScene()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);
+ else if (File.Exists(saveDir)) File.Delete(saveDir);
+ }
+
+ /// <summary>Opens Map.unity, builds the map from the repository inputs and starts the game the way GameBoot.Ready does,
+ /// with the saves in a temporary folder (never the player's real autosave).</summary>
+ GameRoot Boot(SaveStore? store = null)
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ Object.FindFirstObjectByType<MapScene>().Build(Inputs.Map);
+ var root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = store ?? new SaveStore(saveDir);
+ root.Begin(Inputs, 0);
+ return root;
+ }
+
+ static VisualElement Ui => Object.FindFirstObjectByType<UIDocument>().rootVisualElement;
+
+ [Test]
+ public void MapUnityIsTheOnlyBuildSceneAndIsFullyWired()
+ {
+ Assert.AreEqual(new[] { "Assets/Map.unity" }, Array.ConvertAll(EditorBuildSettings.scenes, s => s.path));
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var root = Object.FindFirstObjectByType<GameRoot>();
+ Assert.IsNotNull(root, "GameRoot");
+ var so = new SerializedObject(root);
+ foreach (var field in new[] { "boot", "document", "strings", "portraits", "map", "placements", "pointer", "cameraController" })
+ Assert.IsNotNull(so.FindProperty(field).objectReferenceValue, field);
+ var boot = Object.FindFirstObjectByType<GameBoot>();
+ Assert.IsNotNull(boot);
+ Assert.AreSame(Object.FindFirstObjectByType<MapScene>(), new SerializedObject(boot).FindProperty("map").objectReferenceValue, "GameBoot.map");
+ var map = new SerializedObject(Object.FindFirstObjectByType<MapScene>());
+ Assert.AreEqual(AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/Terrain.mat"), map.FindProperty("terrainMaterial").objectReferenceValue);
+ Assert.AreEqual(AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/HexOverlay.mat"), map.FindProperty("overlayMaterial").objectReferenceValue);
+ Assert.AreEqual(AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/SettlementMarker.mat"), map.FindProperty("markerMaterial").objectReferenceValue);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ Assert.AreEqual(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel), doc.panelSettings);
+ Assert.AreEqual(AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml), doc.visualTreeAsset);
+ Assert.IsNotNull(Camera.main.GetComponent<CameraController>());
+ Assert.IsNotNull(Camera.main.GetComponent<CameraRig>());
+ Assert.IsNotNull(Object.FindFirstObjectByType<PlacementLayer>());
+ Assert.IsNotNull(Object.FindFirstObjectByType<MapPointer>());
+ Assert.IsNull(GameObject.Find("EventSystem"), "UI Toolkit reads the Input System directly; an EventSystem would take over");
+ }
+
+ [Test]
+ public void TheGameStartsInTheSceneOnceTheInputsAreLoaded()
+ {
+ var root = Boot();
+ Assert.IsNotNull(root.Bridge);
+ Assert.AreEqual(root.Bridge!.State.Date.Year.ToString(), Ui.Q<Label>("year").text);
+ Assert.AreEqual("Click the map to inspect a hex", Ui.Q<Label>("info-title").text);
+ Assert.AreEqual(new DateTime(1948, 5, 15), root.Bridge.State.Date, "no autosave: a new game");
+ var pointer = Object.FindFirstObjectByType<MapPointer>();
+ Assert.AreSame(Object.FindFirstObjectByType<MapScene>(), pointer.Map);
+ Assert.IsNotNull(pointer.IsOverUi);
+ Assert.IsNotNull(Camera.main.GetComponent<CameraController>().IsOverUi);
+ var size = Object.FindFirstObjectByType<MapScene>().Terrain.terrainData.size;
+ Assert.AreEqual(size.x, Camera.main.GetComponent<CameraController>().Bounds.width, 1f);
+ Assert.AreEqual(size.z, Camera.main.GetComponent<CameraController>().Bounds.height, 1f);
+ }
+
+ // Carry 2 and 8: ScreenNav hides every screen at start; the empty middle of the screen reaches the map while the
+ // panels do not (the camera and the map pointer ask the game panel); a minimap click moves the camera.
+ [UnityTest]
+ public IEnumerator AfterBootNoScreenIsOpenThePanelsBlockTheMapAndTheMinimapMovesTheCamera()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ var rt = new RenderTexture(1920, 1080, 0);
+ var ps = Object.Instantiate(doc.panelSettings);
+ ps.targetTexture = rt;
+ try
+ {
+ doc.panelSettings = ps;
+ Object.FindFirstObjectByType<MapScene>().Build(Inputs.Map);
+ var root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ root.Begin(Inputs, 0);
+ var ui = doc.rootVisualElement;
+ for (int i = 0; i < 30 && !(ui.Q("minimap-image").worldBound.width > 0); i++) yield return null;
+ Assert.IsTrue(ui.Q("minimap-image").worldBound.width > 0, "the panel was laid out");
+
+ foreach (var s in ScreenNav.Screens)
+ Assert.AreEqual(DisplayStyle.None, ui.Q("screen-" + s).resolvedStyle.display, s + " is hidden at start");
+ var panel = ui.panel;
+ Assert.IsNull(panel.Pick(ui.worldBound.center), "the middle of the screen is map, not UI");
+
+ // A screen point for a panel point: ScreenToPanel is affine, so two probes invert it.
+ float h = Screen.height;
+ Vector2 o = UiPointer.ToPanel(panel, Vector2.zero, h), ex = UiPointer.ToPanel(panel, Vector2.right * 100, h) - o, ey = UiPointer.ToPanel(panel, Vector2.up * 100, h) - o;
+ Vector2 ScreenFor(Vector2 p) => new Vector2((p - o).x / ex.x * 100, (p - o).y / ey.y * 100);
+ var pointer = Object.FindFirstObjectByType<MapPointer>();
+ var camera = Camera.main.GetComponent<CameraController>();
+ foreach (var name in new[] { "top-bar", "info-panel", "minimap" })
+ {
+ var at = ScreenFor(ui.Q(name).worldBound.center);
+ Assert.IsTrue(pointer.IsOverUi!(at), name + " blocks map clicks");
+ Assert.IsTrue(camera.IsOverUi!(at), name + " blocks the wheel and the drag");
+ }
+ var middle = ScreenFor(ui.worldBound.center);
+ Assert.IsFalse(pointer.IsOverUi!(middle));
+ Assert.IsFalse(camera.IsOverUi!(middle));
+
+ UiTestKit.Press(ui.Q<Button>("nav-cabinet"));
+ Assert.AreEqual(DisplayStyle.Flex, ui.Q("screen-cabinet").style.display.value, "the top-bar buttons open screens");
+
+ var image = ui.Q("minimap-image");
+ using (var e = PointerDownEvent.GetPooled(new Event { type = EventType.MouseDown, button = 0, mousePosition = image.worldBound.center }))
+ { e.target = image; image.SendEvent(e); }
+ var map = Object.FindFirstObjectByType<MapScene>();
+ var rig = Camera.main.GetComponent<CameraRig>();
+ var b = map.Hexes.bounds;
+ var expected = map.Frame.ToWorld((b.lon0 + b.lon1) / 2, (b.lat0 + b.lat1) / 2, 0);
+ Assert.AreEqual(expected.x, rig.LookAt.x, map.Frame.WidthM * 0.02f, "the camera moved to the clicked point");
+ Assert.AreEqual(expected.z, rig.LookAt.z, map.Frame.LengthM * 0.02f);
+ Assert.AreEqual(rig.LookAt - rig.transform.forward * rig.Distance, rig.transform.position, "the rig was applied");
+ }
+ finally
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ // NewScene unloads unreferenced assets, which may already have destroyed these
+ if (ps != null) Object.DestroyImmediate(ps);
+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }
+ }
+ }
+
+ // Carry 8: a real raycast on the built terrain picks the hex under the camera and fills the info panel.
+ [Test]
+ public void AClickOnTheTerrainFillsTheInfoPanel()
+ {
+ Boot();
+ var map = Object.FindFirstObjectByType<MapScene>();
+ var c = Inputs.Content;
+ var tlv = c.SettlementHexes.Single(s => s.Id == "tel_aviv");
+ var hex = c.HexAt(tlv.Q, tlv.R)!;
+ var ground = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
+ var cam = Camera.main!;
+ cam.transform.position = new Vector3(ground.x, 50_000f, ground.z);
+ cam.transform.rotation = Quaternion.Euler(90, 0, 0);
+ var pointer = Object.FindFirstObjectByType<MapPointer>();
+ Assert.IsTrue(pointer.HandleClick(new Vector2(cam.pixelWidth / 2f, cam.pixelHeight / 2f)), "the ray hit the terrain");
+ Assert.AreEqual("Tel Aviv", Ui.Q<Label>("info-title").text);
+ }
+
+ // One label each presenter writes on every change: HUD, toast, info panel, Why, Budget, Defence, Cabinet.
+ static readonly string[] Watched = { "year", "toast", "info-title", "why-turn", "budget-money", "mob-level", "cabinet-coalition" };
+
+ // Carry 1, 3-7, 9: disabling GameRoot disposes every presenter, the autosave and its own hooks.
+ [Test]
+ public void ADisabledGameRootHearsNothing()
+ {
+ var root = Boot();
+ var bridge = root.Bridge!;
+ var pointer = Object.FindFirstObjectByType<MapPointer>();
+ root.enabled = false;
+ Assert.IsNull(pointer.IsOverUi, "the pointer no longer asks a disposed panel");
+ Assert.IsNull(Camera.main.GetComponent<CameraController>().IsOverUi);
+ foreach (var label in Watched)
+ Ui.Q<Label>(label).text = "untouched";
+ var turn = bridge.State.Turn;
+ UiTestKit.Press(Ui.Q<Button>("end-turn"));
+ Assert.AreEqual(turn, bridge.State.Turn, "End Turn is no longer wired (HudPresenter)");
+ UiTestKit.Press(Ui.Q<Button>("nav-budget"));
+ Assert.AreNotEqual(DisplayStyle.Flex, Ui.Q("screen-budget").style.display.value, "ScreenNav");
+ var session = bridge.Session;
+ UiTestKit.Press(Ui.Q<Button>("new-game")); UiTestKit.Press(Ui.Q<Button>("new-game"));
+ Assert.AreSame(session, bridge.Session, "NewGamePresenter");
+ Assert.AreEqual(DisplayStyle.None, Ui.Q("event-card").style.display.value, "EventCardPresenter hid its card");
+ bridge.Queue(new SetMobilization(0.1));
+ bridge.EndTurn();
+ foreach (var label in Watched)
+ Assert.AreEqual("untouched", Ui.Q<Label>(label).text, label);
+ Assert.IsFalse(File.Exists(Path.Combine(saveDir, SaveStore.AutosaveName)), "the autosave was disposed");
+ }
+
+ // Carry 9: the start goes through GameStart.Begin (an unreadable autosave is set aside, with a note in the toast);
+ // each turn is saved; the game continues from that save on the next start.
+ [Test]
+ public void TheStartNotesShowInTheToastAndEachTurnIsSaved()
+ {
+ Directory.CreateDirectory(saveDir);
+ File.WriteAllText(Path.Combine(saveDir, SaveStore.AutosaveName), "not a save");
+ var root = Boot();
+ StringAssert.StartsWith("Your saved game could not be loaded", Ui.Q<Label>("toast").text);
+ Assert.IsTrue(File.Exists(Path.Combine(saveDir, "autosave.bad.txt")));
+ root.Bridge!.EndTurn();
+ Assert.IsTrue(File.Exists(Path.Combine(saveDir, SaveStore.AutosaveName)), "the turn was autosaved");
+ var hash = root.Bridge.State.Hash();
+ root.enabled = false;
+ root.enabled = true;
+ root.Begin(Inputs, 0);
+ Assert.AreEqual(hash, root.Bridge!.State.Hash(), "the next start continues the autosave");
+ }
+
+ // Carry 11: the autosave subscribes after the toast, so a save failure is not cleared by the turn's own toast.
+ [Test]
+ public void ASaveFailureIsNotHiddenByTheTurnsToast()
+ {
+ File.WriteAllText(saveDir, "a file where the save folder should be");
+ var root = Boot(new SaveStore(saveDir));
+ LogAssert.Expect(LogType.Warning, new System.Text.RegularExpressions.Regex("^Autosave could not be written"));
+ root.Bridge!.EndTurn();
+ Assert.AreEqual(Text["save.write_failed"], Ui.Q<Label>("toast").text);
+ }
+
+ // Carry 10: placements are drawn at start and redrawn only when State.Placements changes.
+ [Test]
+ public void PlacementsAreRedrawnOnlyWhenTheyChange()
+ {
+ var root = Boot();
+ var c = Inputs.Content;
+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);
+ while (g.State.Date < new DateTime(1950, 8, 1)) g.Step(HistoricalAI.Commands(c, g.State));
+ var bridge = root.Bridge!;
+ bridge.Replace(g);
+ var layer = Object.FindFirstObjectByType<PlacementLayer>().transform;
+ Assert.AreEqual(g.State.Placements.Count, layer.childCount);
+ var tlv = c.SettlementHexes.Single(s => s.Id == "tel_aviv");
+ Assert.IsNull(bridge.Queue(new MapAction(MapActions.TransitCamp, tlv.Q, tlv.R)));
+ Assert.AreEqual(g.State.Placements.Count, layer.childCount, "a queued order draws nothing");
+ bridge.EndTurn();
+ Assert.AreEqual(bridge.State.Placements.Count, layer.childCount);
+ var camp = layer.Cast<Transform>().Single(t => t.name == $"{MapActions.TransitCamp}_{tlv.Q}_{tlv.R}").gameObject;
+ bridge.Queue(new SetMobilization(bridge.State.Mobilization));
+ bridge.EndTurn();
+ Assert.IsTrue(camp != null, "an unchanged set of placements is not redrawn");
+ Assert.IsNull(bridge.Queue(new MapAction(MapActions.Housing, tlv.Q, tlv.R)));
+ bridge.EndTurn();
+ Assert.IsTrue(camp == null, "housing replacing the camp is redrawn");
+ Assert.IsNotNull(layer.Cast<Transform>().SingleOrDefault(t => t.name == $"{MapActions.Housing}_{tlv.Q}_{tlv.R}"));
+ }
+
+ // Amendment A2: the smoke run answers a pending event by pressing the card's option button.
+ [Test]
+ public void TheSmokeRunAnswersAPendingEventThroughTheCard()
+ {
+ using var ui = new UiTestKit();
+ var c = Inputs.Content;
+ var g = GameSession.New(c, GoldenRun.Seed, Mode.Historical);
+ while (!g.State.PendingEvents.Contains("armistice_egypt")) g.Step(new Command[0]);
+ var text = Text;
+ var bridge = new SimBridge(g, text);
+ using var toast = new ToastPresenter(ui.Root, bridge, text);
+ using var hud = new HudPresenter(ui.Root, bridge, text); // wires the End Turn button
+ using var card = new EventCardPresenter(ui.Root, bridge, text, null);
+ var turn = g.State.Turn;
+ var log = new List<string>();
+ var run = GameRoot.Smoke(ui.Root, bridge, card, 1, log.Add);
+ while (run.MoveNext()) { }
+ StringAssert.StartsWith("SMOKE OK 1 turns", log[log.Count - 1], string.Join("\n", log));
+ StringAssert.StartsWith($"SMOKE turn {turn + 1} ", log[log.Count - 2]);
+ Assert.AreEqual(turn + 1, bridge.State.Turn);
+ Assert.IsTrue(bridge.Session.Last!.Why.Any(w => w.Message == "chosen: Sign the armistice"), "the card's option was pressed, not delegated");
+ Assert.IsFalse(bridge.Session.Last.Why.Any(w => w.Target == "armistice_egypt" && w.Message.StartsWith("delegated")));
+ }
+
+ [Test]
+ public void ASmokeRunWhoseEndTurnDoesNothingFails()
+ {
+ using var ui = new UiTestKit();
+ var bridge = new SimBridge(GameSession.New(Inputs.Content, GoldenRun.Seed, Mode.Historical), Text);
+ using var card = new EventCardPresenter(ui.Root, bridge, Text, null); // no HudPresenter: End Turn is not wired
+ var log = new List<string>();
+ var run = GameRoot.Smoke(ui.Root, bridge, card, 2, log.Add);
+ while (run.MoveNext()) { }
+ StringAssert.StartsWith("SMOKE FAIL", log[log.Count - 1]);
+ Assert.IsFalse(log.Any(l => l.StartsWith("SMOKE OK")));
+ }
+
+ // Amendment A3: the URL flag must start a query parameter and end at a word boundary.
+ [Test]
+ public void SmokeTurnsComeFromTheUrlOrTheCommandLine()
+ {
+ Assert.AreEqual(5, GameRoot.SmokeTurns("http://localhost:8000/?golden&smoke=5", new string[0], true));
+ Assert.AreEqual(3, GameRoot.SmokeTurns("http://localhost:8000/?smoke=3", new string[0], true));
+ Assert.AreEqual(GameRoot.DefaultSmokeTurns, GameRoot.SmokeTurns("http://localhost:8000/?smoke", new string[0], true));
+ Assert.AreEqual(0, GameRoot.SmokeTurns("http://localhost:8000/smoke-test/index.html", new string[0], true));
+ Assert.AreEqual(0, GameRoot.SmokeTurns("http://localhost:8000/?smoker=4", new string[0], true));
+ Assert.AreEqual(0, GameRoot.SmokeTurns("http://localhost:8000/", new string[0], true));
+ Assert.AreEqual(4, GameRoot.SmokeTurns(null, new[] { "Statecraft", "-smoke", "4" }, false));
+ Assert.AreEqual(0, GameRoot.SmokeTurns(null, new[] { "Statecraft" }, false));
+ Assert.AreEqual(0, GameRoot.SmokeTurns("http://localhost/?smoke=5", new[] { "Statecraft" }, false), "desktop reads only the command line");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs.meta b/unity/Assets/Tests/EditMode/GameSceneTests.cs.meta
new file mode 100644
index 000000000..b032fac71
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: ce9b3621f537642b98ff6af33b8722a4
\ No newline at end of file