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.

fix(ui): the top bar's change is the difference of its two shown values (fix round 3, m-1)

eyalgolan56993ebbfafe
diff --git a/unity/Assets/Scripts/UI/HudModel.cs b/unity/Assets/Scripts/UI/HudModel.cs
index 8b7a6adff..88ab6cc20 100644
--- a/unity/Assets/Scripts/UI/HudModel.cs
+++ b/unity/Assets/Scripts/UI/HudModel.cs
@@ -41,8 +41,9 @@ namespace Statecraft.Game.UI
{
var value = PlayerText.Percent(now); // the one formatter (fix round 2, N4)
if (before == null) return new Meter(value, "", 0);
- var delta = PlayerText.PercentChange(now - before.Value, 0);
- return delta == "0%" ? new Meter(value, "", 0) : new Meter(value, delta, Math.Sign(now - before.Value));
+ // The difference of the two shown values, so the change always agrees with them (fix round 3, m-1).
+ var points = PlayerText.ShownPoints(now) - PlayerText.ShownPoints(before.Value);
+ return points == 0 ? new Meter(value, "", 0) : new Meter(value, PlayerText.PercentChangeShown(before.Value, now), Math.Sign(points));
}
Meter People(double now, double? before)
{
diff --git a/unity/Assets/Tests/EditMode/HudTests.cs b/unity/Assets/Tests/EditMode/HudTests.cs
index bc1a7b8b4..bb70ee32b 100644
--- a/unity/Assets/Tests/EditMode/HudTests.cs
+++ b/unity/Assets/Tests/EditMode/HudTests.cs
@@ -418,4 +418,24 @@ public class HudTests
}
finally { nav.Dispose(); }
}
+
+ /// <summary>Fix round 3 (m-1): the top bar's change agrees with the two values it shows.</summary>
+ [Test]
+ public void TheShownChangeAgreesWithTheShownValues()
+ {
+ var bridge = NewBridge();
+ bridge.EndTurn();
+ var prev = bridge.Session.Previous!;
+ var now = bridge.State;
+ now.Indicators["security"] = 0.634; prev.Indicators["security"] = 0.626; // "63%" -> "63%"
+ var m = HudModel.From(bridge, Text);
+ Assert.AreEqual("63%", m.Security.Value);
+ Assert.AreEqual("", m.Security.Delta, "no change shown between two equal shown values");
+ Assert.AreEqual(0, m.Security.Sign);
+ now.Indicators["security"] = 0.626; prev.Indicators["security"] = 0.624; // "62%" -> "63%"
+ m = HudModel.From(bridge, Text);
+ Assert.AreEqual("63%", m.Security.Value);
+ Assert.AreEqual("+1%", m.Security.Delta);
+ Assert.AreEqual(1, m.Security.Sign);
+ }
}