M6.13: Sex picker + species variant schema

Adds character Sex (male/female) as a top-level CharacterDraft field
required for every character, and species variants as a layer on top
of the base species record. Two variant axes:

  - "sex": auto-resolves from CharacterDraft.Sex for purebreds; for
           hybrids, pinned by parent role (sire = male, dam = female)
           by definition. No picker needed beyond Step 0.
  - "lineage": explicit per-species pick (Ram-Folk's sheep/goat). Has
               its own picker on Step 1 (purebred path under the grid;
               hybrid path embedded into the per-parent pick column).

Schema (Theriapolis.Core/Data):
  - SpeciesDef gains VariantAxis (string) and Variants (array of
    SpeciesVariantDef { Id, Name, Traits, Detriments }).
  - JSON content not yet populated — that's M6.14.

CharacterDraft adds:
  - Sex (required by Step 0 validation)
  - SpeciesVariant / SireSpeciesVariant / DamSpeciesVariant
  - ResolveVariantId(species, role) that returns the active variant
    id for a given context — used by Aside to layer variant traits
    onto the base species traits.

Step 0 (StepClade): sex picker row above the hybrid toggle. Two
toggle buttons radio-style.

Step 1 (StepSpecies): purebred path renders a lineage picker below
the grid when the picked species has VariantAxis == "lineage";
hybrid path embeds a lineage picker at the top of each parent's
pick column. Hover popovers summarise each variant's contents.

Validation: Sex is required at Step 0. Lineage variant required at
Step 1 for any picked species (purebred or per-hybrid-parent) with
VariantAxis == "lineage".

Aside: AddVariantContent layers the resolved variant's extra
traits/detriments onto the base species rendering, for both purebred
and hybrid paths.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Christopher Wiebe
2026-05-04 21:03:56 -07:00
parent 44b2ec111f
commit e1fb988969
6 changed files with 301 additions and 9 deletions
+139 -5
View File
@@ -27,6 +27,11 @@ public partial class StepSpecies : VBoxContainer, IStep
private string _sirePicksBuiltFor = "";
private string _damPicksBuiltFor = "";
// Lineage-axis variant picker for purebred path (Ram-Folk sheep/goat etc.).
// Hybrid path embeds its own lineage picker into the per-parent col.
private VBoxContainer _purebredVariantSection = null!;
private string _purebredVariantBuiltFor = "";
public void Bind(CharacterDraft draft)
{
_draft = draft;
@@ -62,6 +67,12 @@ public partial class StepSpecies : VBoxContainer, IStep
_purebredGrid = MakeGrid();
_purebredSection.AddChild(_purebredGrid);
// Lineage picker (Ram-Folk sheep/goat). Visible only when the
// selected species has VariantAxis == "lineage".
_purebredVariantSection = new VBoxContainer { Visible = false };
_purebredVariantSection.AddThemeConstantOverride("separation", 6);
_purebredSection.AddChild(_purebredVariantSection);
_hybridSection = new VBoxContainer();
_hybridSection.AddThemeConstantOverride("separation", 16);
AddChild(_hybridSection);
@@ -131,26 +142,110 @@ public partial class StepSpecies : VBoxContainer, IStep
else
{
RefreshGrid(_purebredGrid, _draft.CladeId, _draft.SpeciesId,
spId => _draft.Patch(new Godot.Collections.Dictionary { { "species_id", spId } }));
spId => OnPurebredSpeciesPicked(spId));
SyncPurebredVariant();
}
}
private void OnPurebredSpeciesPicked(string speciesId)
{
_draft.Patch(new Godot.Collections.Dictionary
{
{ "species_id", speciesId },
// Species swap invalidates lineage variant.
{ "species_variant", "" },
});
}
private void OnLineageSpeciesPicked(string lineage, string speciesId)
{
_draft.Patch(new Godot.Collections.Dictionary
{
{ lineage + "_species_id", speciesId },
// Species swap invalidates the previously-picked species trait/detriment.
// Species swap invalidates the previously-picked species trait/detriment + variant.
{ lineage + "_chosen_species_trait", "" },
{ lineage + "_chosen_species_detriment", "" },
{ lineage + "_species_variant", "" },
});
}
/// <summary>Sync the purebred lineage picker row. Visible iff the
/// picked species declares a lineage-axis variant.</summary>
private void SyncPurebredVariant()
{
var sp = CodexContent.SpeciesById(_draft.SpeciesId);
bool show = sp is not null && sp.VariantAxis == "lineage" && sp.Variants.Length > 0;
_purebredVariantSection.Visible = show;
if (!show)
{
_purebredVariantBuiltFor = "";
foreach (var c in _purebredVariantSection.GetChildren()) c.Free();
return;
}
if (_purebredVariantBuiltFor == _draft.SpeciesId)
{
// Same species — just update which lineage button is pressed.
foreach (var child in _purebredVariantSection.GetChildren())
{
if (child is Button btn)
{
bool want = btn.Name == _draft.SpeciesVariant;
if (btn.ButtonPressed != want) btn.SetPressedNoSignal(want);
}
}
return;
}
foreach (var c in _purebredVariantSection.GetChildren()) c.Free();
_purebredVariantBuiltFor = _draft.SpeciesId;
_purebredVariantSection.AddChild(new Label { Text = "LINEAGE", ThemeTypeVariation = "Eyebrow" });
var row = new HBoxContainer();
row.AddThemeConstantOverride("separation", 8);
_purebredVariantSection.AddChild(row);
foreach (var v in sp!.Variants)
{
string captured = v.Id;
var btn = new Button
{
Text = v.Name,
ToggleMode = true,
ButtonPressed = v.Id == _draft.SpeciesVariant,
FocusMode = Control.FocusModeEnum.None,
Name = v.Id,
};
var btnRef = btn;
btn.Pressed += () =>
_draft.Patch(new Godot.Collections.Dictionary
{
{ "species_variant", btnRef.ButtonPressed ? captured : "" },
});
// Hover popover summarizes the variant's traits + detriments.
string capturedName = v.Name;
string capturedDesc = SummarizeVariant(v);
btn.MouseEntered += () =>
PopoverLayer.Instance?.ShowFor(btnRef, capturedName, capturedDesc, "lineage", false);
btn.MouseExited += () =>
PopoverLayer.Instance?.ScheduleClose();
row.AddChild(btn);
}
}
private static string SummarizeVariant(Theriapolis.Core.Data.SpeciesVariantDef v)
{
var parts = new System.Collections.Generic.List<string>();
foreach (var t in v.Traits) parts.Add($"• {t.Name}: {t.Description}");
foreach (var d in v.Detriments) parts.Add($"• {d.Name} (detriment): {d.Description}");
return parts.Count == 0 ? "(no extra traits)" : string.Join("\n", parts);
}
/// <summary>
/// Mutate-in-place sync for the species-pick column (one trait button
/// group + one detriment button group, radio-style). Same Free()-defer
/// hazard as the bonus rows in StepClade — only rebuild when the
/// species id changes.
/// group + one detriment button group, radio-style; plus a lineage
/// picker when the species declares a lineage-axis variant). Same
/// Free()-defer hazard as the bonus rows in StepClade — only rebuild
/// when the species id changes.
/// </summary>
private void SyncSpeciesPicks(VBoxContainer col, ref string builtFor,
string lineage, string speciesId,
@@ -160,6 +255,8 @@ public partial class StepSpecies : VBoxContainer, IStep
{
UpdateRadioGroup(col, "trait", chosenTrait);
UpdateRadioGroup(col, "detriment", chosenDetriment);
UpdateRadioGroup(col, "lineage",
lineage == "sire" ? _draft.SireSpeciesVariant : _draft.DamSpeciesVariant);
return;
}
@@ -178,6 +275,22 @@ public partial class StepSpecies : VBoxContainer, IStep
return;
}
// Lineage picker first when applicable, so the player picks
// lineage before reading the trait/detriment list (variant
// content layers on top).
if (sp.VariantAxis == "lineage" && sp.Variants.Length > 0)
{
col.AddChild(new Label { Text = "Lineage", ThemeTypeVariation = "Eyebrow" });
string currentVariant = lineage == "sire" ? _draft.SireSpeciesVariant : _draft.DamSpeciesVariant;
BuildRadioGroup(col, "lineage", lineage, VariantsAsTraits(sp.Variants),
currentVariant,
(lin, id) => _draft.Patch(new Godot.Collections.Dictionary
{
{ lin + "_species_variant", id },
}),
isDetriment: false);
}
col.AddChild(new Label { Text = "Trait", ThemeTypeVariation = "Eyebrow" });
BuildRadioGroup(col, "trait", lineage, sp.Traits, chosenTrait,
(lin, id) => OnSpeciesPickToggled(lin, "trait", id), isDetriment: false);
@@ -194,6 +307,27 @@ public partial class StepSpecies : VBoxContainer, IStep
}
}
/// <summary>
/// Adapter — BuildRadioGroup operates on TraitDef[]; project the variant
/// list into TraitDef-shape so it can drive the same radio renderer.
/// Description summarises the variant's contents for the hover popover.
/// </summary>
private static Theriapolis.Core.Data.TraitDef[] VariantsAsTraits(
Theriapolis.Core.Data.SpeciesVariantDef[] variants)
{
var arr = new Theriapolis.Core.Data.TraitDef[variants.Length];
for (int i = 0; i < variants.Length; i++)
{
arr[i] = new Theriapolis.Core.Data.TraitDef
{
Id = variants[i].Id,
Name = variants[i].Name,
Description = SummarizeVariant(variants[i]),
};
}
return arr;
}
private static void BuildRadioGroup(VBoxContainer parent, string kind, string lineage,
Theriapolis.Core.Data.TraitDef[] options, string selected,
System.Action<string, string> onPicked, bool isDetriment)