A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Steam: a store-neutral platform seam and the five achievement rules (#2152) (#2182)
Eyal Golan6ac868b6b21b
diff --git a/changelog.d/steam-platform-seam.md b/changelog.d/steam-platform-seam.mdnew file mode 100644index 000000000..4a4daffae--- /dev/null+++ b/changelog.d/steam-platform-seam.md@@ -0,0 +1,3 @@+- A store-neutral platform seam for the coming Steam build (#2152): the game works out which of its five achievements a+ game has earned (the four objectives and finishing the campaign) and reports each to the store. Every build today+ keeps the no-op store, so nothing changes for players.diff --git a/unity/Assets/Scripts/Platform.meta b/unity/Assets/Scripts/Platform.metanew file mode 100644index 000000000..ddba35cc3--- /dev/null+++ b/unity/Assets/Scripts/Platform.meta@@ -0,0 +1,8 @@+fileFormatVersion: 2+guid: 75e2d6182cc34dbe88d2d124fb9e5698+folderAsset: yes+DefaultImporter:+ externalObjects: {}+ userData:+ assetBundleName:+ assetBundleVariant:diff --git a/unity/Assets/Scripts/Platform/AchievementReporter.cs b/unity/Assets/Scripts/Platform/AchievementReporter.csnew file mode 100644index 000000000..6f368cfb5--- /dev/null+++ b/unity/Assets/Scripts/Platform/AchievementReporter.cs@@ -0,0 +1,54 @@+#nullable enable+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Game.UI;++namespace Statecraft.Game+{+ /// <summary>Reports the achievements the game has earned (<see cref="AchievementRules"/>) to the store: once when made+ /// (a loaded save may already have some) and after each <see cref="SimBridge.Changed"/>, passing only ids this reporter+ /// has not reported. GameRoot makes a new reporter at each Begin (a load, a new game, a language switch), which offers+ /// what was earned again, so a store's Unlock must be idempotent (<see cref="IPlatformServices.Unlock"/>). It reads the+ /// turn's start (the saved state), never the order preview. With the no-op store it reads nothing. Nothing it does can+ /// throw out of it: a failure (the store's or the rules') is logged once, until a report succeeds again, and what was not+ /// taken is offered again on the next change.</summary>+ public sealed class AchievementReporter : IDisposable+ {+ readonly SimBridge bridge;+ readonly Func<IPlatformServices> services;+ readonly HashSet<string> reported = new HashSet<string>(StringComparer.Ordinal);+ bool failing;++ /// <param name="services">Asked on every report, so a store set after the game starts is used and gets everything earned+ /// so far (nothing counts as reported to the no-op store).</param>+ public AchievementReporter(SimBridge bridge, Func<IPlatformServices> services)+ {+ this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));+ this.services = services ?? throw new ArgumentNullException(nameof(services));+ bridge.Changed += Report;+ Report();+ }++ void Report()+ {+ try+ {+ var store = services();+ if (store is NullPlatformServices) return; // nothing takes them: offer them to a store set later+ var fresh = AchievementRules.Earned(bridge.TurnStart).Where(id => !reported.Contains(id)).ToList();+ if (fresh.Count == 0) return;+ store.Unlock(fresh);+ reported.UnionWith(fresh);+ failing = false;+ }+ catch (Exception e)+ {+ if (!failing) UnityEngine.Debug.LogException(e); // a store that stays down does not fill the log+ failing = true;+ }+ }++ public void Dispose() => bridge.Changed -= Report;+ }+}diff --git a/unity/Assets/Scripts/Platform/AchievementReporter.cs.meta b/unity/Assets/Scripts/Platform/AchievementReporter.cs.metanew file mode 100644index 000000000..f9c8a5391--- /dev/null+++ b/unity/Assets/Scripts/Platform/AchievementReporter.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: d4ac206f7d1c4ba59429df4f12b1d000diff --git a/unity/Assets/Scripts/Platform/AchievementRules.cs b/unity/Assets/Scripts/Platform/AchievementRules.csnew file mode 100644index 000000000..7445548ad--- /dev/null+++ b/unity/Assets/Scripts/Platform/AchievementRules.cs@@ -0,0 +1,36 @@+#nullable enable+using System;+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++namespace Statecraft.Game+{+ /// <summary>The five achievements (owner Q5 "Five (Recommended)", #2150): one per objective in content/objectives.yaml+ /// and one for finishing the campaign. Read from the game state only; the sim does not know about them. The API names are+ /// the ones the owner enters in Steamworks App Admin; AchievementRulesTests fails when an objective has none.</summary>+ public static class AchievementRules+ {+ /// <summary>The achievement API name for each objective id.</summary>+ public static readonly IReadOnlyDictionary<string, string> ForObjective = new Dictionary<string, string>(StringComparer.Ordinal)+ {+ ["railway"] = "OBJ_RAILWAY",+ ["burma_road"] = "OBJ_BURMA_ROAD",+ ["yishuvim"] = "OBJ_YISHUVIM",+ ["absorb_immigrants"] = "OBJ_ABSORB_IMMIGRANTS",+ };++ /// <summary>Reaching the GDD game's last day (<see cref="GameOverCodes.MvpEnded"/>); a defeat never earns it.</summary>+ public const string CampaignDone = "CAMPAIGN_DONE";++ /// <summary>The API names <paramref name="s"/> has earned, sorted ordinally.</summary>+ public static IReadOnlyList<string> Earned(GameState s)+ {+ if (s == null) throw new ArgumentNullException(nameof(s));+ var earned = s.Objectives.Keys.Where(ForObjective.ContainsKey).Select(id => ForObjective[id]).ToList();+ if (s.GameOver == GameOverCodes.MvpEnded) earned.Add(CampaignDone);+ earned.Sort(StringComparer.Ordinal);+ return earned;+ }+ }+}diff --git a/unity/Assets/Scripts/Platform/AchievementRules.cs.meta b/unity/Assets/Scripts/Platform/AchievementRules.cs.metanew file mode 100644index 000000000..a3ebc8b5e--- /dev/null+++ b/unity/Assets/Scripts/Platform/AchievementRules.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 331da3c6f69d4c50af7cf5852cfc99c1diff --git a/unity/Assets/Scripts/Platform/IPlatformServices.cs b/unity/Assets/Scripts/Platform/IPlatformServices.csnew file mode 100644index 000000000..ebc94a344--- /dev/null+++ b/unity/Assets/Scripts/Platform/IPlatformServices.cs@@ -0,0 +1,17 @@+#nullable enable+using System.Collections.Generic;++namespace Statecraft.Game+{+ /// <summary>What the game asks of a store (Steam; #2149). Store-neutral: Statecraft.Game never references a store's SDK,+ /// so web, itch.io and plain desktop builds run the no-op <see cref="NullPlatformServices"/>; a Steam build (#2154) sets+ /// <see cref="PlatformServices.Current"/> to its own.</summary>+ public interface IPlatformServices+ {+ /// <summary>The store's name for logs ("none" for the no-op).</summary>+ string Name { get; }+ /// <summary>Unlocks these achievements by their API names (<see cref="AchievementRules"/>). Must be idempotent: the+ /// reporter offers an id again after GameRoot rebuilds (a load, a new game, a language switch).</summary>+ void Unlock(IReadOnlyCollection<string> achievementIds);+ }+}diff --git a/unity/Assets/Scripts/Platform/IPlatformServices.cs.meta b/unity/Assets/Scripts/Platform/IPlatformServices.cs.metanew file mode 100644index 000000000..13ba92dac--- /dev/null+++ b/unity/Assets/Scripts/Platform/IPlatformServices.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 2d34b8318b7f48bb945b038a12ec3295diff --git a/unity/Assets/Scripts/Platform/PlatformServices.cs b/unity/Assets/Scripts/Platform/PlatformServices.csnew file mode 100644index 000000000..e68abed25--- /dev/null+++ b/unity/Assets/Scripts/Platform/PlatformServices.cs@@ -0,0 +1,32 @@+#nullable enable+using System.Collections.Generic;++namespace Statecraft.Game+{+ /// <summary>The store the game talks to (#2149). Never null: the default, and what setting null restores, is the no-op+ /// <see cref="NullPlatformServices"/>, which every build but a Steam build keeps. A store is set before GameRoot starts+ /// the game (a Steam build's bootstrap runs before the first scene loads, #2154); one set later gets what was earned at+ /// the next change (an order, a turn, a load).</summary>+ public static class PlatformServices+ {+ static IPlatformServices current = NullPlatformServices.Instance;++ public static IPlatformServices Current+ {+ get => current;+ set => current = value ?? NullPlatformServices.Instance;+ }+ }++ /// <summary>No store: the web, itch.io and plain desktop builds. Unlocks nothing.</summary>+ public sealed class NullPlatformServices : IPlatformServices+ {+ public static readonly NullPlatformServices Instance = new NullPlatformServices();++ NullPlatformServices() { }++ public string Name => "none";++ public void Unlock(IReadOnlyCollection<string> achievementIds) { }+ }+}diff --git a/unity/Assets/Scripts/Platform/PlatformServices.cs.meta b/unity/Assets/Scripts/Platform/PlatformServices.cs.metanew file mode 100644index 000000000..01b3809ea--- /dev/null+++ b/unity/Assets/Scripts/Platform/PlatformServices.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: ecfce43bf1324f818cbd4dd6470035bfdiff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex 1c9765b79..603b532ee 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -419,6 +419,9 @@ namespace Statecraft.Game.UI// is its two presses; a smoke run has none.end = Own(new EndScreenPresenter(root, bridge, text, newGame == null ? null : newGame.Press, show: !endClosed));endClosed = false;+ // The store's achievements (#2152): a no-op unless a Steam build set PlatformServices.Current. A smoke run (the+ // golden seed, scripted turns) is not the player's game, so it reports nothing.+ if (smoke == 0) Own(new AchievementReporter(bridge, () => PlatformServices.Current));// An outcome clip holds the pointer while it shows and in the frame it closes (the skipping click selects no hex).Func<Vector2, bool> overUi = p => opening?.HoldsThePointer == true || outcomes?.HoldsThePointer == true || UiPointer.IsOverUi(root.panel, p, Screen.height);diff --git a/unity/Assets/Tests/EditMode/AchievementRulesTests.cs b/unity/Assets/Tests/EditMode/AchievementRulesTests.csnew file mode 100644index 000000000..8e53b6bee--- /dev/null+++ b/unity/Assets/Tests/EditMode/AchievementRulesTests.cs@@ -0,0 +1,229 @@+#nullable enable+using System;+using System.Linq;+using System.Text.RegularExpressions;+using NUnit.Framework;+using Statecraft.Game;+using Statecraft.Game.UI;+using Statecraft.Sim;+using UnityEditor;+using UnityEngine;+using UnityEngine.TestTools;++/// <summary>The five achievements (#2152; owner Q5 "Five (Recommended)"): one per objective in content/objectives.yaml and+/// one for finishing the campaign, read from the game state only; the reporter unlocks each once.</summary>+public class AchievementRulesTests+{+ static readonly Content C = ContentLoader.Load(Paths.Content);+ static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);++ static GameState NewState() => GameSession.New(C, GoldenRun.Seed, Mode.Historical).State;++ [TearDown] public void Reset() => PlatformServices.Current = null!;++ [Test] public void Every_objective_in_content_has_an_achievement()+ {+ CollectionAssert.AreEquivalent(C.Objectives.Select(o => o.Id), AchievementRules.ForObjective.Keys);+ }++ [Test] public void The_api_names_are_the_ones_the_owner_enters_in_steamworks()+ {+ CollectionAssert.AreEquivalent(new[] { "OBJ_RAILWAY", "OBJ_BURMA_ROAD", "OBJ_YISHUVIM", "OBJ_ABSORB_IMMIGRANTS" },+ AchievementRules.ForObjective.Values);+ Assert.AreEqual("OBJ_RAILWAY", AchievementRules.ForObjective["railway"]);+ Assert.AreEqual("OBJ_BURMA_ROAD", AchievementRules.ForObjective["burma_road"]);+ Assert.AreEqual("OBJ_YISHUVIM", AchievementRules.ForObjective["yishuvim"]);+ Assert.AreEqual("OBJ_ABSORB_IMMIGRANTS", AchievementRules.ForObjective["absorb_immigrants"]);+ Assert.AreEqual("CAMPAIGN_DONE", AchievementRules.CampaignDone);+ }++ [Test] public void A_new_game_has_earned_nothing()+ {+ CollectionAssert.IsEmpty(AchievementRules.Earned(NewState()));+ }++ [Test] public void A_completed_objective_earns_its_achievement()+ {+ var s = NewState();+ s.Objectives["railway"] = new DateTime(1949, 3, 15);+ CollectionAssert.AreEqual(new[] { "OBJ_RAILWAY" }, AchievementRules.Earned(s));+ }++ [Test] public void Earned_is_sorted_ordinally()+ {+ var s = NewState();+ s.Objectives["yishuvim"] = new DateTime(1949, 3, 15);+ s.Objectives["absorb_immigrants"] = new DateTime(1949, 4, 15);+ s.GameOver = GameOverCodes.MvpEnded;+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_ABSORB_IMMIGRANTS", "OBJ_YISHUVIM" }, AchievementRules.Earned(s));+ }++ [Test] public void Reaching_the_last_turn_earns_the_campaign_but_a_defeat_does_not()+ {+ var s = NewState();+ s.GameOver = GameOverCodes.MvpEnded;+ CollectionAssert.Contains(AchievementRules.Earned(s), AchievementRules.CampaignDone);+ foreach (var other in new[] { GameOverCodes.DefeatWar, GameOverCodes.DefeatEconomy, GameOverCodes.CoalitionCollapse, GameOverCodes.EraEnded })+ {+ s.GameOver = other;+ CollectionAssert.DoesNotContain(AchievementRules.Earned(s), AchievementRules.CampaignDone, other);+ }+ }++ /// <summary>A finished game with the railway done, as a loaded save holds it.</summary>+ static GameSession Finished(params string[] done)+ {+ var session = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ foreach (var id in done) session.State.Objectives[id] = new DateTime(1949, 3, 15);+ session.State.GameOver = GameOverCodes.MvpEnded;+ return session;+ }++ [Test] public void The_reporter_unlocks_each_achievement_once_even_over_a_loaded_finished_game()+ {+ var fake = new FakePlatform();+ var bridge = new SimBridge(Finished("railway"), En);+ using (new AchievementReporter(bridge, () => fake))+ {+ bridge.Replace(Finished("railway")); // Changed: the same finished game loaded again+ bridge.Replace(Finished("railway")); // Changed again+ }+ Assert.AreEqual(1, fake.Unlocks.Count);+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_RAILWAY" }, fake.Unlocks[0]);+ }++ [Test] public void The_reporter_passes_only_what_is_new_and_stops_when_disposed()+ {+ var fake = new FakePlatform();+ var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), En);+ var reporter = new AchievementReporter(bridge, () => fake);+ Assert.AreEqual(0, fake.Unlocks.Count, "a new game reports nothing");+ bridge.Replace(Finished("railway"));+ bridge.Replace(Finished("railway", "burma_road"));+ reporter.Dispose();+ bridge.Replace(Finished("railway", "burma_road", "yishuvim"));+ Assert.AreEqual(2, fake.Unlocks.Count);+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_RAILWAY" }, fake.Unlocks[0]);+ CollectionAssert.AreEqual(new[] { "OBJ_BURMA_ROAD" }, fake.Unlocks[1]);+ }++ /// <summary>A store that fails (Steam not running, say) never stops the game starting, and what it failed to take is+ /// offered again on the next change.</summary>+ [Test] public void A_failing_store_is_logged_and_offered_the_same_achievements_again()+ {+ var fake = new FakePlatform();+ bool fail = true;+ IPlatformServices Services() => fail ? new ThrowingPlatform() : fake;+ var bridge = new SimBridge(Finished("railway"), En);+ LogAssert.Expect(LogType.Exception, new Regex("store offline"));+ using (new AchievementReporter(bridge, Services))+ {+ fail = false;+ bridge.Replace(Finished("railway"));+ }+ Assert.AreEqual(1, fake.Unlocks.Count);+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_RAILWAY" }, fake.Unlocks[0]);+ }++ /// <summary>Review round (k2 C3): a store that stays down is retried on every change but logged once, not on every+ /// change for the rest of the session.</summary>+ [Test] public void A_store_that_stays_down_is_logged_once_until_it_recovers()+ {+ var fake = new FakePlatform();+ bool fail = true;+ IPlatformServices Services() => fail ? new ThrowingPlatform() : fake;+ var bridge = new SimBridge(Finished("railway"), En);+ LogAssert.Expect(LogType.Exception, new Regex("store offline"));+ using (new AchievementReporter(bridge, Services))+ {+ bridge.Replace(Finished("railway"));+ bridge.Replace(Finished("railway"));+ fail = false;+ bridge.Replace(Finished("railway"));+ }+ Assert.AreEqual(1, fake.Unlocks.Count);+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_RAILWAY" }, fake.Unlocks[0]);+ }++ /// <summary>Review round (k2 C1): reading the rules can never break the game's start or a change: a failure there is+ /// logged like a store's, and the next change reports.</summary>+ [Test] public void A_rule_that_throws_is_logged_and_never_escapes()+ {+ var fake = new FakePlatform();+ var broken = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ broken.State.Objectives = null!; // reading it throws+ var bridge = new SimBridge(broken, En);+ LogAssert.Expect(LogType.Exception, new Regex("NullReferenceException"));+ using (new AchievementReporter(bridge, () => fake))+ bridge.Replace(Finished("railway"));+ Assert.AreEqual(1, fake.Unlocks.Count);+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_RAILWAY" }, fake.Unlocks[0]);+ }++ /// <summary>Review round (k2 C5): with the no-op store (web, itch.io, plain desktop) the rules are not even read.</summary>+ [Test] public void With_the_no_op_store_the_rules_are_never_read()+ {+ var broken = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ broken.State.Objectives = null!; // reading it would throw, and an unexpected logged exception fails the test+ var bridge = new SimBridge(broken, En);+ using (new AchievementReporter(bridge, () => NullPlatformServices.Instance))+ bridge.Replace(broken);+ }++ /// <summary>Review round (k2 H2): the real End turn that reaches the last day (rules.yaml mvp.end) earns the campaign.+ /// The game is played to its last turn as the sim's CutoverTests plays it (HistoricalAI's orders), so its state is real.</summary>+ [Test] public void The_turn_that_reaches_the_last_day_earns_the_campaign()+ {+ var fake = new FakePlatform();+ var session = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ for (int turn = 0; Simulation.TurnEnd(C, session.State) < C.End && session.State.GameOver == null && turn < 1000; turn++)+ session.Step(HistoricalAI.Commands(C, session.State));+ Assert.IsNull(session.State.GameOver, "precondition: the game is on, one turn before its end");+ var bridge = new SimBridge(session, En);+ using (new AchievementReporter(bridge, () => fake))+ {+ Assert.AreEqual(0, fake.Unlocks.Count, "nothing before the turn");+ bridge.EndTurn();+ Assert.AreEqual(GameOverCodes.MvpEnded, bridge.TurnStart.GameOver, "precondition: the turn ended the game on its last day");+ }+ var all = fake.Unlocks.SelectMany(u => u).ToList();+ CollectionAssert.Contains(all, AchievementRules.CampaignDone);+ CollectionAssert.AllItemsAreUnique(all);+ }++ /// <summary>Review round (k2): a defeat reached by real End turns earns the objectives done but never the campaign.</summary>+ [Test] public void A_defeat_at_a_turn_end_earns_the_objectives_but_never_the_campaign()+ {+ var fake = new FakePlatform();+ var session = GameSession.New(C, GoldenRun.Seed, Mode.Historical);+ var s = session.State;+ s.Objectives["railway"] = new DateTime(1948, 6, 1);+ s.Debt = 1e12; s.Food = 0; s.FxReserves = -1e12; s.ActiveSituations.Add(EconomySystem.FxCrisis); // as EndScreenTests.Exhausted+ var bridge = new SimBridge(session, En);+ using (new AchievementReporter(bridge, () => fake))+ for (int turn = 0; turn < 3 && bridge.TurnStart.GameOver == null; turn++) bridge.EndTurn();+ Assert.AreEqual(GameOverCodes.DefeatEconomy, bridge.TurnStart.GameOver, "precondition: three exhausted turn ends");+ CollectionAssert.AreEquivalent(new[] { "OBJ_RAILWAY" }, fake.Unlocks.SelectMany(u => u));+ }++ sealed class ThrowingPlatform : IPlatformServices+ {+ public string Name => "throwing";+ public void Unlock(System.Collections.Generic.IReadOnlyCollection<string> achievementIds) => throw new InvalidOperationException("store offline");+ }++ /// <summary>A store set after the game started (a late Steam start) still gets what was earned before it: the no-op+ /// store takes nothing, so nothing counts as reported to it.</summary>+ [Test] public void The_reporter_asks_for_the_current_services_each_time()+ {+ var fake = new FakePlatform();+ var bridge = new SimBridge(Finished("railway"), En);+ using (new AchievementReporter(bridge, () => PlatformServices.Current))+ {+ PlatformServices.Current = fake;+ bridge.Replace(Finished("railway", "burma_road"));+ }+ Assert.AreEqual(1, fake.Unlocks.Count);+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_BURMA_ROAD", "OBJ_RAILWAY" }, fake.Unlocks[0]);+ }+}diff --git a/unity/Assets/Tests/EditMode/AchievementRulesTests.cs.meta b/unity/Assets/Tests/EditMode/AchievementRulesTests.cs.metanew file mode 100644index 000000000..c4ff99d40--- /dev/null+++ b/unity/Assets/Tests/EditMode/AchievementRulesTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 9b2951cda6e243d898ca3e1ec63a7ad6diff --git a/unity/Assets/Tests/EditMode/GameSceneTests.cs b/unity/Assets/Tests/EditMode/GameSceneTests.csindex c3abbe9d2..4fd249d40 100644--- a/unity/Assets/Tests/EditMode/GameSceneTests.cs+++ b/unity/Assets/Tests/EditMode/GameSceneTests.cs@@ -655,6 +655,49 @@ public class GameSceneTestsAssert.AreEqual(DisplayStyle.Flex, Ui.Q("toast").style.display.value);}+ /// <summary>#2152: the game reports earned achievements to the store set in PlatformServices.Current (a Steam build's).</summary>+ [Test]+ public void TheGameReportsAchievementsToTheCurrentStore()+ {+ var fake = new FakePlatform();+ PlatformServices.Current = fake;+ try+ {+ var root = Boot();+ Assert.AreEqual(0, fake.Unlocks.Count, "a new game has earned nothing");+ var finished = GameSession.New(Inputs.Content, GoldenRun.Seed, Mode.Historical);+ finished.State.Objectives["railway"] = new DateTime(1949, 3, 15);+ finished.State.GameOver = GameOverCodes.MvpEnded;+ root.Bridge!.Replace(finished);+ Assert.AreEqual(1, fake.Unlocks.Count);+ CollectionAssert.AreEqual(new[] { "CAMPAIGN_DONE", "OBJ_RAILWAY" }, fake.Unlocks[0]);+ }+ finally { PlatformServices.Current = null!; }+ }++ /// <summary>Review round (k2): a smoke run (the golden seed, scripted turns) is not the player's game: it reports nothing.</summary>+ [Test]+ public void ASmokeRunReportsNoAchievements()+ {+ var fake = new FakePlatform();+ PlatformServices.Current = fake;+ try+ {+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);+ Object.FindFirstObjectByType<MapScene>().Build(Inputs.Map);+ var root = Object.FindFirstObjectByType<GameRoot>();+ root.Store = new SaveStore(saveDir);+ LogAssert.Expect(LogType.Warning, "SMOKE FAIL the smoke run needs play mode or a player");+ root.Begin(Inputs, 5);+ var finished = GameSession.New(Inputs.Content, GoldenRun.Seed, Mode.Historical);+ finished.State.Objectives["railway"] = new DateTime(1949, 3, 15);+ finished.State.GameOver = GameOverCodes.MvpEnded;+ root.Bridge!.Replace(finished);+ Assert.AreEqual(0, fake.Unlocks.Count);+ }+ finally { PlatformServices.Current = null!; }+ }+[Test]public void AppendAddsALineOrShowsItAlone(){diff --git a/unity/Assets/Tests/EditMode/PlatformServicesTests.cs b/unity/Assets/Tests/EditMode/PlatformServicesTests.csnew file mode 100644index 000000000..d9895e63f--- /dev/null+++ b/unity/Assets/Tests/EditMode/PlatformServicesTests.cs@@ -0,0 +1,38 @@+#nullable enable+using System.Collections.Generic;+using System.Linq;+using NUnit.Framework;+using Statecraft.Game;++/// <summary>The store-neutral seam (#2152): a no-op by default, so web, itch.io and plain desktop builds never talk to a+/// store; a Steam build (#2154) sets its own services.</summary>+public class PlatformServicesTests+{+ [TearDown] public void Reset() => PlatformServices.Current = null!;++ [Test] public void The_default_is_the_no_op_services()+ {+ Assert.AreSame(NullPlatformServices.Instance, PlatformServices.Current);+ Assert.AreEqual("none", PlatformServices.Current.Name);+ }++ [Test] public void Setting_null_restores_the_default()+ {+ PlatformServices.Current = new FakePlatform();+ PlatformServices.Current = null!;+ Assert.AreSame(NullPlatformServices.Instance, PlatformServices.Current);+ }++ [Test] public void The_no_op_unlock_accepts_anything()+ {+ Assert.DoesNotThrow(() => NullPlatformServices.Instance.Unlock(new[] { "OBJ_RAILWAY" }));+ }+}++/// <summary>A store that records every Unlock call (AchievementRulesTests uses it too).</summary>+internal sealed class FakePlatform : IPlatformServices+{+ public readonly List<string[]> Unlocks = new List<string[]>();+ public string Name => "fake";+ public void Unlock(IReadOnlyCollection<string> achievementIds) => Unlocks.Add(achievementIds.ToArray());+}diff --git a/unity/Assets/Tests/EditMode/PlatformServicesTests.cs.meta b/unity/Assets/Tests/EditMode/PlatformServicesTests.cs.metanew file mode 100644index 000000000..066e7d581--- /dev/null+++ b/unity/Assets/Tests/EditMode/PlatformServicesTests.cs.meta@@ -0,0 +1,2 @@+fileFormatVersion: 2+guid: 935a354b154c4c5bb4497264150f4e77