42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
namespace Theriapolis.GodotHost.UI;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Per-background availability rules — which backgrounds are visible /
|
||
|
|
/// pickable for a given <see cref="CharacterDraft"/>. The
|
||
|
|
/// backgrounds.json schema doesn't carry restriction fields (gating
|
||
|
|
/// lives in flavor text), so they're hardcoded here.
|
||
|
|
///
|
||
|
|
/// Used by StepBackground to filter the visible card list and by
|
||
|
|
/// StepClade to clear the currently-selected background when a clade
|
||
|
|
/// change makes it no longer valid (e.g. picking a non-canid lineage
|
||
|
|
/// while Pack-Raised is selected).
|
||
|
|
/// </summary>
|
||
|
|
public static class BackgroundAvailability
|
||
|
|
{
|
||
|
|
private static readonly Dictionary<string, System.Func<CharacterDraft, bool>> Rules = new()
|
||
|
|
{
|
||
|
|
// Hybrid-only backgrounds — flavor text explicitly hybrid.
|
||
|
|
{ "passer", d => d.IsHybrid },
|
||
|
|
{ "hybrid_underground", d => d.IsHybrid },
|
||
|
|
{ "former_chattel", d => d.IsHybrid },
|
||
|
|
|
||
|
|
// Clade-restricted backgrounds.
|
||
|
|
{ "warren_runner", d => d.HasClade("leporidae") },
|
||
|
|
{ "pack_raised", d => d.HasClade("canidae") },
|
||
|
|
{ "herd_city_born", d => d.HasAnyCladeOfKind("prey") },
|
||
|
|
};
|
||
|
|
|
||
|
|
/// <summary>True if the background id can be picked under the given
|
||
|
|
/// draft state. Backgrounds not in the rules table are universally
|
||
|
|
/// available; the empty id is also "available" (means no
|
||
|
|
/// background selected).</summary>
|
||
|
|
public static bool IsAvailable(string backgroundId, CharacterDraft draft)
|
||
|
|
{
|
||
|
|
if (string.IsNullOrEmpty(backgroundId)) return true;
|
||
|
|
if (!Rules.TryGetValue(backgroundId, out var rule)) return true;
|
||
|
|
return rule(draft);
|
||
|
|
}
|
||
|
|
}
|