|
13 | 13 | * - currentDetailsContent — a LIVE paragraph describing current state |
14 | 14 | * - interactionHintContent — a short hint on how to get started |
15 | 15 | * |
16 | | - * ── Making "current details" live ───────────────────────────────────────────── |
17 | | - * The template has no model state, so currentDetails is a static string. In a |
18 | | - * real sim, build a DerivedProperty over the relevant model Properties and pass |
19 | | - * it as `currentDetailsContent` so the paragraph updates as the sim runs. |
20 | | - * See LunarLander/src/.../LunarLanderScreenSummaryContent.ts for the pattern. |
| 16 | + * currentDetailsContent is a DerivedProperty over the observer/target planet |
| 17 | + * presets, the current time, and (if locked) the current configuration name, |
| 18 | + * so the paragraph updates as the sim runs. |
21 | 19 | */ |
| 20 | +import { DerivedProperty } from "scenerystack/axon"; |
22 | 21 | import { ScreenSummaryContent } from "scenerystack/sim"; |
23 | 22 | import { StringManager } from "../../i18n/StringManager.js"; |
24 | 23 | import type { ConfigurationsModel } from "../model/ConfigurationsModel.js"; |
| 24 | +import { PRESET_KEYS } from "../model/ConfigurationsPlanet.js"; |
25 | 25 |
|
26 | 26 | export class ConfigurationsScreenSummaryContent extends ScreenSummaryContent { |
27 | | - // `model` is unused in the template but kept in the signature so real sims can |
28 | | - // derive a live currentDetailsContent from it without changing call sites. |
29 | | - public constructor(_model: ConfigurationsModel) { |
| 27 | + public constructor(model: ConfigurationsModel) { |
30 | 28 | const a11y = StringManager.getInstance().getConfigurationsA11yStrings(); |
| 29 | + const strings = StringManager.getInstance().getConfigurationsStrings(); |
| 30 | + |
| 31 | + // Ordered to match PRESET_KEYS: mercury, venus, earth, mars, jupiter, saturn. |
| 32 | + const planetLabelProperties = [ |
| 33 | + strings.mercuryStringProperty, |
| 34 | + strings.venusStringProperty, |
| 35 | + strings.earthStringProperty, |
| 36 | + strings.marsStringProperty, |
| 37 | + strings.jupiterStringProperty, |
| 38 | + strings.saturnStringProperty, |
| 39 | + ] as const; |
| 40 | + |
| 41 | + const currentDetailsProperty = new DerivedProperty( |
| 42 | + [ |
| 43 | + model.preset1IndexProperty, |
| 44 | + model.preset2IndexProperty, |
| 45 | + model.timeProperty, |
| 46 | + model.currentConfigurationProperty, |
| 47 | + a11y.currentDetailsTemplateStringProperty, |
| 48 | + a11y.currentConfigurationTemplateStringProperty, |
| 49 | + ...planetLabelProperties, |
| 50 | + ] as const, |
| 51 | + (preset1Index, preset2Index, time, currentConfiguration, template, configTemplate, ...planetLabels) => { |
| 52 | + const earthIndex = PRESET_KEYS.indexOf("earth"); |
| 53 | + const observerLabel = planetLabels[preset1Index] ?? planetLabels[earthIndex]; |
| 54 | + const targetLabel = planetLabels[preset2Index] ?? planetLabels[earthIndex]; |
| 55 | + const configPart = currentConfiguration === "" ? "" : configTemplate.replace("{0}", currentConfiguration); |
| 56 | + |
| 57 | + return template |
| 58 | + .replace("{0}", observerLabel ?? "") |
| 59 | + .replace("{1}", targetLabel ?? "") |
| 60 | + .replace("{2}", time.toFixed(2)) |
| 61 | + .replace("{3}", configPart) |
| 62 | + .trim(); |
| 63 | + }, |
| 64 | + ); |
31 | 65 |
|
32 | 66 | super({ |
33 | 67 | playAreaContent: a11y.screenSummary.playAreaStringProperty, |
34 | 68 | controlAreaContent: a11y.screenSummary.controlAreaStringProperty, |
35 | | - currentDetailsContent: a11y.currentDetailsStringProperty, |
| 69 | + currentDetailsContent: currentDetailsProperty, |
36 | 70 | interactionHintContent: a11y.screenSummary.interactionHintStringProperty, |
37 | 71 | }); |
38 | 72 | } |
|
0 commit comments