A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
docs(advisors): photo fallback for lines without a clip (#1547)
Eyal Golan55b813a4781c
diff --git a/docs/superpowers/plans/2026-10-23-advisors.md b/docs/superpowers/plans/2026-10-23-advisors.mdindex 945dce405..bdb75f009 100644--- a/docs/superpowers/plans/2026-10-23-advisors.md+++ b/docs/superpowers/plans/2026-10-23-advisors.md@@ -4,7 +4,7 @@**Goal:** Three advisors (David Ben-Gurion, Golda Meyerson, Moshe Dayan) teach each mechanic the first time the player meets it and warn as the game goes on, in a side popup, replacing the first-turn guide and How to play; the talking clips plug in last, once the owner picks how they are made.-**Architecture:** A Unity-side data file, `unity/Assets/Resources/Advisors/advisor-messages.yaml`, lists the advisors, their messages and the encyclopedia's pages; `AdvisorCatalog` loads and checks it. Small pure classes decide what shows: `AdvisorSignals` reads the state the screen shows, `AdvisorQueue` orders, caps and filters, `AdvisorLayout` places the popup, `AdvisorSettings` keeps the help level and the seen marks in the settings file. `AdvisorPresenter` draws the popup and hides it under every modal layer through one hook at the end of `ScreenNav.DisableCovered`. Media is one optional row per message: a picture file (a clip or a still) under `StreamingAssets/advisors/`, a narration file per language and timed caption keys; `AdvisorMedia` plays whatever the row names, so the production route can change without touching code.+**Architecture:** A Unity-side data file, `unity/Assets/Resources/Advisors/advisor-messages.yaml`, lists the advisors, their messages and the encyclopedia's pages; `AdvisorCatalog` loads and checks it. Small pure classes decide what shows: `AdvisorSignals` reads the state the screen shows, `AdvisorQueue` orders, caps and filters, `AdvisorLayout` places the popup, `AdvisorSettings` keeps the help level and the seen marks in the settings file. `AdvisorPresenter` draws the popup and hides it under every modal layer through one hook at the end of `ScreenNav.DisableCovered`. Media is one optional row per message: an optional picture file (a clip or a still; without one the advisor's portrait shows) under `StreamingAssets/advisors/`, a narration file per language and timed caption keys; `AdvisorMedia` plays whatever the row names, so the production route can change without touching code.**Tech Stack:** C# in Unity 6000.3.25f1 (UI Toolkit, NUnit EditMode tests), YamlDotNet (already a Unity plugin), the netstandard2.1 sim (xUnit, `dotnet test sim/Statecraft.sln`) for one read-only helper, `scripts/check.sh`.@@ -14,7 +14,7 @@- **Approval.** The owner, 23 October 2026, verbatim: "spec approved". The open questions of spec section 18 take their stated defaults: OQ-1 and OQ-2, no aide name ships (a narrator is named by office only); OQ-3, CRF 28; OQ-4, no Hebrew advisor line or narration ships before a native reviewer approves it; OQ-5, the 1951 photograph under D-P with its risk note; OQ-6, keep the first version's stills; OQ-7, no line names Dayan's 1948-49 posts; OQ-8, Off does not keep the capture prompt; OQ-9, S2 ports whatever `guide.move.text` is on main; OQ-10, S4 adds `end.outcome.defeat_war`; OQ-11, no folded tab; OQ-12, no new key.- **Media is not settled.** Spec sections 11 and 12 still describe the still-photo clips, which the owner has since rejected. Owner rulings since: talking advisors. Route A: the leader's stylized face speaking the aide's voice, labelled "stylized portrayal, fictional dialogue and voice", made locally with LivePortrait. Route B: Tal Heuberger's fictional figures speaking through ElevenLabs, with Tal's permission. Both are being tested now. So:- - every media-dependent piece reads one data row: a picture file under `unity/Assets/StreamingAssets/advisors/` (`.mp4` plays as a silent clip, `.jpg` or `.png` shows as a still), a narration file per language in the same folder (`.wav`, played as separate audio), caption cues as string keys with start times (live text), and a disclosure label key;+ - every media-dependent piece reads one data row: an optional picture file under `unity/Assets/StreamingAssets/advisors/` (`.mp4` plays as a silent clip, `.jpg` or `.png` shows as a still; without one the advisor's portrait stays, by the owner's ruling of 24 October 2026: "select some dayan, some ben gurion and some golda to match the budget. the rest of the advisor screen would use their photos for now until we have more tolens"), a narration file per language in the same folder (`.wav`, played as separate audio), caption cues as string keys with start times (live text), and a disclosure label key;- nothing outside Task 26 names a route, a tool or a file that Task 26 makes;- spec 12's player rules stay: never autoplays, the picture is silent, the narration is a separate file, captions are live text, one press stops both, lazy, nothing at boot.- **Presentation only.** No change to the sim's state, the save or a golden hash. With no settings file (automated runs, EditMode tests by default) the advisors never show by themselves, so the smoke runs, the golden check and the browser checks do not change. The one sim addition is spec section 5's read-only helper (Task 15): it adds two functions, changes no state and draws no random number, and `dotnet test sim/Statecraft.sln` must show the goldens unchanged.@@ -3501,13 +3501,13 @@ Everything in this slice is tested with fake pictures and fake audio, and with t**Interfaces:**- Consumes: Task 1.-- Produces: `AdvisorCatalog.Media { string Picture; Dictionary<string,string> Narration; Dictionary<string,List<double>> Cues; string Label; string Credit }`; `Message.Media` and `Page.Media` (null when absent); `AdvisorCatalog.MediaFolder = "advisors"` (under StreamingAssets). Cue keys `advisor.<id>.cue.<n>` (pages: `advisor.page.<id>.cue.<n>`), `n` from 1.+- Produces: `AdvisorCatalog.Media { string? Picture; Dictionary<string,string> Narration; Dictionary<string,List<double>> Cues; string Label; string Credit }`; `Message.Media` and `Page.Media` (null when absent); `AdvisorCatalog.MediaFolder = "advisors"` (under StreamingAssets). Cue keys `advisor.<id>.cue.<n>` (pages: `advisor.page.<id>.cue.<n>`), `n` from 1.The row, media-neutral (Global Constraints):```yamlmedia:- picture: opening.greeting.mp4 # StreamingAssets/advisors/: .mp4 a silent clip, .jpg or .png a still+ picture: opening.greeting.mp4 # optional; .mp4 a silent clip, .jpg/.png a still; omit to use the advisor portraitnarration: { en: opening.greeting.en.wav } # he: only once the Hebrew is approved (OQ-4, spec 11.2)cues: { en: [0.0, 4.2] } # start seconds of advisor.<id>.cue.1, .cue.2, ... in that languagelabel: advisor.media_label # the disclosure line under the picture, in both languages@@ -3543,10 +3543,18 @@ Everything in this slice is tested with fake pictures and fake audio, and with tvar t = Strings("advisor.x.text", "advisor.x.cue.1", "advisor.x.cue.2", "lab");Assert.IsEmpty(c.Problems(t, t, known));}++ [Test]+ public void AGoodNarrationOnlyRowHasNoProblems()+ {+ var known = new AdvisorCatalog.Known { Signals = new[] { "new_game" }, StreamingFile = _ => true };+ var c = AdvisorCatalog.Parse(Head + "messages:\n - { id: x, advisor: dayan, signal: new_game, level: new, media: { narration: { en: x.en.wav }, cues: { en: [0.0] }, label: lab } }\n");+ Assert.IsEmpty(c.Problems(Strings("advisor.x.text", "advisor.x.cue.1", "lab"), Strings("advisor.x.text", "advisor.x.cue.1", "lab"), known));+ }```- [ ] **Step 2: Run** `FILTER="AdvisorCatalogTests"`; expect compile errors (`media`).-- [ ] **Step 3: Implement** `public const string MediaFolder = "advisors";`, `Media` and a `CheckMedia(p, at, keyStem, media, heReview, en, he, known)` called for messages and pages: the picture's extension and file; each narration `.wav` and its file; `he` narration and cues only with `he_review: approved`; for each language with narration, cues present, first 0, strictly rising, and each `keyStem + ".cue." + n` in both strings files (the same count of cues in both languages, so the keys stay in parity); the label key in both; the credit key in both when set. `Shipped().StreamingFile = f => System.IO.File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, MediaFolder, f))`.+- [ ] **Step 3: Implement** `public const string MediaFolder = "advisors";`, `Media` and a `CheckMedia(p, at, keyStem, media, heReview, en, he, known)` called for messages and pages: when supplied, the picture's extension and file; a row with no picture must have narration; each narration `.wav` and its file; `he` narration and cues only with `he_review: approved`; for each language with narration, cues present, first 0, strictly rising, and each `keyStem + ".cue." + n` in both strings files (the same count of cues in both languages, so the keys stay in parity); the label key in both; the credit key in both when set. `Shipped().StreamingFile = f => System.IO.File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, MediaFolder, f))`.- [ ] **Step 4: Run** `FILTER="AdvisorCatalogTests"`; expect PASS.- [ ] **Step 5: Commit.** `git commit -m "ui: the advisors' media rows and their checks (Refs #1484)"`@@ -3691,7 +3699,7 @@ public class AdvisorMediaTests```- [ ] **Step 2: Run** `FILTER="AdvisorMediaTests"`; expect compile errors.-- [ ] **Step 3: Implement.** `CardVideo`: `Play(..., bool held = false)` stores `held`; `OnPrepared` shows the texture and calls `p.Play()` only when not held; `public void Release() { held = false; if (player != null && player.isPrepared) player.Play(); }`; `public double Time => player?.time ?? 0;`; `public void Seek(double t) { if (player != null) player.time = t; }`. The card and the outcome clips pass nothing, so they behave as today (`EventVideoTests`, `OutcomeClipTests` unchanged). `ClipPicture.Load` calls `video.Play(url, target, failed, loop: false, held: true)` and keeps the URL; `Ready => video.Current == url && video.Showing`; `Start => video.Release()`; `Stop => { if (video.Current == url) video.Stop(); }`. `StillPicture` fetches with `UnityWebRequestTexture.GetTexture(url)`, sets the target's background on success, and is `Ready` then; `Time` and `Seek` do nothing (the narration drives the captions). `AdvisorMedia.Play` picks the clip picture for `.mp4`, the still for `.jpg`/`.png`, fetches the narration of the UI's language (`Url(file)`, as `DeclarationRecording.Url` builds its URL with the build id, `DeclarationRecording.cs:91-95`), and schedules `Tick` every `TickMs` on the caption's scheduler. `Tick`: while loading, start both in the same call once `picture.Ready && output.Ready(clip) == true`; while playing, set the caption to the cue at `output.Position` (`text[keyStem + ".cue." + (i + 1)]`, empty before the first), seek the picture when `Math.Abs(picture.Time - output.Position) > DriftS` (a still never drifts), and stop when the narration has been heard and is no longer playing; the load and decode limits are `DeclarationRecording`'s (`StallTimeoutMs`, `DecodeTimeoutMs`, `StartTimeoutMs`, `DeclarationRecording.cs:30`); a failure stops both, logs `ADVISOR MEDIA failed <file>: <why>`, and calls `failed`. `Stop` stops the picture, then the output, releases the clip, clears the caption. In `AdvisorPresenter`: a `Media` property (GameRoot sets it with `ClipPicture(video)` for the card's player and `StillPicture`, or leaves it null where `CardVideo.ForcedOff()`); `Watch(AdvisorCatalog.Media media, string keyStem)` (internal; Task 25 gives it a button, with the message's or page's own key stem); `Media?.Stop()` in `Hide` (a layer or the message leaving), `GotIt`, `NotNow`, the X and `Dispose`.+- [ ] **Step 3: Implement.** `CardVideo`: `Play(..., bool held = false)` stores `held`; `OnPrepared` shows the texture and calls `p.Play()` only when not held; `public void Release() { held = false; if (player != null && player.isPrepared) player.Play(); }`; `public double Time => player?.time ?? 0;`; `public void Seek(double t) { if (player != null) player.time = t; }`. The card and the outcome clips pass nothing, so they behave as today (`EventVideoTests`, `OutcomeClipTests` unchanged). `ClipPicture.Load` calls `video.Play(url, target, failed, loop: false, held: true)` and keeps the URL; `Ready => video.Current == url && video.Showing`; `Start => video.Release()`; `Stop => { if (video.Current == url) video.Stop(); }`. `StillPicture` fetches with `UnityWebRequestTexture.GetTexture(url)`, sets the target's background on success, and is `Ready` then; `Time` and `Seek` do nothing (the narration drives the captions). `AdvisorMedia.Play` picks the clip picture for `.mp4`, the still for `.jpg`/`.png`, and no picture player when `Picture` is absent (the presenter keeps the advisor portrait visible); it fetches the narration of the UI's language (`Url(file)`, as `DeclarationRecording.Url` builds its URL with the build id, `DeclarationRecording.cs:91-95`), and schedules `Tick` every `TickMs` on the caption's scheduler. `Tick`: while loading, start in the same call once every supplied picture and the output are ready; while playing, set the caption to the cue at `output.Position` (`text[keyStem + ".cue." + (i + 1)]`, empty before the first), seek a supplied picture when `Math.Abs(picture.Time - output.Position) > DriftS` (a still never drifts), and stop when the narration has been heard and is no longer playing; the load and decode limits are `DeclarationRecording`'s (`StallTimeoutMs`, `DecodeTimeoutMs`, `StartTimeoutMs`, `DeclarationRecording.cs:30`); a failure stops both, logs `ADVISOR MEDIA failed <file>: <why>`, and calls `failed`. `Stop` stops a supplied picture, then the output, releases the clip, clears the caption. In `AdvisorPresenter`: a `Media` property (GameRoot sets it with `ClipPicture(video)` for the card's player and `StillPicture`, or leaves it null where `CardVideo.ForcedOff()`); `Watch(AdvisorCatalog.Media media, string keyStem)` (internal; Task 25 gives it a button, with the message's or page's own key stem); `Media?.Stop()` in `Hide` (a layer or the message leaving), `GotIt`, `NotNow`, the X and `Dispose`.- [ ] **Step 4: Run** `FILTER="AdvisorMediaTests;EventVideoTests;OutcomeClipTests;DeclarationRecordingTests;AdvisorPopupTests"`; expect PASS.- [ ] **Step 5: Commit.** `git commit -m "ui: the advisors' media player: picture, narration and live captions in step (Refs #1484)"`@@ -3747,11 +3755,13 @@ public class AdvisorMediaTests```- [ ] **Step 2: Run**; expect compile errors.-- [ ] **Step 3: Implement.** The Watch badge shows on the portrait only for a message with media whose files have not failed this session (a failure hides it until reload, as the card's `failed` set does, `EventCardPresenter.cs:394`). Inline (`AdvisorMedia.Inline(AdvisorLayout.Tier(hudRoot), Slot().height)`, or `ForceInline` in tests): the popup gets `advisor-watching`, which hides the head's portrait row and the text and shows `advisor-media` (364x205) and the caption in `advisor-text`'s place; the buttons stay. Otherwise the overlay, styled as `.outcome-layer` (a dim backdrop, the 16:9 picture, the caption under it, the label line, an X; Escape closes it through GameRoot's poll, `:770`, before the other layers). The label key's text (the row's `label`) shows under the picture in both places, and the narrator line comes from it too (OQ-1: by office only). The encyclopedia's page and Counsel's rows get a Watch button for an item with media, always in the overlay (their screens are open). Strings `advisor.watch`.+- [ ] **Step 3: Implement.** Per line, show the supplied picture (a clip or a still) when `media.picture` is present; otherwise keep the advisor portrait visible and play narration when the current language has it; otherwise keep the portrait and text and show no Watch control. The Watch badge shows on the portrait only for a message with playable media whose files have not failed this session (a failure hides it until reload, as the card's `failed` set does, `EventCardPresenter.cs:394`). Add a test that a narration-only row starts its voice without `advisor-watching` or `advisor-overlay-open`, leaves `advisor-portrait` visible, and stops on any popup button; add a test that a row without a clip or current-language narration has no Watch button and leaves the portrait and text visible.++ With a supplied picture, inline behavior is unchanged (`AdvisorMedia.Inline(AdvisorLayout.Tier(hudRoot), Slot().height)`, or `ForceInline` in tests): the popup gets `advisor-watching`, which hides the head's portrait row and the text and shows `advisor-media` (364x205) and the caption in `advisor-text`'s place; the buttons stay. Otherwise the overlay is used only for supplied pictures and is styled as `.outcome-layer` (a dim backdrop, the 16:9 picture, the caption under it, the label line, an X; Escape closes it through GameRoot's poll, `:770`, before the other layers). The label key's text (the row's `label`) shows under the picture in both places, and the narrator line comes from it too (OQ-1: by office only). The encyclopedia's page and Counsel's rows get a Watch button for an item with playable media; supplied pictures use the overlay, while narration-only items keep their portrait visible. Strings `advisor.watch`.- [ ] **Step 4: Run** `FILTER="AdvisorMediaTests;AdvisorPopupTests;AdvisorPopupLayoutTests;EncyclopediaScreenTests;CounselScreenTests"`; expect PASS. Then the slice's gates with the boot timing (base and PR: nothing at boot), and `changelog.d/advisors-s6a.md`:```markdown-- The advisors' popup can play a short clip or a still with its narration and live captions, in the popup on desktop+- The advisors' popup can play a short clip, a still or the advisor's portrait with its narration and live captions, in the popup on desktopand in a centred overlay on phones; it never plays by itself, and any button or a window opening over it stops it.No clip ships yet (Refs #1484).```diff --git a/docs/superpowers/specs/2026-10-23-advisors-design.md b/docs/superpowers/specs/2026-10-23-advisors-design.mdindex fc970fe93..f754a3199 100644--- a/docs/superpowers/specs/2026-10-23-advisors-design.md+++ b/docs/superpowers/specs/2026-10-23-advisors-design.md@@ -53,6 +53,7 @@ as the option's label; "(Recommended)" marks the option we had recommended.| Voices | "Yes, both": save the three chosen aide voices, then render the Hebrew lines with ElevenLabs `eleven_v3` || Private people | "By role (Recommended)": private people are named by their role in research notes; public figures keep their names. This spec follows the same rule || Video sources | Ben-Gurion: "1951 official PM portrait"; Golda: "1964 desk photo (Recommended)"; Dayan: "1956 map briefing (Recommended)". Choosing them approved downloading those Commons originals |+| Which lines talk (24 October 2026) | "select some dayan, some ben gurion and some golda to match the budget. the rest of the advisor screen would use their photos for now until we have more tolens": only some lines of each advisor get a clip; every other line shows the advisor's portrait, with the narration where one exists (sections 7.1, 12) || Price and ads | "the game is never going to charge any money. ever", and then "the game is never going to have ads" (`docs/oss/DECISIONS.md` D1, `:15`) |How "The real figures talking" is carried out (part of the approved design): the real figures' own voices or likeness@@ -159,11 +160,12 @@ shown one at a time. We copy that shape.| `priority` | 1 to 3; a higher one jumps the queue || `repeat` | `once`, or `every` with a `cooldown_turns` || `actions` | Up to two buttons: `show_me` (highlight a UI element by name, as the guide's ring does, `FirstTurnGuidePresenter.cs:278-303`), `open_screen` (a side screen by name, `ScreenNav.cs:13`), `encyclopedia` (a page id). The dismiss controls (section 7.1) are the popup's own, not data |-| `video` | Optional: the silent clip's file, the narration file per language, and the caption cues per language (section 12) |+| `media` | Optional: a silent clip or still (itself optional), the narration file per language, and the caption cues per language (section 12). With narration but no picture, the advisor's popup portrait is the picture || `quote` | Optional id from the verified list (section 3.3); only these lines show a quote |A load-time test checks that every message names a known advisor, signal, condition, screen and string key in both-languages, that every `video` row's files and cues exist in both languages, that `requires` has no cycle, and that every+languages, that every `media` row's supplied files and cues exist in both languages, that a row without a picture has+narration, that `requires` has no cycle, and that every`quote` is on the list.### 4.2 The runtime@@ -284,7 +286,9 @@ bar's date and the toast, so neither is used.```- **Portrait**: a still archival photograph cropped round the face, about 96x120, in the info panel's gold frame. Never- flipped, never animated. When the message has a clip, a small play badge on it is the "Watch" button (section 12).+ flipped, never animated. When the message has a clip or narration in the current language, a small play badge on it is+ the "Watch" button (section 12). If that line has narration but no clip, the portrait stays visible while the voice and+ live captions play. If it has neither, the normal portrait and text remain and there is no Watch button.- **Name and label**: the advisor's name (section 3.1) and "Advisor" in small capitals; never quotation marks or italics.The name wraps and never shrinks (Hebrew names are longer).- **Text**: one or two sentences, 22 px panel size like `.guide-text`, raised to the 12 screen px text floor@@ -437,20 +441,24 @@ outreach happens without the owner.** The consent letters are kept as ElevenLabs## 12. Video and sound-- **Never autoplays.** The popup's play badge ("Watch") plays the clip, as do the encyclopedia and Counsel.+- **Never autoplays.** The popup's play badge ("Watch") plays the available media, as do the encyclopedia and Counsel.+ Per line: play the clip (or a supplied still) when present; otherwise keep the advisor's portrait visible and play narration when present;+ otherwise show the portrait and text with no Watch control. "Present" means available in the current UI language.- **Small, inside the popup** where the popup's slot has room for the picture, two caption lines and the buttons (about460 logical px tall): 1920x1080, 1280x720, 1366x768, 1024x768 and 960x1080. The picture, 364x205 at 400 px wide,- takes the portrait row's place; the live caption takes the text's place; the buttons stay.+ takes the portrait row's place when a clip or explicit media still exists. With narration only, the portrait row stays;+ the live caption uses the text's place. The buttons stay.- **In a centred overlay** where it has no room: a phone held sideways (400 px free) and an upright phone (the sheet).The overlay follows `.outcome-layer` (`Statecraft.uss:322-332`), keeps the captions under the picture, and closes withits own X and Escape. The choice is made from the measured slot height, not from a guess at the device.- **Captions are live text**, never burned into the clip: timed cue strings per language (`advisor.<id>.cue.<n>` with astart time), the same text as the narration, under the text floor and direction rules, and in Counsel's history. Aversion with burned captions may be made for sharing outside the game; it is not the game's file.-- **The picture is a silent clip** on the existing player. `CardVideo` is silent by design: "A silent clip player ... No+- **A clip is silent** on the existing player. `CardVideo` is silent by design: "A silent clip player ... Noaudio is output" (`CardVideo.cs:9-15`), `audioOutputMode = VideoAudioOutputMode.None` (`:102`), into one 960x540RenderTexture (`:18`, `:90-109`); the encoder passes `-an` (`tools/encode_event_videos.py:42-45`) and its check rejects- any audio stream (`:111-126`). Neither changes.+ any audio stream (`:111-126`). Neither changes. A line without a clip does not borrow the video player; it uses the+ advisor's existing portrait.- **The narration is a separate audio file**, fetched and played the way the start screen's recording is(`DeclarationRecording.cs:41-56`: a fetched `AudioClip`, an output with a play position; `SourceOutput`, an`AudioSource`, `:240-261`). The captions follow the audio's play position. Any button, the X, a layer opening over the