A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
sim: office successor, read and validated (refs #57) (#329)
agamrafaeli-instincta5c3795d42d1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 23e205506..26feb5ffc 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,10 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIBand a `set_policy` outside the window is refused. The loader refuses a reference to a record that is not active for thewhole window of the record using it; an event that fires after its window leaves out records that have ended. With nodates nothing changes (goldens unchanged). Offices and regions come later.+- Offices accept `successor`, the office that takes over when this one is abolished (chapters spec 3.2, refs #57). The+ loader refuses an unknown or self successor, one without `until`, one not in office at the handover, and one that+ could not own the budget lines and policies it takes over (several holders, or a historical title). Nothing reads it+ yet. Goldens unchanged.- Map: today's name of a 1948 locality by tap and in the info panel. A tap on a locality pill toggles its tooltip, a tapelsewhere hides it, and a mouse still hovers as before. The info panel lists the selected hex's 1948 localities withtoday's name where a living place carries on, by the same rule as the tooltip. Keyboard players reach the panel listdiff --git a/content/schema/offices.schema.json b/content/schema/offices.schema.jsonindex ca1395c67..e8d2fa1d8 100644--- a/content/schema/offices.schema.json+++ b/content/schema/offices.schema.json@@ -23,7 +23,8 @@"historical_only": { "type": "boolean", "description": "Historical record only: no Cabinet seat, no player appointment, no gameplay." },"several_holders": { "type": "boolean", "description": "Several people may hold it on the same day (Minister without Portfolio, a second deputy minister). Such an office cannot appear in event text or own policies or effects, and the player cannot appoint to it." },"from": { "$ref": "#/definitions/date", "description": "Day the office was established (inclusive). Leave out if it exists from the start." },- "until": { "$ref": "#/definitions/date", "description": "Day the office was abolished (exclusive). Leave out while it still exists." }+ "until": { "$ref": "#/definitions/date", "description": "Day the office was abolished (exclusive). Leave out while it still exists." },+ "successor": { "type": "string", "description": "Id of the office that takes over (budget lines and policies) when this one is abolished: in office on the until day, one holder, not historical-only. Needs until. Leave out if none." }}}}diff --git a/sim/Statecraft.Sim.Tests/OfficeSuccessorTests.cs b/sim/Statecraft.Sim.Tests/OfficeSuccessorTests.csnew file mode 100644index 000000000..8ef902529--- /dev/null+++ b/sim/Statecraft.Sim.Tests/OfficeSuccessorTests.cs@@ -0,0 +1,46 @@+using System.Collections.Generic;+using System.Linq;+using Statecraft.Sim;++/// <summary>`successor` on an office (#57): read and validated at load; nothing reads it yet (Chapters 4).</summary>+public class OfficeSuccessorTests+{+ static Content Load(string extra)+ {+ var offices = Fixture.Files["offices.yaml"] + extra;+ return ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["offices.yaml"] = offices }));+ }++ static void Refused(string extra, string expected) =>+ Assert.Contains(expected, Assert.Throws<ContentException>(() => Load(extra)).Message);++ [Fact]+ public void ASuccessorIsReadAndTheOldOfficeKeepsItsOwnWindow()+ {+ var c = Load(" - id: old_office\n title: Old\n until: 1950-01-01\n successor: new_office\n - id: new_office\n title: New\n from: 1949-06-01\n");+ Assert.Equal("new_office", c.Offices.Single(o => o.Id == "old_office").Successor);+ Assert.Equal("", c.Offices.Single(o => o.Id == "new_office").Successor);+ }++ [Fact] public void AnUnknownSuccessorIsRefused() => Refused(" - id: o\n title: O\n until: 1950-01-01\n successor: ghost\n", "offices.yaml: offices[o].successor: unknown office 'ghost'");+ [Fact] public void AnOfficeCannotSucceedItself() => Refused(" - id: o\n title: O\n until: 1950-01-01\n successor: o\n", "cannot succeed itself");+ [Fact] public void ASuccessorNeedsUntil() => Refused(" - id: o\n title: O\n successor: finance_minister\n", "needs until");+ [Fact] public void ASuccessorEstablishedAfterTheHandoverIsRefused() =>+ Refused(" - id: o\n title: O\n until: 1950-01-01\n successor: n\n - id: n\n title: N\n from: 1951-01-01\n", "after o is abolished");+ [Fact] public void ASuccessorAbolishedBeforeTheHandoverIsRefused() =>+ Refused(" - id: o\n title: O\n until: 1951-01-01\n successor: n\n - id: n\n title: N\n until: 1950-01-01\n", "before it can take over");++ // The handover day is the old office's `until` (exclusive): the successor may start on it and must still exist on it.+ [Fact] public void ASuccessorEstablishedOnTheHandoverDayIsAccepted() =>+ Assert.Equal("n", Load(" - id: o\n title: O\n until: 1950-01-01\n successor: n\n - id: n\n title: N\n from: 1950-01-01\n").Offices.Single(x => x.Id == "o").Successor);+ [Fact] public void ASuccessorAbolishedOnTheHandoverDayIsRefused() =>+ Refused(" - id: o\n title: O\n until: 1950-01-01\n successor: n\n - id: n\n title: N\n until: 1950-01-01\n", "before it can take over");++ // Spec 4.2: budget lines and policies pass to the successor, so it must be able to own them.+ [Fact] public void ASuccessorWithSeveralHoldersIsRefused() =>+ Refused(" - id: o\n title: O\n until: 1950-01-01\n successor: n\n - id: n\n title: N\n several_holders: true\n", "cannot take over budget lines");+ [Fact] public void AHistoricalOnlySuccessorIsRefused() =>+ Refused(" - id: o\n title: O\n until: 1950-01-01\n successor: n\n - id: n\n title: N\n historical_only: true\n", "is a historical title");+ [Fact] public void AHistoricalTitleMayPassToAnother() =>+ Assert.Equal("n", Load(" - id: o\n title: O\n until: 1950-01-01\n historical_only: true\n successor: n\n - id: n\n title: N\n historical_only: true\n").Offices.Single(x => x.Id == "o").Successor);+}diff --git a/sim/Statecraft.Sim/Content.cs b/sim/Statecraft.Sim/Content.csindex a9516ee29..b0b51a3ab 100644--- a/sim/Statecraft.Sim/Content.cs+++ b/sim/Statecraft.Sim/Content.cs@@ -22,6 +22,9 @@ namespace Statecraft.Simpublic DateTime? From { get; set; }/// <summary>Day the office was abolished (exclusive end, like a term's `to`); null while it still exists.</summary>public DateTime? Until { get; set; }+ /// <summary>Id of the office that takes over when this one is abolished (chapters spec 3.2). Empty means none.+ /// Read and validated by the loader; used when an era boundary is crossed (#59).</summary>+ public string Successor { get; set; } = "";/// <summary>True when the office exists on <paramref name="date"/>: on or after From and before Until.</summary>public bool ExistsOn(DateTime date) => (!From.HasValue || date >= From.Value) && (!Until.HasValue || date < Until.Value);}diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 266a31ac6..11c0130b3 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -596,6 +596,24 @@ namespace Statecraft.Simif (t.To.HasValue && t.To.Value <= t.From) throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}", FormattableString.Invariant($"term ends ({t.To:yyyy-MM-dd}) before it starts ({t.From:yyyy-MM-dd})"));}}+ foreach (var o in c.Offices.Where(o => o.Successor != ""))+ {+ var at = $"offices[{o.Id}].successor";+ var next = c.Offices.FirstOrDefault(x => x.Id == o.Successor);+ if (next == null) throw new ContentException("offices.yaml", at, $"unknown office '{o.Successor}'");+ if (next == o) throw new ContentException("offices.yaml", at, "an office cannot succeed itself");+ if (!o.Until.HasValue) throw new ContentException("offices.yaml", at, "needs until: only an abolished office has a successor");+ // The successor takes over the old office's budget lines and policies (chapters spec 4.2, #59), so it must be able+ // to own whatever the old office could.+ if (next.SeveralHolders && !o.SeveralHolders)+ throw new ContentException("offices.yaml", at, $"office '{next.Id}' has several holders, so it cannot take over budget lines and policies");+ if (next.HistoricalOnly && !o.HistoricalOnly)+ throw new ContentException("offices.yaml", at, $"office '{next.Id}' is a historical title, so it cannot take over budget lines and policies");+ if (next.From.HasValue && next.From.Value > o.Until.Value)+ throw new ContentException("offices.yaml", at, FormattableString.Invariant($"office '{next.Id}' is established on {next.From:yyyy-MM-dd}, after {o.Id} is abolished ({o.Until:yyyy-MM-dd})"));+ if (next.Until.HasValue && next.Until.Value <= o.Until.Value)+ throw new ContentException("offices.yaml", at, FormattableString.Invariant($"office '{next.Id}' is abolished on {next.Until:yyyy-MM-dd}, before it can take over on {o.Until:yyyy-MM-dd}"));+ }foreach (var o in c.Offices.Where(o => o.From.HasValue)){if (o.Until.HasValue && o.Until.Value <= o.From!.Value)