A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
#nullable enable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Statecraft.Game;
using Statecraft.Game.UI;
using Statecraft.Sim;
using UnityEditor;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;
/// <summary>The advisors' encyclopedia (spec 10), which replaces How to play (#1041): side-menu navigation, the pages grouped
/// by advisor, both languages, gdd-0.3's help without Attention (R-GOV-002), and its two required layouts.</summary>
public class EncyclopediaScreenTests
{
static readonly Content C = ContentLoader.Load(Paths.Content);
static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
static UiText He => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
// A copy with every page approved, so the Hebrew checks also read the pages still pending (security and public_support, #2223).
// Then changed (3 Nov 2026): those two were approved (HE batch 2), so no shipped page is pending now.
static AdvisorCatalog Approved() => AdvisorCatalog.Parse(File.ReadAllText(AdvisorCatalog.Path).Replace("he_review: pending", "he_review: approved"));
[Test]
public void TheSideMenuOpensAndClosesTheScreenInBothLanguages([Values(false, true)] bool hebrew)
{
var text = hebrew ? He : En;
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, FixtureText(text), Pages(), nav, null);
var screen = ui.Q<VisualElement>("screen-encyclopedia");
Assert.IsFalse(ScreenNav.IsOpen(screen), "hidden at start");
ui.Press("nav-encyclopedia");
Assert.IsTrue(ScreenNav.IsOpen(screen), "the side-menu button opens it");
Assert.AreEqual("encyclopedia", nav.Current);
Assert.AreEqual(text["encyclopedia.title"], ui.Q<Label>("encyclopedia-title").text);
ui.Press("nav-encyclopedia");
Assert.IsFalse(ScreenNav.IsOpen(screen), "pressing the same button closes it");
Assert.IsNull(nav.Current);
}
/// <summary>Spec 10: grouped by advisor; a page shows its title and text; Back returns to the list; in Hebrew a pending
/// page is left out of the list (OQ-4), and an advisor with no page shown has no heading.</summary>
[Test]
public void PagesAreGroupedByAdvisorAndPendingOnesHideInHebrew()
{
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, FixtureText(En), Pages(), nav, null);
ui.Press("nav-encyclopedia");
var list = ui.Q<ScrollView>("encyclopedia-list");
CollectionAssert.AreEqual(new[] { "encyclopedia-advisor-ben_gurion", "encyclopedia-page-p.bg", "encyclopedia-advisor-dayan", "encyclopedia-page-p.dayan" },
list.contentContainer.Children().Select(c => c.name).ToArray());
ui.Press("encyclopedia-page-p.bg");
Assert.AreEqual("p.bg", pedia.ShowingPage);
Assert.AreEqual("Title BG.", ui.Q<Label>("encyclopedia-page-title").text);
Assert.AreEqual("Text BG.", ui.Q<Label>("encyclopedia-page-text").text);
Assert.AreEqual(DisplayStyle.None, ui.Q<Button>("encyclopedia-show-me").style.display.value, "no advisor to show it");
ui.Press("encyclopedia-back");
Assert.IsNull(pedia.ShowingPage);
Assert.AreEqual(DisplayStyle.Flex, list.style.display.value, "Back shows the list again");
using var ui2 = new UiTestKit();
using var nav2 = new ScreenNav(ui2.Root);
using var he = new EncyclopediaPresenter(ui2.Root, FixtureText(He), Pages(), nav2, null);
ui2.Press("nav-encyclopedia");
CollectionAssert.AreEqual(new[] { "encyclopedia-advisor-ben_gurion", "encyclopedia-page-p.bg" },
ui2.Q<ScrollView>("encyclopedia-list").contentContainer.Children().Select(c => c.name).ToArray(), "p.dayan is pending");
}
/// <summary>Open(page), an advisor's Tell me more: the screen opens on that page; on the list for a page not shown.</summary>
[Test]
public void OpenShowsThePageAndFallsBackToTheList()
{
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, FixtureText(He), Pages(), nav, null);
pedia.Open("p.bg");
Assert.AreEqual("encyclopedia", nav.Current);
Assert.AreEqual("p.bg", pedia.ShowingPage);
pedia.Open("p.dayan");
Assert.AreEqual("encyclopedia", nav.Current);
Assert.IsNull(pedia.ShowingPage, "pending in Hebrew: the list instead");
}
/// <summary>Spec 10: the mechanics the guide and How to play taught, the 14 nothing taught, immigration, the national
/// meters, and Security and Public support (#2223): 27 pages, grouped by advisor as spec 3.1 splits them.</summary>
[Test]
public void TheShippedPagesCoverEveryMechanic()
{
var pages = AdvisorCatalog.Load().Pages.ToDictionary(p => p.Id, p => p.Advisor);
var expected = new Dictionary<string, string>
{
["turns"] = "ben_gurion", ["attention"] = "ben_gurion", ["events"] = "ben_gurion", ["objectives"] = "ben_gurion",
["defeat"] = "ben_gurion", ["top_bar"] = "ben_gurion", ["why"] = "ben_gurion",
["cities"] = "meyerson", ["immigration"] = "meyerson", ["training"] = "meyerson", ["projects"] = "meyerson",
["pioneer_work"] = "meyerson", ["corridors"] = "meyerson", ["money_debt"] = "meyerson", ["budget"] = "meyerson",
["cabinet"] = "meyerson", ["food"] = "meyerson", ["national_meters"] = "meyerson",
["security"] = "meyerson", ["public_support"] = "meyerson",
["units_movement"] = "dayan", ["standing_orders"] = "dayan", ["combat"] = "dayan", ["arms"] = "dayan",
["truces"] = "dayan", ["capture"] = "dayan", ["enemy_phase"] = "dayan",
};
CollectionAssert.AreEquivalent(expected, pages);
}
// R-GOV-002: help is selected by explicit ruleset, never by language or a zero Attention price.
[Test]
public void Gdd03HelpContainsNoAttentionInEitherLanguage([Values(false, true)] bool hebrew)
{
var text = hebrew ? He : En;
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, text, Approved(), nav, null, SaveGame.Gdd03Ruleset);
ui.Press("nav-encyclopedia");
var entries = ui.Q<ScrollView>("encyclopedia-list").contentContainer.Children().Select(c => c.name).ToList();
CollectionAssert.DoesNotContain(entries, "encyclopedia-page-attention");
var all = new List<string>(ui.Q<ScrollView>("encyclopedia-list").Query<TextElement>().ToList().Select(t => t.text));
foreach (var page in Approved().Pages.Where(p => p.Id != "attention"))
{
pedia.Open(page.Id);
Assert.AreEqual(page.Id, pedia.ShowingPage);
all.Add(ui.Q<Label>("encyclopedia-page-title").text);
all.Add(ui.Q<Label>("encyclopedia-page-text").text);
}
AssertNoAttention(string.Join("\n", all));
}
[Test]
public void OldRulesetsKeepTheAttentionPage([Values(SaveGame.LegacyRuleset, SaveGame.GddRuleset)] string ruleset)
{
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, En, AdvisorCatalog.Load(), nav, null, ruleset);
pedia.Open("attention");
Assert.AreEqual("attention", pedia.ShowingPage);
Assert.AreEqual(En["advisor.page.attention.text"], ui.Q<Label>("encyclopedia-page-text").text);
}
/// <summary>The turns page keeps How to play's End turn guidance (#1688): a unit that needs orders is selected instead,
/// with its remedies, in both languages and both rulesets; and it states R-TURN-004: every unit order but Send home is
/// immediate and final, not only moves and attacks (#2095 review).</summary>
[Test]
public void TheTurnsPageKeepsNeedsOrdersGuidance([Values(false, true)] bool hebrew, [Values(SaveGame.GddRuleset, SaveGame.Gdd03Ruleset)] string ruleset)
{
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, hebrew ? He : En, Approved(), nav, null, ruleset);
pedia.Open("turns");
var line = ui.Q<Label>("encyclopedia-page-text").text;
foreach (var phrase in hebrew ? new[] { "ממתינה להוראות", "מסמנת את היחידה", "ביצור", "דלגו", "(התקפה, ביצור, החזקה) מתבצעות מיד", "שליחה הביתה" }
: new[] { "needs orders", "selects it instead", "fortify", "skip it", "unit orders (attack, fortify, hold) happen at once", "Send home" })
StringAssert.Contains(phrase, line);
}
// R-CITY-010: only gdd-0.3 withholds the job income of a city with an enemy military unit on it; gdd-0.1 and legacy keep the base text.
[Test]
public void Gdd03HeldCityJobIncomeUsesRulesetTextInBothLanguages()
{
var texts = new[] { En, He };
var heldClauses = new[] { "a city with an enemy military unit on it earns no job income that turn", "משרות בעיר שיש בה יחידה צבאית של האויב אינן מכניסות כסף באותו תור" };
for (var language = 0; language < texts.Length; language++)
{
var text = texts[language];
foreach (var page in new[] { "cities", "money_debt" })
{
var variantKey = "advisor.page." + page + ".gdd03.text";
var baseKey = "advisor.page." + page + ".text";
Assert.IsTrue(text.Has(variantKey), variantKey + " exists");
StringAssert.Contains(heldClauses[language], text[variantKey]);
StringAssert.DoesNotContain(heldClauses[language], text[baseKey]);
foreach (var ruleset in new[] { SaveGame.Gdd03Ruleset, SaveGame.GddRuleset, SaveGame.LegacyRuleset })
{
var key = "advisor.page." + page + (ruleset == SaveGame.Gdd03Ruleset ? ".gdd03.text" : ".text");
Assert.IsTrue(text.Has(key), key + " exists");
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, text, Approved(), nav, null, ruleset);
pedia.Open(page);
Assert.AreEqual(text[key], ui.Q<Label>("encyclopedia-page-text").text, key);
}
}
}
}
// R-PROJ-003, R-ARMS-004, R-HOUSE-006: gdd-0.3 names its extra city-project kinds; older rulesets keep the base text.
// R-PROJ-003, R-CITY-011: under gdd-0.3 a project moves only with a builder, so the variant does not say it needs no workers.
[Test]
public void Gdd03ProjectsPageNamesItsExtraKindsInBothLanguages()
{
var catalog = AdvisorCatalog.Load();
var texts = new[] { En, He };
var gdd03Kinds = new[]
{
new[] { "housing", "industry", "arms workshop", "housing repair" },
new[] { "דיור", "תעשייה", "סדנת נשק", "שיפוץ דיור" },
};
for (var language = 0; language < texts.Length; language++)
{
var text = texts[language];
const string baseKey = "advisor.page.projects.text";
const string variantKey = "advisor.page.projects.gdd03.text";
Assert.IsTrue(text.Has(variantKey), variantKey + " exists");
foreach (var kind in gdd03Kinds[language])
StringAssert.Contains(kind, text[variantKey]);
StringAssert.DoesNotContain(gdd03Kinds[language][2], text[baseKey]);
StringAssert.DoesNotContain(gdd03Kinds[language][3], text[baseKey]);
var builder = language == 0 ? new[] { "builder", "without one it waits" } : new[] { "יש לו בונה", "בלי בונה הוא ממתין" };
foreach (var phrase in builder)
{
StringAssert.Contains(phrase, text[variantKey]);
StringAssert.DoesNotContain(phrase, text[baseKey]);
}
StringAssert.DoesNotContain(language == 0 ? "needs no workers" : "אינו דורש עובדים", text[variantKey]);
var approvedTail = text[baseKey].Substring(text[baseKey].IndexOf(". ", text[baseKey].IndexOf(". ") + 1));
StringAssert.EndsWith(approvedTail, text[variantKey], "only the first two sentences change");
foreach (var ruleset in new[] { SaveGame.Gdd03Ruleset, SaveGame.GddRuleset, SaveGame.LegacyRuleset })
{
var key = ruleset == SaveGame.Gdd03Ruleset ? variantKey : baseKey;
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, text, catalog, nav, null, ruleset);
pedia.Open("projects");
Assert.AreEqual(text[key], ui.Q<Label>("encyclopedia-page-text").text, key);
}
}
}
// R-TURN-004: withdrawal is promised only where the panel offers it.
[Test]
public void TurnsPageDoesNotPromiseEveryWaitingOrderCanBeWithdrawn()
{
StringAssert.DoesNotContain("until then you can change or withdraw them", En["advisor.page.turns.text"]);
StringAssert.DoesNotContain("ועד אז אפשר לשנות אותן או להסיר אותן", He["advisor.page.turns.text"]);
StringAssert.Contains("may be changed (and withdrawn where the panel offers it)", En["advisor.page.turns.text"]);
StringAssert.Contains("(ולהסיר אותן אם האפשרות מוצעת במסך)", He["advisor.page.turns.text"]);
}
/// <summary>On the SHIPPED catalogue (AdvisorCatalog.Load(), not Approved()), the Hebrew encyclopedia lists every
/// approved page: the nine that replace How to play, which Beri read as a native speaker on #2095 (1 Nov 2026), and the
/// other 16, which the owner read as a native speaker the same day ("all 16 pages look good"). Security and Public
/// support (#2223) wait for their native read (OQ-4), so they are the only pages the Hebrew list leaves out.
/// Then changed (3 Nov 2026): the owner read Security and Public support as a native speaker (HE batch 2: "approved"),
/// so no page is pending and the Hebrew list leaves none out.</summary>
[Test]
public void TheShippedHebrewEncyclopediaListsEveryApprovedPage()
{
var shipped = AdvisorCatalog.Load();
Assert.AreEqual(27, shipped.Pages.Count, "shipped pages");
CollectionAssert.IsEmpty(shipped.Pages.Where(p => !p.ApprovedIn(true)).Select(p => p.Id), "pending pages");
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, He, shipped, nav, null);
ui.Press("nav-encyclopedia");
var entries = ui.Q<ScrollView>("encyclopedia-list").contentContainer.Children().Select(c => c.name).ToList();
var missing = shipped.Pages.Where(p => p.ApprovedIn(true)).Select(p => p.Id).Where(p => !entries.Contains("encyclopedia-page-" + p)).ToList();
Assert.IsEmpty(missing, "pages missing from the shipped Hebrew list: " + string.Join(", ", missing));
CollectionAssert.Contains(entries, "encyclopedia-page-security", "approved in Hebrew on 3 Nov 2026");
CollectionAssert.Contains(entries, "encyclopedia-page-public_support", "approved in Hebrew on 3 Nov 2026");
}
/// <summary>Under gdd-0.3 a lost city alone does not end the game (R-END-003, #1668): the defeat page says so, in both
/// languages, and the old war-loss sentence (a city held at a turn's end loses the game at once) is gone (#2733 item 11).</summary>
[Test]
public void Gdd03DefeatPageHasNoWarLoss([Values(false, true)] bool hebrew)
{
var text = hebrew ? He : En;
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using var pedia = new EncyclopediaPresenter(ui.Root, text, AdvisorCatalog.Load(), nav, null, SaveGame.Gdd03Ruleset);
pedia.Open("defeat");
var line = ui.Q<Label>("encyclopedia-page-text").text;
Assert.AreEqual(text["advisor.page.defeat.gdd03.text"], line);
AssertContainsOrdinal(hebrew ? "אובדן עיר לבדו אינו מסיים את המשחק" : "Losing a city does not end the game by itself", line,
"the page says a lost city alone does not end the game");
foreach (var warLoss in hebrew ? new[] { "המשחק אבוד מיד", "מחזיקה באחת הערים שלנו" } : new[] { "the game is lost at once", "holds one of our cities" })
StringAssert.DoesNotContain(warLoss, line, "the old war-loss sentence is gone");
}
/// <summary>R-COMBAT-001, R-COMBAT-004: under gdd-0.3 player attacks neither check nor spend Arms, while military training
/// still takes them when it starts and is refused when the stock runs short. The Arms page says so in both languages,
/// and the older rulesets keep the text where each attack spends Arms (#2733 item 12). The gdd-0.3 page names no attack
/// at all: if a later text mentions attacks, it must say they spend no Arms, and this test changes with it.</summary>
[Test]
public void Gdd03ArmsPageSaysAttacksSpendNoArmsInBothLanguages([Values(false, true)] bool hebrew)
{
var text = hebrew ? He : En;
using var ui = new UiTestKit();
using var nav = new ScreenNav(ui.Root);
using (var pedia = new EncyclopediaPresenter(ui.Root, text, AdvisorCatalog.Load(), nav, null, SaveGame.Gdd03Ruleset))
{
pedia.Open("arms");
Assert.AreEqual("arms", pedia.ShowingPage);
var line = ui.Q<Label>("encyclopedia-page-text").text;
Assert.AreEqual(text["advisor.page.arms.gdd03.text"], line);
foreach (var training in hebrew ? new[] { "אימון צבאי לוקח ממנו כשהוא מתחיל", "אימון שדורש נשק נדחה" }
: new[] { "Military training takes them when it starts", "training that needs Arms is refused" })
AssertContainsOrdinal(training, line, "training still takes Arms and is refused without them");
foreach (var attack in hebrew ? new[] { "התקפ", "תקיפ" } : new[] { "attack" })
StringAssert.DoesNotContain(attack, line.ToLowerInvariant(), "gdd-0.3 attacks neither check nor spend Arms");
}
using var ui2 = new UiTestKit();
using var nav2 = new ScreenNav(ui2.Root);
using var older = new EncyclopediaPresenter(ui2.Root, text, AdvisorCatalog.Load(), nav2, null, SaveGame.GddRuleset);
older.Open("arms");
AssertContainsOrdinal(hebrew ? "וכל התקפה מוציאה ממנו" : "each attack spends them", ui2.Q<Label>("encyclopedia-page-text").text,
"gdd-0.1 keeps the attack price (R-COMBAT-004)");
}
// Ordinal, not StringAssert's culture compare, which ignores direction marks in Hebrew (#1790).
static void AssertContainsOrdinal(string expected, string actual, string message) =>
Assert.That(actual.IndexOf(expected, System.StringComparison.Ordinal) >= 0, Is.True, $"{message}: expected \"{expected}\" in \"{actual}\"");
static void AssertNoAttention(string all)
{
StringAssert.DoesNotContain("Attention", all);
StringAssert.DoesNotContain("תשומת לב", all);
StringAssert.DoesNotContain("תשומת הלב", all);
}
[UnityTest]
public IEnumerator TheEncyclopediaFitsLaptopAndPhoneInBothLanguages([Values(SaveGame.GddRuleset, SaveGame.Gdd03Ruleset)] string ruleset,
[Values(100, 125, 150)] int uiScale) // #40: at the Settings scale choices (#2219 review)
{
var problems = new List<string>();
foreach (var hebrew in new[] { false, true })
foreach (var size in new[] { new Vector2Int(1280, 720), new Vector2Int(390, 844), new Vector2Int(360, 800), new Vector2Int(2560, 1080) }) // and the ends of the verified range
yield return Rendered(size.x, size.y, hebrew, (root, pedia) => Fits(root, problems, $"{ruleset} {(hebrew ? "he" : "en")} {size.x}x{size.y} at {uiScale}%", pedia, ruleset), ruleset, uiScale);
Assert.IsEmpty(problems, string.Join("\n", problems));
}
/// <summary>Keyboard focus (#2095 review): from an entry the page takes it on Back, and Back hands it to the entry just
/// read, so it never sits on a hidden or removed element; the opening button belongs to the list and hides on a page.</summary>
[UnityTest]
public IEnumerator FocusGoesFromTheEntryToBackAndBackToTheEntry()
{
yield return Rendered(1280, 720, false, (root, pedia) => EntryPageBack(root));
}
static IEnumerable EntryPageBack(VisualElement root)
{
VisualElement? Focused() => root.panel.focusController.focusedElement as VisualElement;
var opening = root.Q<Button>("encyclopedia-opening");
Assert.AreEqual(DisplayStyle.Flex, opening.style.display.value, "precondition: the list offers the opening advice");
var entry = root.Q<Button>("encyclopedia-page-cities");
entry.Focus();
yield return null;
Assert.AreSame(entry, Focused(), "precondition: the entry has the focus");
UiTestKit.Press(entry);
for (int i = 0; i < 2; i++) yield return null;
Assert.AreSame(root.Q<Button>("encyclopedia-back"), Focused(), "the page: Back has the focus");
Assert.AreEqual(DisplayStyle.None, opening.style.display.value, "a page shows only Back and Show me");
UiTestKit.Press(root.Q<Button>("encyclopedia-back"));
for (int i = 0; i < 2; i++) yield return null;
Assert.AreSame(root.Q<Button>("encyclopedia-page-cities"), Focused(), "Back: the entry just read has the focus");
Assert.AreEqual(DisplayStyle.Flex, opening.style.display.value, "the list offers it again");
}
static IEnumerable Fits(VisualElement root, List<string> problems, string at, EncyclopediaPresenter pedia, string ruleset)
{
var window = root.worldBound;
void Inside(string what, Rect r, Rect outer)
{
if (!(r.width > 0 && r.height > 0)) problems.Add($"{at}: {what} is not visible");
else if (r.xMin < outer.xMin - 1 || r.yMin < outer.yMin - 1 || r.xMax > outer.xMax + 1 || r.yMax > outer.yMax + 1)
problems.Add($"{at}: {what} {r} leaves {outer}");
}
var screen = root.Q("screen-encyclopedia").worldBound;
Inside("screen", screen, window);
var list = root.Q<ScrollView>("encyclopedia-list");
if (list.contentContainer.childCount == 0) problems.Add($"{at}: the list is empty");
foreach (var entry in list.contentContainer.Children())
if (entry.worldBound.xMin < list.worldBound.xMin - 1 || entry.worldBound.xMax > list.worldBound.xMax + 1)
problems.Add($"{at}: {entry.name} {entry.worldBound} overflows the list {list.worldBound}");
pedia.Open(ruleset == SaveGame.Gdd03Ruleset ? "cities" : "attention"); // a page with a Show me; gdd-0.3 has no Attention
for (int i = 0; i < 3; i++) yield return null;
if (root.Q("encyclopedia-opening").style.display.value != DisplayStyle.None) problems.Add($"{at}: the opening button shows on a page");
var body = root.Q<ScrollView>("encyclopedia-page-body").worldBound;
var words = root.Q<Label>("encyclopedia-page-text").worldBound; // it may scroll down, never sideways
if (!(words.width > 0) || words.xMin < body.xMin - 1 || words.xMax > body.xMax + 1) problems.Add($"{at}: page text {words} overflows {body}");
foreach (var name in new[] { "encyclopedia-page-title", "encyclopedia-back", "encyclopedia-show-me" })
Inside(name, root.Q(name).worldBound, screen);
}
static AdvisorCatalog Pages() => AdvisorCatalog.Parse("advisors:\n - { id: ben_gurion, person: ben_gurion }\n - { id: meyerson, person: golda_meir }\n - { id: dayan, person: dayan }\n" +
"messages: []\npages:\n - { id: p.bg, advisor: ben_gurion, show_me: attention, he_review: approved }\n - { id: p.dayan, advisor: dayan }\n");
static UiText FixtureText(UiText baseText) => UiText.Parse(
AssetDatabase.LoadAssetAtPath<TextAsset>(baseText["ui.lang"] == UiLanguage.Hebrew ? UiPaths.StringsHebrew : UiPaths.Strings).text +
"\nadvisor.page.p.bg.title: \"Title BG.\"\nadvisor.page.p.bg.text: \"Text BG.\"\nadvisor.page.p.dayan.title: \"Title D.\"\nadvisor.page.p.dayan.text: \"Text D.\"\n");
/// <summary>The whole HUD as the game lays it out, the encyclopedia open on its list, with an advisor so Show me shows.
/// The Hebrew is the test's approved copy (every shipped page is approved since 1 Nov 2026).</summary>
static IEnumerator Rendered(int width, int height, bool hebrew, System.Func<VisualElement, EncyclopediaPresenter, IEnumerable> check,
string ruleset = SaveGame.GddRuleset, int uiScale = 100)
{
var rt = new RenderTexture(width, height, 0);
var ps = Object.Instantiate(AssetDatabase.LoadAssetAtPath<PanelSettings>(UiPaths.Panel));
ps.targetTexture = rt;
if (uiScale != 100) ps.referenceResolution = new Vector2Int(Mathf.RoundToInt(1920f * 100f / uiScale), Mathf.RoundToInt(1080f * 100f / uiScale)); // #40: the panel as the Settings scale choice sets it
var go = new GameObject("EncyclopediaLayoutTest");
go.SetActive(false);
var doc = go.AddComponent<UIDocument>();
doc.panelSettings = ps;
doc.visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(UiPaths.GameUxml);
go.SetActive(true);
var root = doc.rootVisualElement;
root.Q("root").RemoveFromClassList("loading");
if (hebrew) root.Q("root").AddToClassList(UiLanguage.HebrewClass);
var text = hebrew ? He : En;
var bridge = new SimBridge(GameSession.New(C, GoldenRun.Seed, Mode.Historical), text);
var hud = new HudPresenter(root, bridge, text);
var nav = new ScreenNav(root);
var advisor = new AdvisorPresenter(root, bridge, text, new AdvisorSession(Approved(), new AdvisorSettings(null), false));
var pedia = new EncyclopediaPresenter(root, text, Approved(), nav, advisor, ruleset);
nav.Open("encyclopedia");
try
{
for (int i = 0; i < 30 && !(root.Q("screen-encyclopedia").layout.width > 0); i++) yield return null;
for (int i = 0; i < 3; i++) yield return null;
foreach (var step in check(root, pedia)) yield return step;
}
finally
{
pedia.Dispose(); advisor.Dispose(); nav.Dispose(); hud.Dispose();
Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt);
}
}
}