A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Show boot failures without local paths; test the real catch path
eyalgolan4cc34d6f673c
diff --git a/unity/Assets/Scripts/Boot/GameBoot.cs b/unity/Assets/Scripts/Boot/GameBoot.csindex b46c3f326..116b5a083 100644--- a/unity/Assets/Scripts/Boot/GameBoot.cs+++ b/unity/Assets/Scripts/Boot/GameBoot.cs@@ -1,5 +1,6 @@#nullable enableusing System;+using System.Text.RegularExpressions;using Statecraft.Game.Map;using UnityEngine;@@ -29,15 +30,34 @@ namespace Statecraft.Game.BootFailed?.Invoke(reason);}+ /// <summary>The failure reason as the player sees it: absolute local paths (a desktop player reads its files from+ /// disk, file:// URIs included) shortened to the file name; http(s) URLs and plain reasons are kept. Error and the+ /// log keep the full reason (pre-merge rereview).</summary>+ public static string ForPlayer(string reason) =>+ BarePath.Replace(QuotedPath.Replace(reason, m => m.Groups[1].Value + FileName(m.Groups[2].Value) + m.Groups[1].Value),+ m => FileName(m.Value));++ static readonly Regex QuotedPath = new Regex(@"(['""])((?:file://|/|[A-Za-z]:\\)[^'""]*)\1");+ static readonly Regex BarePath = new Regex(@"(?<![\w:/.\\])(?:file://)?(?:/|[A-Za-z]:\\)[^\s'""()]+");+ static string FileName(string path) => path.Substring(path.LastIndexOfAny(new[] { '/', '\\' }) + 1);+async void Start(){DiagLog.Init();DiagLog.BootPhase("player started");+ await BootAsync(LoadAsync);+ }++ static async Awaitable<GameInputs> LoadAsync() => Application.platform == RuntimePlatform.WebGLPlayer+ ? await GameInputs.FetchAsync(GameInputs.StreamingUrl())+ : GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);++ /// <summary>The boot Start runs, with the loader passed in so a test can drive the real failure path.</summary>+ internal async Awaitable BootAsync(Func<Awaitable<GameInputs>> load)+ {try{- Inputs = Application.platform == RuntimePlatform.WebGLPlayer- ? await GameInputs.FetchAsync(GameInputs.StreamingUrl())- : GameInputs.FromDisk(Paths.Content, Paths.StreamingMap);+ Inputs = await load();if (GoldenCheck.Requested()){var (ok, lines) = GoldenCheck.Run(Inputs.Content);diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 5452c5720..6d189acf1 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -67,7 +67,7 @@ namespace Statecraft.Game.UI{if (document == null || strings == null) return;var line = document.rootVisualElement.Q<Label>("loading");- if (line != null) line.text = UiText.Parse(strings.text).Format("boot.failed", reason);+ if (line != null) line.text = UiText.Parse(strings.text).Format("boot.failed", GameBoot.ForPlayer(reason).TrimEnd('.'));}void OnDisable()diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex 0acab7417..776d3d5f9 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -608,4 +608,40 @@ public class GameSceneTestsvar names = SettlementPlacer.Parse(Inputs.Map.SettlementsYaml).Select(s => s.Id).ToHashSet();foreach (var sh in Inputs.Content.SettlementHexes) Assert.IsTrue(names.Contains(sh.Id), sh.Id);}++ /// <summary>Rereview: the real failure path. GameBoot's boot (what Start runs) catches a failing load, and the player+ /// sees the reason with no absolute local path (desktop players read files from disk), only the file name.</summary>+ [UnityTest]+ public IEnumerator AFailingLoadIsCaughtAndShownWithoutLocalPaths()+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ var doc = Object.FindFirstObjectByType<UIDocument>();+ var rt = new RenderTexture(1280, 720, 0);+ var ps = Object.Instantiate(doc.panelSettings); ps.targetTexture = rt;+ try+ {+ doc.panelSettings = ps;+ var boot = Object.FindFirstObjectByType<GameBoot>();+ LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("BOOT FAIL Could not find file"));+ LogAssert.Expect(LogType.Exception, new System.Text.RegularExpressions.Regex("Could not find file"));+ _ = boot.BootAsync(() => throw new IOException("Could not find file '/Users/someone/Statecraft Israel.app/Contents/Resources/Data/StreamingAssets/map/heightmap.json'."));+ for (int i = 0; i < 3; i++) yield return null;+ var line = doc.rootVisualElement.Q<Label>("loading").text;+ Assert.AreEqual("Statecraft could not start: Could not find file 'heightmap.json'. Reload the page.", line);+ StringAssert.DoesNotContain("/Users/", line);+ }+ finally+ {+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);+ if (ps != null) Object.DestroyImmediate(ps);+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }+ }+ }++ [TestCase("Could not find file '/Users/a b/x/content/people.yaml'.", "Could not find file 'people.yaml'.")]+ [TestCase(@"Could not find file 'C:\Games\Statecraft\StreamingAssets\map\hexes.json'.", "Could not find file 'hexes.json'.")]+ [TestCase("heightmap.r16: Cannot connect to destination host (file:///Users/me/Data/StreamingAssets/map/heightmap.r16)", "heightmap.r16: Cannot connect to destination host (heightmap.r16)")]+ [TestCase("people.yaml: people[x].name: required", "people.yaml: people[x].name: required")]+ [TestCase("manifest.json: HTTP/1.1 404 Not Found (http://localhost:8766/StreamingAssets/content/manifest.json)", "manifest.json: HTTP/1.1 404 Not Found (http://localhost:8766/StreamingAssets/content/manifest.json)")]+ public void BootFailureTextKeepsOnlyFileNames(string reason, string shown) => Assert.AreEqual(shown, GameBoot.ForPlayer(reason));}