A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(boot): one whole-parameter rule for the golden, profile and camlog URL flags (Task 24 review M2)
eyalgolanac6dc379a29c
diff --git a/unity/Assets/Scripts/Boot/UrlFlags.cs b/unity/Assets/Scripts/Boot/UrlFlags.csindex 3a5451d25..c31e21079 100644--- a/unity/Assets/Scripts/Boot/UrlFlags.cs+++ b/unity/Assets/Scripts/Boot/UrlFlags.cs@@ -4,11 +4,12 @@ using System.Text.RegularExpressions;namespace Statecraft.Game.Boot{- /// <summary>Flags in the WebGL page URL's query: "?golden", "&smoke=5", "?profile". A flag must start a query- /// parameter and end at a word boundary, so a path such as ".../golden-project/..." never turns one on.</summary>+ /// <summary>Flags in the WebGL page URL's query: "?golden", "&smoke=5", "?profile", "?camlog". A flag is a whole query+ /// parameter: it starts at '?' or '&' and ends at '=', '&', '#' or the end of the URL (the rule GameRoot's smoke+ /// flag uses), so neither a path such as ".../golden-project/..." nor "?profile-x" or "?golden.y" turns one on.</summary>public static class UrlFlags{- public static bool Has(string? url, string name) => Regex.IsMatch(url ?? "", @"[?&]" + Regex.Escape(name) + @"\b");+ public static bool Has(string? url, string name) => Regex.IsMatch(url ?? "", @"[?&]" + Regex.Escape(name) + @"(?=[=&#]|$)");/// <summary>The flag's integer value ("smoke=5" -> 5), or 0 when absent.</summary>public static int Int(string? url, string name)diff --git a/unity/Assets/Scripts/Map/PixelErrorProfile.cs b/unity/Assets/Scripts/Map/PixelErrorProfile.csindex 11c029230..15d339fb6 100644--- a/unity/Assets/Scripts/Map/PixelErrorProfile.cs+++ b/unity/Assets/Scripts/Map/PixelErrorProfile.cs@@ -11,7 +11,7 @@ namespace Statecraft.Game.Map/// <summary>Measures frame time with the terrain's heightmapPixelError at 1 (M2's value, which keeps the hex overlay/// draped visibly) and at Unity's default 5, from the diorama camera over central Israel, then restores the M2 value./// Logs "PROFILE pixelError=<e> frames=<n> avg_ms=<a> p95_ms=<p>" per setting and "PROFILE done".- /// Asked for by "profile" in the WebGL page URL (a whole query parameter, UrlFlags) or -profile on desktop.</summary>+ /// Asked for by "profile" in the WebGL page URL (a whole query parameter, UrlFlags.Has) or -profile on desktop.</summary>public static class PixelErrorProfile{public const int WarmupFrames = 60, MeasuredFrames = 300;diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex b70f9597c..b827879e7 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -68,7 +68,7 @@ namespace Statecraft.Game.UI}// "smoke" as a whole query parameter: bare ("?smoke", "&smoke=") or with a number; it ends at '&', '#' or the end, so- // "?smoke-x", "?smoker" and "?smoke=five" are not the flag (tighter than UrlFlags' word boundary, amendment A3).+ // "?smoke-x", "?smoker" and "?smoke=five" are not the flag: UrlFlags' whole-parameter rule, plus digits only (amendment A3).static readonly Regex SmokeQuery = new Regex(@"[?&]smoke(?:=(\d*))?(?=&|#|$)", RegexOptions.CultureInvariant);/// <summary>Smoke-test turn count: from the page URL on WebGL, else from the command line. "?smoke=N" / "-smoke N"@@ -217,7 +217,7 @@ namespace Statecraft.Game.UI/// <summary>"camlog" in the WebGL page URL (a whole query parameter) or -camlog on desktop: log the camera distance and/// yaw whenever they change (checks the wheel-zoom step in a real browser).</summary>internal static bool CameraLogRequested(string? url, string[] args, bool webgl) =>- webgl ? Regex.IsMatch(url ?? "", @"[?&]camlog(?=&|#|=|$)") : Array.IndexOf(args, "-camlog") >= 0;+ webgl ? UrlFlags.Has(url, "camlog") : Array.IndexOf(args, "-camlog") >= 0;static bool CameraLogRequested() =>CameraLogRequested(Application.absoluteURL, Environment.GetCommandLineArgs(), Application.platform == RuntimePlatform.WebGLPlayer);diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex e844e256d..62114cc6d 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -473,6 +473,7 @@ public class GameSceneTestsAssert.IsTrue(GameRoot.CameraLogRequested("http://localhost/?golden&camlog", new string[0], true));Assert.IsFalse(GameRoot.CameraLogRequested("http://localhost/?camlogs", new string[0], true));Assert.IsFalse(GameRoot.CameraLogRequested("http://localhost/camlog/", new string[0], true));+ Assert.IsFalse(GameRoot.CameraLogRequested("http://localhost/?camlog-x", new string[0], true));Assert.IsTrue(GameRoot.CameraLogRequested(null, new[] { "x", "-camlog" }, false));Assert.IsFalse(GameRoot.CameraLogRequested(null, new[] { "x" }, false));Assert.AreEqual("CAMERA distance=120000 yaw=0.0", GameRoot.CameraLine(120000f, 0f));diff --git a/unity/Assets/Tests/EditMode/GoldenCheckTests.cs b/unity/Assets/Tests/EditMode/GoldenCheckTests.csindex 66a7b11ff..37088b875 100644--- a/unity/Assets/Tests/EditMode/GoldenCheckTests.cs+++ b/unity/Assets/Tests/EditMode/GoldenCheckTests.cs@@ -18,6 +18,10 @@ public class GoldenCheckTests[TestCase("https://html.itch.zone/html/123/golden-project/index.html", false)][TestCase("http://localhost:8000/index.html?goldenrod=1", false)][TestCase("http://localhost:8000/index.html", false)]+ [TestCase("http://localhost:8000/index.html?golden.y", false)] // Task 24 review M2: a whole query parameter+ [TestCase("http://localhost:8000/index.html?golden-x&smoke=5", false)]+ [TestCase("http://localhost:8000/index.html?golden#top", true)]+ [TestCase("http://localhost:8000/index.html?golden=1", true)]public void TheGoldenFlagIsAQueryParameterNotAPathWord(string url, bool expected) =>Assert.AreEqual(expected, UrlFlags.Has(url, "golden"));@@ -39,4 +43,18 @@ public class GoldenCheckTestsAssert.IsNull(GoldenCheck.QuitCodeOnError(requested: true, webgl: true));Assert.IsNull(GoldenCheck.QuitCodeOnError(requested: false, webgl: false));}++ /// <summary>Task 24 review M2: golden, profile and camlog share one rule (UrlFlags.Has): the flag is a whole query+ /// parameter, bare or with a value, ending at '&', '#' or the end.</summary>+ [TestCase("profile")]+ [TestCase("camlog")]+ [TestCase("golden")]+ public void EveryBooleanFlagIsAWholeQueryParameter(string flag)+ {+ Assert.IsTrue(UrlFlags.Has($"http://x/index.html?{flag}", flag));+ Assert.IsTrue(UrlFlags.Has($"http://x/index.html?smoke=5&{flag}&y", flag));+ Assert.IsFalse(UrlFlags.Has($"http://x/index.html?{flag}-x", flag));+ Assert.IsFalse(UrlFlags.Has($"http://x/index.html?{flag}s", flag));+ Assert.IsFalse(UrlFlags.Has($"http://x/{flag}/index.html", flag));+ }}diff --git a/unity/Assets/Tests/EditMode/PixelErrorProfileTests.cs b/unity/Assets/Tests/EditMode/PixelErrorProfileTests.csindex 0b3108780..2da1f2cc1 100644--- a/unity/Assets/Tests/EditMode/PixelErrorProfileTests.cs+++ b/unity/Assets/Tests/EditMode/PixelErrorProfileTests.cs@@ -15,6 +15,7 @@ public class PixelErrorProfileTests[TestCase("http://localhost:8000/index.html?profile", true)][TestCase("http://localhost:8000/index.html?golden&profile", true)][TestCase("https://html.itch.zone/html/123/profile-pics/index.html", false)]+ [TestCase("http://localhost:8000/index.html?profile-x", false)] // Task 24 review M2public void TheProfileFlagIsAQueryParameter(string url, bool expected) =>Assert.AreEqual(expected, PixelErrorProfile.Requested(url, new string[0], true));