A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(unity): enforce templateDefaultScene, restore settings before a failed build exits, test compression settings
eyalgolanc1d79069f189
diff --git a/unity/Assets/Editor/Build.cs b/unity/Assets/Editor/Build.csindex 105f81805..66fbc12c1 100644--- a/unity/Assets/Editor/Build.cs+++ b/unity/Assets/Editor/Build.cs@@ -1,6 +1,5 @@#nullable enableusing System;-using System.IO;using System.Linq;using UnityEditor;using UnityEditor.Build;@@ -40,8 +39,10 @@ namespace Statecraft.Game.EditorToolsProjectSetup.Apply();PlayerSettings.WebGL.compressionFormat = Compression(name);PlayerSettings.WebGL.decompressionFallback = false; // itch.io serves .br/.gz with Content-Encoding- try { Run(BuildTarget.WebGL, Arg("-out") ?? "Builds/Web-" + name); }+ bool ok;+ try { ok = Run(BuildTarget.WebGL, Arg("-out") ?? "Builds/Web-" + name); }finally { ProjectSetup.Apply(); } // back to the committed settings (compression Disabled)+ ExitIfFailed(ok);}public static void Mac()@@ -49,11 +50,16 @@ namespace Statecraft.Game.EditorToolsProjectSetup.Apply();// Apple clang fuses a*b+c into fmadd by default (tech notes 4.2); turn it off if the Mac golden check fails.PlayerSettings.SetAdditionalIl2CppArgs(Flag("-ffp-contract-off") ? "--compiler-flags=-ffp-contract=off" : "");- try { Run(BuildTarget.StandaloneOSX, Arg("-out") ?? "Builds/Mac/Statecraft.app"); }+ bool ok;+ try { ok = Run(BuildTarget.StandaloneOSX, Arg("-out") ?? "Builds/Mac/Statecraft.app"); }finally { PlayerSettings.SetAdditionalIl2CppArgs(""); AssetDatabase.SaveAssets(); }+ ExitIfFailed(ok);}- static void Run(BuildTarget target, string location)+ /// <summary>Exits with code 1 after the caller's settings have been restored.</summary>+ static void ExitIfFailed(bool ok) { if (!ok) EditorApplication.Exit(1); }++ static bool Run(BuildTarget target, string location){var report = BuildPipeline.BuildPlayer(new BuildPlayerOptions{@@ -61,7 +67,7 @@ namespace Statecraft.Game.EditorTools});var s = report.summary;Debug.Log($"BUILD {s.result} {target} -> {location}: {s.totalSize / 1048576.0:0.0} MB, {s.totalErrors} errors, {s.totalTime.TotalSeconds:0}s");- if (s.result != BuildResult.Succeeded) EditorApplication.Exit(1);+ return s.result == BuildResult.Succeeded;}}}diff --git a/unity/Assets/Editor/ProjectSetup.cs b/unity/Assets/Editor/ProjectSetup.csindex 286ee7fc8..55b3c4b43 100644--- a/unity/Assets/Editor/ProjectSetup.cs+++ b/unity/Assets/Editor/ProjectSetup.cs@@ -21,6 +21,9 @@ namespace Statecraft.Game.EditorToolsPlayerSettings.WebGL.template = WebTemplate;PlayerSettings.WebGL.compressionFormat = WebGLCompressionFormat.Disabled;PlayerSettings.WebGL.decompressionFallback = false;+ var player = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/ProjectSettings.asset")[0]);+ var template = player.FindProperty("templateDefaultScene"); // no public API; the sample scene it named is gone+ if (template != null && template.stringValue != BootScene) { template.stringValue = BootScene; player.ApplyModifiedPropertiesWithoutUndo(); }EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(BootScene, true) };AssetDatabase.SaveAssets();}diff --git a/unity/Assets/Tests/EditMode/ProjectSettingsTests.cs b/unity/Assets/Tests/EditMode/ProjectSettingsTests.csindex 95c1047c3..91555ede0 100644--- a/unity/Assets/Tests/EditMode/ProjectSettingsTests.cs+++ b/unity/Assets/Tests/EditMode/ProjectSettingsTests.cs@@ -14,9 +14,17 @@ public class ProjectSettingsTestsAssert.AreEqual(ScriptingImplementation.IL2CPP, PlayerSettings.GetScriptingBackend(NamedBuildTarget.Standalone));Assert.AreEqual("PROJECT:Statecraft", PlayerSettings.WebGL.template);Assert.IsFalse(PlayerSettings.WebGL.decompressionFallback);+ Assert.AreEqual(WebGLCompressionFormat.Disabled, PlayerSettings.WebGL.compressionFormat);Assert.AreEqual(new[] { "Assets/Map.unity" }, EditorBuildSettings.scenes.Select(s => s.path).ToArray());}+ [Test]+ public void TheNewSceneTemplateDoesNotPointAtTheDeletedSampleScene()+ {+ var player = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/ProjectSettings.asset")[0]);+ Assert.AreEqual("Assets/Map.unity", player.FindProperty("templateDefaultScene").stringValue);+ }+[Test]public void TheTemplateFillsTheWindowAndPersistsSaves(){diff --git a/unity/ProjectSettings/ProjectSettings.asset b/unity/ProjectSettings/ProjectSettings.assetindex f1839dcb1..e9f867f66 100644--- a/unity/ProjectSettings/ProjectSettings.asset+++ b/unity/ProjectSettings/ProjectSettings.asset@@ -262,7 +262,7 @@ PlayerSettings:shaderPrecisionModel: 0clonedFromGUID: 3c72c65a16f0acb438eed22b8b16c24atemplatePackageId: [email protected]- templateDefaultScene: Assets/Scenes/SampleScene.unity+ templateDefaultScene: Assets/Map.unityuseCustomMainManifest: 0useCustomLauncherManifest: 0useCustomMainGradleTemplate: 0