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.

GDD 0.3: no Attention in the UI and CLI under gdd-0.3 (2/2a) (Refs #1688) (#1750)

Eyal Golan88a462dd0531
diff --git a/changelog.d/1688-gdd03-attention-ui.md b/changelog.d/1688-gdd03-attention-ui.md
new file mode 100644
index 000000000..64ca9959a
--- /dev/null
+++ b/changelog.d/1688-gdd03-attention-ui.md
@@ -0,0 +1 @@
+- Omit Attention from the HUD, order costs, capture previews and CLI under gdd-0.3, while preserving older rulesets and other order requirements.
diff --git a/sim/Statecraft.Cli/Program.cs b/sim/Statecraft.Cli/Program.cs
index 153ee26ee..4dd91c707 100644
--- a/sim/Statecraft.Cli/Program.cs
+++ b/sim/Statecraft.Cli/Program.cs
@@ -138,7 +138,8 @@ return 0;
static void Briefing(Content c, GameState s)
{
var gov = Offices.Government(c, s.Date);
- Console.WriteLine($"== {s.Date:yyyy-MM-dd} | turn {s.Turn} | {gov?.Name} | security level {s.Rung} | attention {s.Attention:0.0}");
+ var attention = c.UsesAttention ? $" | attention {s.Attention:0.0}" : "";
+ Console.WriteLine($"== {s.Date:yyyy-MM-dd} | turn {s.Turn} | {gov?.Name} | security level {s.Rung}{attention}");
foreach (var id in s.PendingEvents)
{
var e = c.Events.First(x => x.Id == id);
diff --git a/sim/Statecraft.Sim.Tests/NoAttentionCliTests.cs b/sim/Statecraft.Sim.Tests/NoAttentionCliTests.cs
new file mode 100644
index 000000000..39a832beb
--- /dev/null
+++ b/sim/Statecraft.Sim.Tests/NoAttentionCliTests.cs
@@ -0,0 +1,33 @@
+using System.Diagnostics;
+using Statecraft.Sim;
+
+public class NoAttentionCliTests
+{
+ [Theory]
+ [InlineData("legacy", true)]
+ [InlineData("gdd-0.1", true)]
+ [InlineData("gdd-0.3", false)]
+ public async Task BriefingOnlyShowsAttentionWhenTheRulesetUsesIt(string ruleset, bool attention)
+ {
+ var files = ruleset == "legacy" ? new Dictionary<string, string>() : Fixture.Gdd();
+ if (ruleset == "gdd-0.3")
+ {
+ files["eras.yaml"] = files["eras.yaml"].Replace("loop: gdd", "loop: gdd, ruleset: gdd-0.3");
+ files[Gdd03BalanceCatalogue.FileName] = File.ReadAllText(Path.Combine(RealContentTests.ContentRoot(), Gdd03BalanceCatalogue.FileName));
+ }
+ var info = new ProcessStartInfo("dotnet") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false };
+ foreach (var arg in new[] { typeof(Statecraft.Cli.InputParse).Assembly.Location, "--content", Fixture.Write(files), "--auto", "historical", "--turns", "1" }) info.ArgumentList.Add(arg);
+ // Runs the compiled CLI, never a nested build/test or a build server. The test host owns the shared machine lock.
+ using var child = Process.Start(info)!;
+ var stdout = child.StandardOutput.ReadToEndAsync(); var stderr = child.StandardError.ReadToEndAsync();
+ using var limit = new CancellationTokenSource(TimeSpan.FromSeconds(60));
+ try { await child.WaitForExitAsync(limit.Token); }
+ catch (OperationCanceledException) { child.Kill(entireProcessTree: true); throw; }
+ var output = await stdout; var error = await stderr;
+ Assert.True(child.ExitCode == 0, output + error);
+ var briefing = output.Split('\n').Single(x => x.StartsWith("== ", StringComparison.Ordinal));
+ Assert.Equal(attention, briefing.Contains(" | attention ", StringComparison.Ordinal));
+ Assert.Contains(" | security level ", briefing);
+ if (attention) Assert.EndsWith(" | attention 3.0", briefing.TrimEnd('\r'));
+ }
+}
diff --git a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs
index ef55b803e..5f4f0ea99 100644
--- a/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs
+++ b/unity/Assets/Scripts/UI/CaptureDialogPresenter.cs
@@ -188,7 +188,7 @@ namespace Statecraft.Game.UI
var stem = ending ? EndStem : CaptureStem;
var lines = new List<string>();
void Line(string caption, string change) => lines.Add(t.Format("report.line", t[caption], change));
- if (p.Attention != 0) Line("capture.caption.attention", t.Format("capture.delta_attention", p.Attention));
+ if (p.Attention is double attention && attention != 0) Line("capture.caption.attention", t.Format("capture.delta_attention", attention));
var money = Math.Round(p.Money - p.Debt, 1, MidpointRounding.AwayFromZero);
if (money != 0) Line("hud.caption.treasury", PlayerText.MoneyChange(c, "treasury", money));
if (p.Food != 0) Line("capture.caption.food", t.Format("capture.delta_count", p.Food));
diff --git a/unity/Assets/Scripts/UI/EventCardPresenter.cs b/unity/Assets/Scripts/UI/EventCardPresenter.cs
index 04871d9c9..4b57e31d8 100644
--- a/unity/Assets/Scripts/UI/EventCardPresenter.cs
+++ b/unity/Assets/Scripts/UI/EventCardPresenter.cs
@@ -233,7 +233,7 @@ namespace Statecraft.Game.UI
// does. When the turn's Attention left cannot pay, every option would be refused (#1034, #1043): the options are
// greyed out with their price, the card says End Turn hands it to its minister, and End Turn is highlighted.
var answer = Shown == null ? null : new ChooseEventOption(Shown.Id, "");
- var price = answer == null ? 0 : bridge.Price(answer);
+ var price = answer == null ? null : bridge.Price(answer);
var unpaid = answer != null && !bridge.CanPay(answer);
endTurn?.EnableInClassList(EndTurnWaitingClass, !hiddenInCapture && unpaid);
if (Shown == null || Collapsed) video?.Stop();
@@ -281,7 +281,7 @@ namespace Statecraft.Game.UI
{
var option = o;
var label = Local(Cabinet.Fill(c, s, o.Text, date), o.TextHe);
- var b = new Button(() => Choose(e, option)) { name = "option-" + o.Id, text = price > 0 ? text.Format("event.option_cost", label, price) : label };
+ var b = new Button(() => Choose(e, option)) { name = "option-" + o.Id, text = price is double cost && cost > 0 ? text.Format("event.option_cost", label, cost) : label };
b.AddToClassList(OptionClass);
b.SetEnabled(!unpaid);
options.Add(b);
diff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.cs
index 60c9c66c9..82843d2c7 100644
--- a/unity/Assets/Scripts/UI/GameRoot.cs
+++ b/unity/Assets/Scripts/UI/GameRoot.cs
@@ -948,7 +948,9 @@ namespace Statecraft.Game.UI
for (int guard = 0; card.Shown != null; guard++)
{
var shown = card.Shown;
- if (bridge.AttentionLeft + 1e-9 < AttentionSystem.Cost(bridge.Content, bridge.State, new ChooseEventOption(shown.Id, "").Kind)) break;
+ // Rulesets with Attention keep the smoke's own pool check unchanged; gdd-0.3 has no pool to run out of (#1688).
+ if (bridge.Content.UsesAttention
+ && bridge.AttentionLeft!.Value + 1e-9 < AttentionSystem.Cost(bridge.Content, bridge.State, new ChooseEventOption(shown.Id, "").Kind)) break;
var option = root.Q<VisualElement>("event-options")?.Q<Button>();
if (option == null || guard >= 50) { log(FormattableString.Invariant($"SMOKE FAIL event {shown.Id} has no option to press")); yield break; }
if (!Press(option, log)) yield break;
diff --git a/unity/Assets/Scripts/UI/GddHexPanel.cs b/unity/Assets/Scripts/UI/GddHexPanel.cs
index 69cd6cdcf..6b71be80e 100644
--- a/unity/Assets/Scripts/UI/GddHexPanel.cs
+++ b/unity/Assets/Scripts/UI/GddHexPanel.cs
@@ -120,7 +120,9 @@ namespace Statecraft.Game.UI
Button(workers, "city-workers-more", "+", () => Workers(bridge, id, city.Employed, target + 1)).SetEnabled(target < max);
// The Assign order's Attention price (the queue's, at this turn's start) and when it applies (playtest B7): the
// Jobs line stays the sim's actual count until End turn. Changing a queued target does not buy another order.
- Line(host, "city-workers-cost", text.Format("city.workers_cost", bridge.Price(new AssignWorkers(id, "job", target))));
+ Line(host, "city-workers-cost", bridge.Content.UsesAttention
+ ? text.Format("city.workers_cost", bridge.Price(new AssignWorkers(id, "job", target))!.Value)
+ : text.Format("city.workers_ordered", Groups(text, target)));
// Train, for each facility the city has (Training.HasFacility: its own, D-D5, or a built camp site's, R-CAMP-001):
// each press orders one more group; R-TRAIN-001 takes only civilians without work, and the sim counts every track's
diff --git a/unity/Assets/Scripts/UI/HudModel.cs b/unity/Assets/Scripts/UI/HudModel.cs
index 5df643758..0904a0896 100644
--- a/unity/Assets/Scripts/UI/HudModel.cs
+++ b/unity/Assets/Scripts/UI/HudModel.cs
@@ -120,7 +120,7 @@ namespace Statecraft.Game.UI
Year = s.Date.Year.ToString(System.Globalization.CultureInfo.InvariantCulture),
Turn = t.Format("hud.turn", s.Turn),
Date = t.Format("hud.date", Statecraft.Game.Map.Control1948.DateText(s.Date, k => t[k])), // the UI's language (#687)
- Attention = t.Format("hud.attention", b.AttentionLeft, c.RulesAt(s.Date).AttentionPerTurn),
+ Attention = c.UsesAttention ? t.Format("hud.attention", b.AttentionLeft!.Value, c.RulesAt(s.Date).AttentionPerTurn) : "",
SecurityLevel = t.Format("hud.level", s.Rung),
Score = c.IsGdd ? t.Format("hud.score", s.Score) : "", // the GDD loop only (#380); PR 6 moves it
Treasury = Money("treasury", s.Treasury - s.Debt, prev == null ? (double?)null : prev.Treasury - prev.Debt),
diff --git a/unity/Assets/Scripts/UI/HudPresenter.cs b/unity/Assets/Scripts/UI/HudPresenter.cs
index 1a52e72ac..6f773edd1 100644
--- a/unity/Assets/Scripts/UI/HudPresenter.cs
+++ b/unity/Assets/Scripts/UI/HudPresenter.cs
@@ -300,7 +300,7 @@ namespace Statecraft.Game.UI
const float TurnBoxPx = 150f, CaptionMaxPx = 120f, PlateWidthPx = 230f;
// The button keeps its stylesheet font; only the attention line grows with the text floor.
float TurnBoxWidth => UnityEngine.Mathf.Max(bridge.NeedsOrders.Count > 0 ? 230f : TurnBoxPx,
- TurnBoxPx * smallTextSize / SmallTextPx);
+ bridge.Content.UsesAttention ? TurnBoxPx * smallTextSize / SmallTextPx : TurnBoxPx);
/// <summary>The widest date line's width per px of font size, with a little to spare: the Hebrew 31 October 1956 is
/// about 7.8 times its size (196 px at 25 px), the English "30 September 1956" 7.2 (TopBarScoreLayoutTests.WorstDate).</summary>
const float DateLinePerPx = 8f;
@@ -452,7 +452,7 @@ namespace Statecraft.Game.UI
var raised = FloorRaises(width);
var tierWidth = raised ? width - FloorGrowth() : width; // the owner's text floor needs room (#624)
bar.EnableInClassList(CompactClass, tierWidth < CompactBelowPx);
- hudRoot.EnableInClassList(NarrowClass, tierWidth < NarrowBelowPx || raised && smallTextSize > OneRowSmallMaxPx);
+ hudRoot.EnableInClassList(NarrowClass, tierWidth < NarrowBelowPx || bridge.Content.UsesAttention && raised && smallTextSize > OneRowSmallMaxPx);
bar.EnableInClassList(CaptionLineClass, hudRoot.ClassListContains(NarrowClass) && !bar.ClassListContains(CompactClass));
captionFitWrap = raised && width >= TwoRowBelowPx && bar.ClassListContains(CompactClass) && CaptionsNeedAnotherRow(width);
hudRoot.EnableInClassList(TwoRowClass, width < TwoRowBelowPx || captionFitWrap);
@@ -488,6 +488,11 @@ namespace Statecraft.Game.UI
public void Render()
{
var m = HudModel.From(bridge, text);
+ var attention = root.Q<Label>("attention");
+ attention.style.display = bridge.Content.UsesAttention ? DisplayStyle.Flex : DisplayStyle.None;
+ attention.pickingMode = bridge.Content.UsesAttention ? PickingMode.Position : PickingMode.Ignore;
+ attention.focusable = false;
+ attention.tooltip = "";
Set("year", m.Year); Set("turn", m.Turn); Set("date", m.Date); Set("attention", m.Attention);
Set("security-level", m.SecurityLevel);
var score = root.Q<Label>("score"); // the GDD loop only (#380): hidden when HudModel gives none
diff --git a/unity/Assets/Scripts/UI/SimBridge.cs b/unity/Assets/Scripts/UI/SimBridge.cs
index fa31b6637..18a37e256 100644
--- a/unity/Assets/Scripts/UI/SimBridge.cs
+++ b/unity/Assets/Scripts/UI/SimBridge.cs
@@ -88,14 +88,14 @@ namespace Statecraft.Game.UI
_ => c.Kind,
};
- /// <summary>The order's Attention price at this turn's prices: what <see cref="Queue"/> charges and the card shows.</summary>
- public double Price(Command c) => AttentionSystem.Price(Content, TurnStart, c);
+ /// <summary>The order's Attention price, or null when the ruleset has no Attention: what <see cref="Queue"/> charges and the card shows.</summary>
+ public double? Price(Command c) => Content.UsesAttention ? AttentionSystem.Price(Content, TurnStart, c) : null;
/// <summary>Whether the Attention left pays for the order (a queued order with its key is refunded first): the one
/// check <see cref="Queue"/> refuses on, so the event card (#1034) and a refusal can never disagree.</summary>
- public bool CanPay(Command c) => Price(c) <= LeftFor(c) + 1e-9;
+ public bool CanPay(Command c) => !Content.UsesAttention || Price(c)!.Value <= LeftFor(c) + 1e-9;
- double LeftFor(Command c) { var old = QueuedLike(c); return AttentionLeft + (old != null ? Price(old) : 0); }
+ double LeftFor(Command c) { var old = QueuedLike(c); return AttentionLeft!.Value + (old != null ? Price(old)!.Value : 0); }
/// <summary>Who End Turn hands the event to with the orders queued now (Simulation.DelegatedTo), or null for the
/// cabinet: an appointment queued this turn is in office by then (#1034).</summary>
@@ -109,8 +109,8 @@ namespace Statecraft.Game.UI
/// (EconomySystem.Unsubmitted): the side menu's Budget badge (#1109).</summary>
public bool BudgetUnsubmitted(IReadOnlyDictionary<string, double> draft) => EconomySystem.Unsubmitted(Content, TurnStart, draft, deferred);
- /// <summary>Attention left after paying for the queued orders at this turn's prices.</summary>
- public double AttentionLeft => AttentionSystem.Left(Content, TurnStart, All);
+ /// <summary>Attention left after queued orders, or null when the ruleset has no Attention.</summary>
+ public double? AttentionLeft => Content.UsesAttention ? AttentionSystem.Left(Content, TurnStart, All) : null;
/// <summary>The queued order with this key, or null.</summary>
public Command? QueuedLike(Command c) => deferred.FirstOrDefault(q => Key(q) == Key(c));
@@ -248,10 +248,10 @@ namespace Statecraft.Game.UI
return null;
}
if (c is AllocateBudget ab) c = new AllocateBudget(new Dictionary<string, double>(ab.Shares)); // a snapshot: later edits to the caller's dictionary must not change the order
- if (!CanPay(c))
+ if (Content.UsesAttention && !CanPay(c))
{
Notify(RefusedForAttention); // presentation only: a failing listener never changes the refusal
- return Refuse(text.Format("order.no_attention", Price(c), LeftFor(c)));
+ return Refuse(text.Format("order.no_attention", Price(c)!.Value, LeftFor(c)));
}
// Send home takes the unit's place in the queue: an order queued for it earlier (a reinforcement) is withdrawn, and
// its Attention refunded, so End turn never acts on a unit it sends home in the same turn. Withdrawing only refunds,
diff --git a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs
index 45426251a..b9474afe7 100644
--- a/unity/Assets/Tests/EditMode/CaptureDialogTests.cs
+++ b/unity/Assets/Tests/EditMode/CaptureDialogTests.cs
@@ -367,9 +367,9 @@ public class CaptureDialogTests
var shown = r.Root.Q<Label>("capture-preview-" + o.Outcome).text;
Assert.AreEqual(CaptureDialogPresenter.PreviewText(r.Bridge.Content, r.Bridge.State, o.Preview!, En), shown, $"{o.Outcome}: the helper's preview");
Assert.Less(o.Preview!.Attention, 0, "precondition: the sim charges Attention for the order");
- StringAssert.Contains(En.Format("report.line", En["capture.caption.attention"], En.Format("capture.delta_attention", o.Preview.Attention)), shown,
+ StringAssert.Contains(En.Format("report.line", En["capture.caption.attention"], En.Format("capture.delta_attention", o.Preview.Attention!.Value)), shown,
$"{o.Outcome}: the sim's own Attention change");
- Assert.AreEqual(-r.Bridge.Price(new ResolveCapture("lod", o.Outcome)), o.Preview.Attention, 1e-9, "the order's price at this turn's prices");
+ Assert.AreEqual(-r.Bridge.Price(new ResolveCapture("lod", o.Outcome))!.Value, o.Preview.Attention!.Value, 1e-9, "the order's price at this turn's prices");
}
using var free = new Rig(Awaiting(C, "lod"));
yield return Frames(3);
@@ -657,8 +657,8 @@ public class CaptureDialogTests
var shown = r.Root.Q<Label>("capture-preview-" + o.Outcome).text;
Assert.AreEqual(CaptureDialogPresenter.PreviewText(r.Bridge.Content, r.Bridge.State, o.Preview!, En, ending: true), shown);
StringAssert.StartsWith(En["capture.end.changes"], shown);
- StringAssert.Contains(En.Format("report.line", En["capture.caption.attention"], En.Format("capture.delta_attention", o.Preview!.Attention)), shown);
- Assert.AreEqual(-r.Bridge.Price(new EndOccupation("lod", o.Outcome)), o.Preview.Attention, 1e-9);
+ StringAssert.Contains(En.Format("report.line", En["capture.caption.attention"], En.Format("capture.delta_attention", o.Preview!.Attention!.Value)), shown);
+ Assert.AreEqual(-r.Bridge.Price(new EndOccupation("lod", o.Outcome))!.Value, o.Preview.Attention!.Value, 1e-9);
}
using var free = new Rig(Ending(C, true, false, "lod"));
yield return Frames(3);
diff --git a/unity/Assets/Tests/EditMode/CityPanelTests.cs b/unity/Assets/Tests/EditMode/CityPanelTests.cs
index db43afdbb..7b09a96fe 100644
--- a/unity/Assets/Tests/EditMode/CityPanelTests.cs
+++ b/unity/Assets/Tests/EditMode/CityPanelTests.cs
@@ -1179,17 +1179,17 @@ public class CityPanelTests
var city = bridge.State.Cities["tel_aviv"]; int before = city.Employed;
Assert.Greater(before, 0, "precondition: there is a worker to remove");
Assert.IsNotNull(ui.Q<Label>("city-workers-cost"), "the order price and timing are visible, not only in a tooltip");
- Assert.AreEqual(text.Format("city.workers_cost", bridge.Price(new AssignWorkers("tel_aviv", "job", before))), ui.Q<Label>("city-workers-cost").text);
+ Assert.AreEqual(text.Format("city.workers_cost", bridge.Price(new AssignWorkers("tel_aviv", "job", before))!.Value), ui.Q<Label>("city-workers-cost").text);
UiTestKit.Press(ui.Q<Button>("city-workers-less"));
Assert.AreEqual(before, city.Employed, "queued work does not pretend the simulation already ran");
Assert.AreEqual(text.Format("city.workers_ordered", GddHexPanel.Groups(text, before - 1)), ui.Q<Label>("city-workers").text);
Assert.AreEqual(text.Format("city.jobs", before, city.JobSlots), ui.Q<Label>("city-jobs").text);
StringAssert.Contains("0.6", ui.Q<Label>("city-workers-cost").text, "the price as the HUD and the cards show Attention (one decimal)");
- double left = bridge.AttentionLeft;
+ double left = bridge.AttentionLeft!.Value;
if (before > 1)
{
UiTestKit.Press(ui.Q<Button>("city-workers-less"));
- Assert.AreEqual(left, bridge.AttentionLeft, 1e-9, "adjusting one queued assignment does not buy another order");
+ Assert.AreEqual(left, bridge.AttentionLeft!.Value, 1e-9, "adjusting one queued assignment does not buy another order");
UiTestKit.Press(ui.Q<Button>("city-workers-more"));
}
UiTestKit.Press(ui.Q<Button>("city-workers-more"));
diff --git a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs b/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs
index 9c1b91571..768ea5e21 100644
--- a/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs
+++ b/unity/Assets/Tests/EditMode/CityProjectPanelTests.cs
@@ -263,7 +263,7 @@ public class CityProjectPanelTests
Assert.IsFalse(bridge.CanPay(order), "precondition: no Attention left");
ui.Press("city-project-housing");
Assert.IsEmpty(bridge.Queued);
- Assert.AreEqual(new[] { En.Format("order.no_attention", bridge.Price(order), 0.0) }, refusals);
+ Assert.AreEqual(new[] { En.Format("order.no_attention", bridge.Price(order)!.Value, 0.0) }, refusals);
}
[Test]
diff --git a/unity/Assets/Tests/EditMode/EventCardTests.cs b/unity/Assets/Tests/EditMode/EventCardTests.cs
index df64f14af..b78e497a4 100644
--- a/unity/Assets/Tests/EditMode/EventCardTests.cs
+++ b/unity/Assets/Tests/EditMode/EventCardTests.cs
@@ -507,7 +507,7 @@ public class EventCardTests
var card = new EventCardPresenter(ui.Root, bridge, Text, null);
var appoint = new Appoint("defense_minister", "zisling");
Assert.IsNull(bridge.Queue(appoint));
- g.State.Attention = bridge.Price(appoint); // the rest of the turn's Attention is spent
+ g.State.Attention = bridge.Price(appoint)!.Value; // the rest of the turn's Attention is spent
card.Render();
Assert.AreEqual("You don't have enough Attention left to answer this turn. End the turn and the decision goes to Aharon Zisling.", ui.Q<Label>("event-delegate").text);
var turn = bridge.EndTurn();
diff --git a/unity/Assets/Tests/EditMode/SimBridgeGddTests.cs b/unity/Assets/Tests/EditMode/SimBridgeGddTests.cs
index e6b957502..654884e9b 100644
--- a/unity/Assets/Tests/EditMode/SimBridgeGddTests.cs
+++ b/unity/Assets/Tests/EditMode/SimBridgeGddTests.cs
@@ -7,6 +7,7 @@ using Statecraft.Game.UI;
using Statecraft.Sim;
using UnityEditor;
using UnityEngine;
+using UnityEngine.UIElements;
/// <summary>The GDD orders through the UI's queue (#380): AssignWorkers, Train and CancelTraining queue in the slice
/// (the real content, the GDD game since the cutover), an id the content or state does not have is refused before End Turn, an order replaces an earlier one
@@ -96,14 +97,14 @@ public class SimBridgeGddTests
{
var bridge = new SimBridge(GameSession.New(Slice, GoldenRun.Seed, Mode.Historical), Text);
var unit = bridge.NeedsOrders[0]; var other = bridge.NeedsOrders[1];
- var start = bridge.AttentionLeft;
+ var start = bridge.AttentionLeft!.Value;
var kept = new Reinforce(other, "tel_aviv", 1);
Assert.IsNull(bridge.Queue(new Reinforce(unit, "tel_aviv", 1)));
Assert.IsNull(bridge.Queue(kept));
var home = new UnitOrder(unit, Demobilization.SendHome);
Assert.IsNull(bridge.Queue(home));
CollectionAssert.AreEqual(new Command[] { kept, home }, bridge.Queued.ToList(), "the other unit's order stays");
- Assert.AreEqual(start - bridge.Price(kept) - bridge.Price(home), bridge.AttentionLeft, 1e-9, "the withdrawn order is refunded");
+ Assert.AreEqual(start - bridge.Price(kept)!.Value - bridge.Price(home)!.Value, bridge.AttentionLeft!.Value, 1e-9, "the withdrawn order is refunded");
}
[Test]
@@ -213,3 +214,169 @@ public class SimBridgeGddTests
Assert.AreEqual(0, b.Queued.Count);
}
}
+
+/// <summary>#1688: absence of Attention in gdd-0.3, with the old accounting retained in older rulesets.</summary>
+public class NoAttentionPresentationTests
+{
+ static Content Load(bool modern)
+ {
+ var dir = Paths.Content;
+ return ContentLoader.Load(rel =>
+ {
+ var path = System.IO.Path.Combine(dir, rel);
+ if (!System.IO.File.Exists(path)) return null;
+ var value = System.IO.File.ReadAllText(path);
+ return modern && rel == "eras.yaml" ? value.Replace("loop: gdd", "loop: gdd, ruleset: gdd-0.3") : value;
+ }, System.IO.Directory.GetFiles(System.IO.Path.Combine(dir, "events"), "*.yaml").Select(f => "events/" + System.IO.Path.GetFileName(f)));
+ }
+ static UiText Text(bool he) => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(he ? UiPaths.StringsHebrew : UiPaths.Strings).text);
+ static SimBridge Bridge(bool modern, bool he = false)
+ {
+ var c = Load(modern);
+ var b = new SimBridge(GameSession.New(c, GoldenRun.Seed, Mode.Historical), Text(he));
+ if (modern)
+ {
+ // Any accidental obsolete price read must fail, rather than silently reading a plausible zero.
+ foreach (var r in c.EraRules.Values.Append(c.Rules))
+ { r.AttentionCost.Clear(); r.AttentionPerTurn = double.NaN; r.RungAttentionStep = double.NaN; }
+ b.State.Attention = double.NaN;
+ }
+ return b;
+ }
+
+ [Test]
+ public void BridgeHasNoPoolOrPriceAndStillReplacesAndWithdrawsOrders()
+ {
+ var b = Bridge(true);
+ var first = new SetPolicy("rationing", .5);
+ var next = new SetPolicy("rationing", .7);
+ Assert.IsNull(b.AttentionLeft);
+ Assert.IsNull(b.Price(first));
+ Assert.IsTrue(b.CanPay(first));
+ Assert.IsNull(b.Queue(first)); Assert.IsNull(b.Queue(next));
+ Assert.AreEqual(1, b.Queued.Count);
+ Assert.AreEqual(next, b.Queued[0]);
+ b.Withdraw(next); Assert.IsEmpty(b.Queued);
+ Assert.IsNotNull(b.Queue(new SetPolicy("not-a-policy", .5)), "real validity checks remain");
+ }
+
+ [TestCase(false)] [TestCase(true)]
+ public void HudHasNoAttentionTextOrHitTarget(bool he)
+ {
+ var b = Bridge(true, he);
+ Assert.AreEqual("", HudModel.From(b, Text(he)).Attention);
+ using var ui = new UiTestKit();
+ using var hud = new HudPresenter(ui.Root, b, Text(he));
+ var line = ui.Q<UnityEngine.UIElements.Label>("attention");
+ Assert.AreEqual("", line.text);
+ Assert.AreEqual(UnityEngine.UIElements.DisplayStyle.None, line.style.display.value);
+ Assert.AreEqual(UnityEngine.UIElements.PickingMode.Ignore, line.pickingMode);
+ Assert.IsFalse(line.focusable);
+ Assert.IsTrue(string.IsNullOrEmpty(line.tooltip));
+ foreach (var label in ui.Q<VisualElement>("top-bar").Query<Label>().ToList())
+ {
+ bool visible = true;
+ for (VisualElement? e = label; e != null; e = e.parent)
+ if (e.style.display.value == DisplayStyle.None) visible = false;
+ if (!visible) continue;
+ StringAssert.DoesNotContain(Text(he)["capture.caption.attention"], label.text ?? "");
+ StringAssert.DoesNotContain(Text(he)["capture.caption.attention"], label.tooltip ?? "");
+ }
+ StringAssert.DoesNotContain("NaN", ui.Q<UnityEngine.UIElements.Button>("end-turn").text);
+ }
+
+ [TestCase(false)] [TestCase(true)]
+ public void NullCapturePreviewOmitsOnlyAttention(bool he)
+ {
+ var b = Bridge(true, he); var t = Text(he);
+ var preview = new CapturePreview(null, 3, 0, 2, 4, 0, 0, 0);
+ var line = CaptureDialogPresenter.PreviewText(b.Content, b.State, preview, t);
+ StringAssert.DoesNotContain(t["capture.caption.attention"], line);
+ StringAssert.Contains(t["hud.caption.treasury"], line);
+ StringAssert.Contains(t["capture.caption.food"], line);
+ StringAssert.Contains(t["capture.caption.arms"], line);
+ }
+
+ [TestCase(false)] [TestCase(true)]
+ public void EventsRemainAnswerableWithoutAttentionOrDelegationWarning(bool he)
+ {
+ var b = Bridge(true, he); var t = Text(he);
+ b.Content.Events.Add(new GameEvent { Id = "no-attention-card", Title = "A decision", Text = "Decide", Options = new List<EventOption> { new EventOption { Id = "yes", Text = "Continue" } } });
+ b.State.PendingEvents.Clear(); b.State.PendingEvents.Add("no-attention-card");
+ using var ui = new UiTestKit();
+ using var card = new EventCardPresenter(ui.Root, b, t, null);
+ var option = ui.Q<UnityEngine.UIElements.Button>("option-yes");
+ Assert.AreEqual("Continue", option.text); Assert.IsTrue(option.enabledSelf);
+ Assert.IsFalse(ui.Q<UnityEngine.UIElements.Button>("end-turn").ClassListContains(EventCardPresenter.EndTurnWaitingClass));
+ Assert.IsNull(b.Queue(new ChooseEventOption("no-attention-card", "yes")));
+ Assert.IsNull(card.Shown, "the answer is queued, so the card closes before End turn");
+ Assert.IsNotNull(b.QueuedLike(new ChooseEventOption("no-attention-card", "")));
+ }
+
+ [TestCase(false)] [TestCase(true)]
+ public void WorkersKeepTheirEndTurnTimingWithoutAnAttentionCost(bool he)
+ {
+ var b = Bridge(true, he); var t = Text(he);
+ var spot = b.Content.SettlementHexes.First(x => b.State.Cities.ContainsKey(x.Id));
+ var host = new UnityEngine.UIElements.VisualElement();
+ GddHexPanel.Render(host, new UnityEngine.UIElements.VisualElement(), b, t, spot.Q, spot.R, id => id);
+ var line = host.Q<UnityEngine.UIElements.Label>("city-workers-cost");
+ Assert.IsNotNull(line);
+ StringAssert.DoesNotContain(t["capture.caption.attention"], line.text);
+ StringAssert.StartsWith(t["city.workers_ordered"].Split('{')[0], line.text);
+ }
+
+ [TestCase(false)] [TestCase(true)]
+ public void SmokeAnswersAnEventWithoutReadingTheObsoletePool(bool he)
+ {
+ var b = Bridge(true, he); var t = Text(he);
+ b.Content.Events.Add(new GameEvent { Id = "smoke-no-attention", Title = "Decision", Text = "Decide", Options = new List<EventOption> { new EventOption { Id = "yes", Text = "Continue" } } });
+ b.State.PendingEvents.Clear(); b.State.PendingEvents.Add("smoke-no-attention");
+ using var ui = new UiTestKit();
+ using var card = new EventCardPresenter(ui.Root, b, t, null);
+ var logs = new List<string>();
+ var smoke = GameRoot.Smoke(ui.Root, b, card, 1, logs.Add);
+ try
+ {
+ Assert.IsTrue(smoke.MoveNext());
+ Assert.IsTrue(smoke.MoveNext());
+ Assert.IsNull(card.Shown);
+ Assert.IsEmpty(logs.Where(x => x.StartsWith("SMOKE FAIL")));
+ }
+ finally { (smoke as System.IDisposable)?.Dispose(); }
+ }
+
+ [TestCase(false)] [TestCase(true)]
+ public void DefenceAndCabinetStillRenderTheirActualRequirements(bool he)
+ {
+ var b = Bridge(true, he); var t = Text(he);
+ using var ui = new UiTestKit();
+ using var defence = new DefencePresenter(ui.Root, b, t);
+ using var cabinet = new CabinetPresenter(ui.Root, b, t, null);
+ var proposed = defence.ProposedMobilization;
+ Assert.AreEqual(t.Format("defence.mob_cost", PlayerText.Money(b.Content, "treasury", EconomySystem.MobilizationCost(b.Content, b.State.Date, proposed))), ui.Q<Label>("mob-cost").text);
+ var refusedAttention = 0; b.RefusedForAttention += () => refusedAttention++;
+ var shares = new Dictionary<string, double>(b.State.Budget);
+ Assert.IsNull(b.Queue(new AllocateBudget(shares)));
+ var key = shares.Keys.First(); var original = shares[key]; shares[key] = original + .1;
+ var retained = (AllocateBudget)b.QueuedLike(new AllocateBudget(shares))!;
+ Assert.AreEqual(original, retained.Shares[key], "budget remains a snapshot");
+ b.Withdraw(retained);
+ Assert.AreEqual(0, refusedAttention);
+ b.State.GameOver = "finished";
+ Assert.AreEqual(t["order.game_over"], b.Queue(new SetPolicy("rationing", .5)));
+ }
+
+ [Test]
+ public void OldRulesetsKeepTheirAttentionPriceAndCaptureLine()
+ {
+ foreach (var c in new[] { Load(false), SimBridgeGddTests.LoadLegacy() })
+ {
+ var t = Text(false); var b = new SimBridge(GameSession.New(c, GoldenRun.Seed, Mode.Historical), t);
+ Assert.IsTrue(c.UsesAttention);
+ Assert.Greater(b.Price(new SetPolicy("rationing", .5)), 0);
+ Assert.IsNotEmpty(HudModel.From(b, t).Attention);
+ StringAssert.Contains(t["capture.caption.attention"], CaptureDialogPresenter.PreviewText(c, b.State, new CapturePreview(-1, 0, 0, 0, 0, 0, 0, 0), t));
+ }
+ }
+}