Ui/CardRuleContent.razor

The UI component renders a game card rule's text content. It formats the rule text based on predefined sections, displaying labels, help text, and interactive word references.

@namespace CitySim
@using CitySim.Cards
@using CitySim.Match
@using CitySim.DesignSystem
@using CitySim.Punchboard
@using Sandbox.UI
@inherits Panel

<root class="card-rule-content">
 @foreach (var section in CardRuleText.Split(Text)) {
  @if (section.Label != null) { <PbRuleKeyword CssClass=@(section.LabelCssClass) Label=@(GameText.Plain(section.Label)) Help=@(GameText.Plain(section.Help)) /> }
  @foreach (var word in CardRuleText.Words(section.Text)) {
   @if (word.LineBreak) { <div class="rule-line-break"></div> }
   else if (word.Interactive) {
    <PlotterCardReference City=@City [email protected] [email protected] [email protected] Targets=@(WordTargets(word)) ReferenceChanged=@ReferenceChanged TargetsChanged=@TargetsChanged />
   }
   else { <span [email protected]>@word.Text</span> }
  }
 }
</root>
@code {
 [Parameter] public CityGame City { get; set; }
 [Parameter] public string Text { get; set; }
 [Parameter] public Action<Tag> ReferenceChanged { get; set; }
 [Parameter] public Action<IReadOnlyList<InteractionTarget>> TargetsChanged { get; set; }
 static IReadOnlyList<InteractionTarget> WordTargets(CardRuleText.Word word) => new[] {
  new InteractionTarget(word.Text, word.Park ? InteractionKind.Park : word.Shop ? InteractionKind.Shop : word.Kind, CardId: word.CardId)
 };
 protected override int BuildHash() => HashCode.Combine(GameText.LanguageCode, Text, City, ReferenceChanged, TargetsChanged);
}