M6.4: Card-grid steps + hybrid origin + clade-restricted backgrounds
Per GODOT_PORTING_GUIDE.md §12, the four "easy" card-grid steps land
together (Species / Calling / Subclass / History), plus three real
features that emerged during testing: cross-step validation gating,
hybrid origin, and clade-restricted background availability.
New step files (Scenes/Steps/):
StepSpecies.cs — cards filtered by clade; for hybrids shows two
stacked grids (Sire / Dam).
StepClass.cs — all classes; class change clears chosen skills
and the previously-selected subclass.
StepSubclass.cs — subclasses filtered by ClassDef.SubclassIds.
StepBackground.cs — backgrounds filtered by hybrid + clade rules
(see below).
UI/WizardValidation.cs (new):
Static per-step validators against CharacterDraft. Replaces the
per-instance Validate() route on the wizard side — Wizard now
computes the lock state for every step in the flow, not just the
current one. Mirrors app.jsx's firstIncomplete rule exactly.
Bug it fixes: previously the wizard checked only the current step's
validity, so picking a clade let you skip directly to Abilities
without picking species/calling/etc.
UI/CharacterDraft.cs:
Phase 6.5 hybrid fields — IsHybrid, SireCladeId, SireSpeciesId,
DamCladeId, DamSpeciesId, DominantParent. EffectiveCladeId /
EffectiveSpeciesId resolve to the dominant parent's lineage when
hybrid; downstream steps don't need to care which path. Helpers
HasClade(id) and HasAnyCladeOfKind(kind) feed the background
availability rules.
StepClade.cs:
Hybrid toggle splits the picker into Sire + Dam grids with a
Dominant Lineage radio. Validation refuses same-clade Sire+Dam.
Switched to build-once + mutate-in-place: cards are created once
during Build(), Refresh just updates Modulate per selection state.
Tearing down + rebuilding inside the click callback caused
duplicates because Free() defers when the freed node is mid-signal.
StepBackground.cs:
Availability rules table — predicates per restricted background id.
Hybrid-only: passer, hybrid_underground, former_chattel.
Clade-restricted: warren_runner (Leporidae), pack_raised (Canidae),
herd_city_born (any prey clade).
Hybrids match if either parent satisfies the rule.
Other steps (Species/Class/Subclass/Background):
Refresh dispatched via Callable.From(Refresh).CallDeferred() so the
rebuild runs after the click handler completes — same Free()-during-
signal bug as StepClade hit, fixed via deferral instead of mutate-
in-place because the card lists are dynamic (clade- / class- /
hybrid-flag-dependent).
Wizard.cs:
- RebuildStepperStates uses WizardValidation.FirstIncomplete to lock
every step past the first unsatisfied one.
- OnStepperClicked checks every step in [0..target-1].
- UpdateChrome's banner uses WizardValidation for the active step.
- Scroll preservation moved here (snapshot before step.Refresh
fires, restore in _Process); StepStats's local copy removed.
Wizard.tscn:
Scroll node marked unique_name_in_owner so Wizard can grab it.
PopoverLayer's TraitChip is reused throughout the new step cards.
Aside.cs:
Hybrid-aware summary — shows "Sire (dominant)" / "Dam" lineage rows
when IsHybrid; otherwise the existing Clade / Species rows.
Verified end-to-end:
- Walk Clade → Species → Calling → Subclass → History → Abilities
- Stepper locks every step past first unsatisfied
- Hybrid toggle works both directions, dominant changes lineage
- Hybrid-only and clade-restricted backgrounds appear / disappear
based on lineage
- Scroll position preserved across selections
- Drag-drop still works on Abilities
Closes M6.4. Per guide §12, next is M6.5 — StepSkills (class-driven
choice list with TraitChip per skill).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -40,13 +40,35 @@ public partial class Aside : MarginContainer
|
|||||||
foreach (var c in _content.GetChildren()) c.QueueFree();
|
foreach (var c in _content.GetChildren()) c.QueueFree();
|
||||||
|
|
||||||
_content.AddChild(new Label { Text = "SUMMARY" });
|
_content.AddChild(new Label { Text = "SUMMARY" });
|
||||||
|
|
||||||
|
if (_draft.IsHybrid)
|
||||||
|
{
|
||||||
|
AddBlock("Origin", "Hybrid");
|
||||||
|
AddBlock(_draft.DominantParent == "sire" ? "Sire (dominant)" : "Sire",
|
||||||
|
FormatLineage(_draft.SireCladeId, _draft.SireSpeciesId));
|
||||||
|
AddBlock(_draft.DominantParent == "dam" ? "Dam (dominant)" : "Dam",
|
||||||
|
FormatLineage(_draft.DamCladeId, _draft.DamSpeciesId));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
AddBlock("Clade", CodexContent.Clade(_draft.CladeId)?.Name);
|
AddBlock("Clade", CodexContent.Clade(_draft.CladeId)?.Name);
|
||||||
AddBlock("Species", CodexContent.SpeciesById(_draft.SpeciesId)?.Name);
|
AddBlock("Species", CodexContent.SpeciesById(_draft.SpeciesId)?.Name);
|
||||||
|
}
|
||||||
|
|
||||||
AddBlock("Calling", CodexContent.Class(_draft.ClassId)?.Name);
|
AddBlock("Calling", CodexContent.Class(_draft.ClassId)?.Name);
|
||||||
AddBlock("Background", CodexContent.Background(_draft.BackgroundId)?.Name);
|
AddBlock("Background", CodexContent.Background(_draft.BackgroundId)?.Name);
|
||||||
AddBlock("Name", string.IsNullOrEmpty(_draft.CharacterName) ? null : _draft.CharacterName);
|
AddBlock("Name", string.IsNullOrEmpty(_draft.CharacterName) ? null : _draft.CharacterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string? FormatLineage(string cladeId, string speciesId)
|
||||||
|
{
|
||||||
|
var clade = CodexContent.Clade(cladeId);
|
||||||
|
var species = CodexContent.SpeciesById(speciesId);
|
||||||
|
if (clade is null && species is null) return null;
|
||||||
|
if (species is not null) return $"{species.Name} ({clade?.Name ?? cladeId})";
|
||||||
|
return clade?.Name;
|
||||||
|
}
|
||||||
|
|
||||||
private void AddBlock(string label, string? value)
|
private void AddBlock(string label, string? value)
|
||||||
{
|
{
|
||||||
var v = new VBoxContainer();
|
var v = new VBoxContainer();
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
using Godot;
|
||||||
|
using Theriapolis.Core.Data;
|
||||||
|
using Theriapolis.GodotHost.Scenes.Widgets;
|
||||||
|
using Theriapolis.GodotHost.UI;
|
||||||
|
|
||||||
|
namespace Theriapolis.GodotHost.Scenes.Steps;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Step V — History. Direct port of <c>StepBackground</c> in
|
||||||
|
/// <c>src/steps.jsx</c>: card per background showing flavor, granted
|
||||||
|
/// skill / tool proficiencies, and a unique feature with a description
|
||||||
|
/// popover.
|
||||||
|
/// </summary>
|
||||||
|
public partial class StepBackground : VBoxContainer, IStep
|
||||||
|
{
|
||||||
|
private CharacterDraft _draft = null!;
|
||||||
|
private GridContainer _grid = null!;
|
||||||
|
|
||||||
|
public void Bind(CharacterDraft draft)
|
||||||
|
{
|
||||||
|
_draft = draft;
|
||||||
|
_draft.Changed += () => Callable.From(Refresh).CallDeferred();
|
||||||
|
Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Validate() =>
|
||||||
|
string.IsNullOrEmpty(_draft?.BackgroundId) ? "Pick a history." : null;
|
||||||
|
|
||||||
|
private void Build()
|
||||||
|
{
|
||||||
|
AddThemeConstantOverride("separation", 16);
|
||||||
|
|
||||||
|
var intro = new VBoxContainer();
|
||||||
|
intro.AddThemeConstantOverride("separation", 6);
|
||||||
|
AddChild(intro);
|
||||||
|
intro.AddChild(new Label { Text = "FOLIO V · HISTORY" });
|
||||||
|
intro.AddChild(new Label { Text = "Choose a History" });
|
||||||
|
intro.AddChild(new Label
|
||||||
|
{
|
||||||
|
Text = "Where your character came from before the wandering began. "
|
||||||
|
+ "History grants extra skill and tool proficiencies and a unique "
|
||||||
|
+ "feature that resolves in-fiction more often than in combat.",
|
||||||
|
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||||
|
});
|
||||||
|
|
||||||
|
_grid = new GridContainer { Columns = 3, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||||
|
_grid.AddThemeConstantOverride("h_separation", 16);
|
||||||
|
_grid.AddThemeConstantOverride("v_separation", 16);
|
||||||
|
AddChild(_grid);
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Background-availability rules. The backgrounds.json schema doesn't
|
||||||
|
/// carry restriction fields — the gating lives in flavor text only —
|
||||||
|
/// so they're hardcoded here. Each predicate returns true when the
|
||||||
|
/// background is available to the given draft; missing entries are
|
||||||
|
/// universally available.
|
||||||
|
///
|
||||||
|
/// If backgrounds.json ever gains structured restriction fields,
|
||||||
|
/// swap these out for a property-driven check.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly System.Collections.Generic.Dictionary<string, System.Func<UI.CharacterDraft, bool>> AvailabilityRules = 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") },
|
||||||
|
};
|
||||||
|
|
||||||
|
private void Refresh()
|
||||||
|
{
|
||||||
|
if (_grid is null) return;
|
||||||
|
foreach (var c in _grid.GetChildren()) c.QueueFree();
|
||||||
|
foreach (var bg in CodexContent.Backgrounds)
|
||||||
|
{
|
||||||
|
if (AvailabilityRules.TryGetValue(bg.Id, out var rule) && !rule(_draft))
|
||||||
|
continue;
|
||||||
|
_grid.AddChild(BuildCard(bg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Control BuildCard(BackgroundDef bg)
|
||||||
|
{
|
||||||
|
bool selected = _draft.BackgroundId == bg.Id;
|
||||||
|
|
||||||
|
var card = new PanelContainer
|
||||||
|
{
|
||||||
|
CustomMinimumSize = new Vector2(200, 0),
|
||||||
|
MouseFilter = MouseFilterEnum.Stop,
|
||||||
|
};
|
||||||
|
if (selected) card.Modulate = new Color(1f, 0.95f, 0.85f);
|
||||||
|
|
||||||
|
card.GuiInput += (InputEvent e) =>
|
||||||
|
{
|
||||||
|
if (e is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
||||||
|
_draft.Patch(new Godot.Collections.Dictionary { { "background_id", bg.Id } });
|
||||||
|
};
|
||||||
|
|
||||||
|
var box = new VBoxContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
box.AddThemeConstantOverride("separation", 6);
|
||||||
|
card.AddChild(box);
|
||||||
|
|
||||||
|
box.AddChild(new Label { Text = bg.Name });
|
||||||
|
if (!string.IsNullOrEmpty(bg.Flavor))
|
||||||
|
{
|
||||||
|
box.AddChild(new Label
|
||||||
|
{
|
||||||
|
Text = bg.Flavor,
|
||||||
|
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skill + tool prof chips.
|
||||||
|
if (bg.SkillProficiencies.Length > 0 || bg.ToolProficiencies.Length > 0)
|
||||||
|
{
|
||||||
|
var profs = new HFlowContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
profs.AddThemeConstantOverride("h_separation", 6);
|
||||||
|
profs.AddThemeConstantOverride("v_separation", 4);
|
||||||
|
box.AddChild(profs);
|
||||||
|
|
||||||
|
foreach (var s in bg.SkillProficiencies)
|
||||||
|
profs.AddChild(new TraitChip { TraitName = s, Description = "Skill proficiency", Tag = "skill" });
|
||||||
|
foreach (var t in bg.ToolProficiencies)
|
||||||
|
profs.AddChild(new TraitChip { TraitName = t, Description = "Tool proficiency", Tag = "tool" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Background feature — chip whose popover shows the description.
|
||||||
|
if (!string.IsNullOrEmpty(bg.FeatureName))
|
||||||
|
{
|
||||||
|
var featRow = new HBoxContainer();
|
||||||
|
featRow.AddThemeConstantOverride("separation", 6);
|
||||||
|
box.AddChild(featRow);
|
||||||
|
featRow.AddChild(new Label { Text = "FEATURE" });
|
||||||
|
featRow.AddChild(new TraitChip
|
||||||
|
{
|
||||||
|
TraitName = bg.FeatureName,
|
||||||
|
Description = bg.FeatureDescription,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using System.Collections.Generic;
|
||||||
using Theriapolis.Core.Data;
|
using Theriapolis.Core.Data;
|
||||||
using Theriapolis.GodotHost.Scenes.Widgets;
|
using Theriapolis.GodotHost.Scenes.Widgets;
|
||||||
using Theriapolis.GodotHost.UI;
|
using Theriapolis.GodotHost.UI;
|
||||||
@@ -7,16 +8,27 @@ namespace Theriapolis.GodotHost.Scenes.Steps;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Step I — Clade. Direct port of <c>StepClade</c> in
|
/// Step I — Clade. Direct port of <c>StepClade</c> in
|
||||||
/// <c>src/steps.jsx</c>: intro paragraph, then a card grid with one
|
/// <c>src/steps.jsx</c>, plus the Phase 6.5 hybrid-origin extension
|
||||||
/// card per clade. Click selects via <see cref="CharacterDraft.Patch"/>.
|
/// per port plan §10: a Hybrid toggle splits the picker into Sire +
|
||||||
|
/// Dam grids, each independent. The dominant-parent radio drives
|
||||||
|
/// <see cref="CharacterDraft.EffectiveCladeId"/> for downstream steps.
|
||||||
///
|
///
|
||||||
/// Default theme only at this layer (per GODOT_PORTING_GUIDE.md §12 build
|
/// Cards are built once and mutated in place (Modulate update only) on
|
||||||
/// order); the parchment look lands in the final theming pass.
|
/// selection change — tearing down + rebuilding inside the click
|
||||||
|
/// callback chain caused duplicates because Free() defers when the
|
||||||
|
/// freed node is currently mid-signal.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class StepClade : VBoxContainer, IStep
|
public partial class StepClade : VBoxContainer, IStep
|
||||||
{
|
{
|
||||||
private CharacterDraft _draft = null!;
|
private CharacterDraft _draft = null!;
|
||||||
private GridContainer _grid = null!;
|
private CheckBox _hybridToggle = null!;
|
||||||
|
private VBoxContainer _purebredSection = null!;
|
||||||
|
private VBoxContainer _hybridSection = null!;
|
||||||
|
private OptionButton _dominantToggle = null!;
|
||||||
|
|
||||||
|
private readonly Dictionary<string, PanelContainer> _purebredCards = new();
|
||||||
|
private readonly Dictionary<string, PanelContainer> _sireCards = new();
|
||||||
|
private readonly Dictionary<string, PanelContainer> _damCards = new();
|
||||||
|
|
||||||
public void Bind(CharacterDraft draft)
|
public void Bind(CharacterDraft draft)
|
||||||
{
|
{
|
||||||
@@ -25,7 +37,7 @@ public partial class StepClade : VBoxContainer, IStep
|
|||||||
Build();
|
Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? Validate() => string.IsNullOrEmpty(_draft?.CladeId) ? "Pick a clade." : null;
|
public string? Validate() => WizardValidation.Validate(0, _draft);
|
||||||
|
|
||||||
private void Build()
|
private void Build()
|
||||||
{
|
{
|
||||||
@@ -40,90 +52,173 @@ public partial class StepClade : VBoxContainer, IStep
|
|||||||
{
|
{
|
||||||
Text = "The broad mammalian family of your line. Clade defines the largest "
|
Text = "The broad mammalian family of your line. Clade defines the largest "
|
||||||
+ "strokes — predator or prey, communal or solitary, scent-driven or "
|
+ "strokes — predator or prey, communal or solitary, scent-driven or "
|
||||||
+ "sight-driven. Each clade carries inherited traits and limits that "
|
+ "sight-driven. Hybrid characters blend two lineages.",
|
||||||
+ "no character escapes.",
|
|
||||||
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||||
CustomMinimumSize = new Vector2(0, 0),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_grid = new GridContainer
|
var toggleRow = new HBoxContainer();
|
||||||
{
|
toggleRow.AddThemeConstantOverride("separation", 12);
|
||||||
Columns = 3,
|
AddChild(toggleRow);
|
||||||
SizeFlagsHorizontal = SizeFlags.ExpandFill,
|
_hybridToggle = new CheckBox { Text = "Hybrid Origin (two parent lineages)" };
|
||||||
};
|
_hybridToggle.Toggled += OnHybridToggled;
|
||||||
_grid.AddThemeConstantOverride("h_separation", 16);
|
toggleRow.AddChild(_hybridToggle);
|
||||||
_grid.AddThemeConstantOverride("v_separation", 16);
|
|
||||||
AddChild(_grid);
|
// Purebred section
|
||||||
|
_purebredSection = new VBoxContainer();
|
||||||
|
_purebredSection.AddThemeConstantOverride("separation", 6);
|
||||||
|
AddChild(_purebredSection);
|
||||||
|
var purebredGrid = MakeGrid();
|
||||||
|
_purebredSection.AddChild(purebredGrid);
|
||||||
|
PopulateGrid(purebredGrid, _purebredCards, OnPurebredCladePicked);
|
||||||
|
|
||||||
|
// Hybrid section
|
||||||
|
_hybridSection = new VBoxContainer();
|
||||||
|
_hybridSection.AddThemeConstantOverride("separation", 16);
|
||||||
|
AddChild(_hybridSection);
|
||||||
|
|
||||||
|
_hybridSection.AddChild(new Label { Text = "SIRE — Paternal Lineage" });
|
||||||
|
var sireGrid = MakeGrid();
|
||||||
|
_hybridSection.AddChild(sireGrid);
|
||||||
|
PopulateGrid(sireGrid, _sireCards, id => OnLineageCladePicked("sire", id));
|
||||||
|
|
||||||
|
_hybridSection.AddChild(new Label { Text = "DAM — Maternal Lineage" });
|
||||||
|
var damGrid = MakeGrid();
|
||||||
|
_hybridSection.AddChild(damGrid);
|
||||||
|
PopulateGrid(damGrid, _damCards, id => OnLineageCladePicked("dam", id));
|
||||||
|
|
||||||
|
var dominantRow = new HBoxContainer();
|
||||||
|
dominantRow.AddThemeConstantOverride("separation", 8);
|
||||||
|
_hybridSection.AddChild(dominantRow);
|
||||||
|
dominantRow.AddChild(new Label { Text = "DOMINANT LINEAGE" });
|
||||||
|
_dominantToggle = new OptionButton();
|
||||||
|
_dominantToggle.AddItem("Sire", 0);
|
||||||
|
_dominantToggle.AddItem("Dam", 1);
|
||||||
|
_dominantToggle.ItemSelected += OnDominantSelected;
|
||||||
|
dominantRow.AddChild(_dominantToggle);
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Refresh()
|
private static GridContainer MakeGrid()
|
||||||
{
|
{
|
||||||
if (_grid is null) return;
|
var grid = new GridContainer { Columns = 3, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||||
foreach (var c in _grid.GetChildren()) c.QueueFree();
|
grid.AddThemeConstantOverride("h_separation", 16);
|
||||||
foreach (var clade in CodexContent.Clades)
|
grid.AddThemeConstantOverride("v_separation", 16);
|
||||||
_grid.AddChild(BuildCard(clade));
|
return grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Control BuildCard(CladeDef clade)
|
private void PopulateGrid(GridContainer grid, Dictionary<string, PanelContainer> cardMap, System.Action<string> onClick)
|
||||||
{
|
{
|
||||||
bool selected = _draft.CladeId == clade.Id;
|
foreach (var clade in CodexContent.Clades)
|
||||||
|
{
|
||||||
|
var card = BuildCard(clade, onClick);
|
||||||
|
cardMap[clade.Id] = card;
|
||||||
|
grid.AddChild(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// PanelContainer (a Container subclass) so the card height is
|
private void OnHybridToggled(bool pressed)
|
||||||
// driven by its inner VBoxContainer's content. Switching from
|
{
|
||||||
// Button avoids the issue where Button's intrinsic min size
|
var patch = new Godot.Collections.Dictionary { { "is_hybrid", pressed } };
|
||||||
// doesn't aggregate from non-Button children, causing chips to
|
if (pressed)
|
||||||
// overflow into the cards below at high trait counts.
|
{
|
||||||
|
patch["clade_id"] = "";
|
||||||
|
patch["species_id"] = "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
patch["sire_clade_id"] = "";
|
||||||
|
patch["sire_species_id"] = "";
|
||||||
|
patch["dam_clade_id"] = "";
|
||||||
|
patch["dam_species_id"] = "";
|
||||||
|
}
|
||||||
|
_draft.Patch(patch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDominantSelected(long index)
|
||||||
|
{
|
||||||
|
_draft.Patch(new Godot.Collections.Dictionary
|
||||||
|
{
|
||||||
|
{ "dominant_parent", index == 0 ? "sire" : "dam" },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Refresh()
|
||||||
|
{
|
||||||
|
if (_hybridToggle is null) return;
|
||||||
|
|
||||||
|
bool hybrid = _draft.IsHybrid;
|
||||||
|
if (_hybridToggle.ButtonPressed != hybrid) _hybridToggle.SetPressedNoSignal(hybrid);
|
||||||
|
_purebredSection.Visible = !hybrid;
|
||||||
|
_hybridSection.Visible = hybrid;
|
||||||
|
|
||||||
|
UpdateSelection(_purebredCards, _draft.CladeId);
|
||||||
|
UpdateSelection(_sireCards, _draft.SireCladeId);
|
||||||
|
UpdateSelection(_damCards, _draft.DamCladeId);
|
||||||
|
|
||||||
|
int dominantIdx = _draft.DominantParent == "dam" ? 1 : 0;
|
||||||
|
if (_dominantToggle.Selected != dominantIdx) _dominantToggle.Select(dominantIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateSelection(Dictionary<string, PanelContainer> cards, string selectedId)
|
||||||
|
{
|
||||||
|
foreach (var (id, card) in cards)
|
||||||
|
card.Modulate = id == selectedId ? new Color(1f, 0.95f, 0.85f) : Colors.White;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPurebredCladePicked(string cladeId)
|
||||||
|
{
|
||||||
|
string speciesId = _draft.SpeciesId;
|
||||||
|
var sp = CodexContent.SpeciesById(speciesId);
|
||||||
|
if (sp is null || !string.Equals(sp.CladeId, cladeId, System.StringComparison.OrdinalIgnoreCase))
|
||||||
|
speciesId = "";
|
||||||
|
_draft.Patch(new Godot.Collections.Dictionary
|
||||||
|
{
|
||||||
|
{ "clade_id", cladeId },
|
||||||
|
{ "species_id", speciesId },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLineageCladePicked(string lineage, string cladeId)
|
||||||
|
{
|
||||||
|
var patch = new Godot.Collections.Dictionary
|
||||||
|
{
|
||||||
|
{ lineage + "_clade_id", cladeId },
|
||||||
|
};
|
||||||
|
string currentSpecies = lineage == "sire" ? _draft.SireSpeciesId : _draft.DamSpeciesId;
|
||||||
|
var sp = CodexContent.SpeciesById(currentSpecies);
|
||||||
|
if (sp is null || !string.Equals(sp.CladeId, cladeId, System.StringComparison.OrdinalIgnoreCase))
|
||||||
|
patch[lineage + "_species_id"] = "";
|
||||||
|
_draft.Patch(patch);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PanelContainer BuildCard(CladeDef clade, System.Action<string> onClick)
|
||||||
|
{
|
||||||
var card = new PanelContainer
|
var card = new PanelContainer
|
||||||
{
|
{
|
||||||
CustomMinimumSize = new Vector2(200, 0),
|
CustomMinimumSize = new Vector2(200, 0),
|
||||||
MouseFilter = MouseFilterEnum.Stop,
|
MouseFilter = MouseFilterEnum.Stop,
|
||||||
};
|
};
|
||||||
if (selected) card.Modulate = new Color(1f, 0.95f, 0.85f); // gild tint placeholder until theming
|
|
||||||
|
|
||||||
card.GuiInput += (InputEvent e) =>
|
card.GuiInput += (InputEvent e) =>
|
||||||
{
|
{
|
||||||
if (e is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
if (e is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
||||||
{
|
onClick(clade.Id);
|
||||||
// Default species for the new clade — match React app.jsx:
|
|
||||||
// when clade changes, species defaults to first species in clade.
|
|
||||||
string speciesId = "";
|
|
||||||
foreach (var s in CodexContent.SpeciesOfClade(clade.Id))
|
|
||||||
{
|
|
||||||
speciesId = s.Id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_draft.Patch(new Godot.Collections.Dictionary
|
|
||||||
{
|
|
||||||
{ "clade_id", clade.Id },
|
|
||||||
{ "species_id", speciesId },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var box = new VBoxContainer { MouseFilter = MouseFilterEnum.Pass };
|
var box = new VBoxContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
box.AddThemeConstantOverride("separation", 6);
|
box.AddThemeConstantOverride("separation", 6);
|
||||||
card.AddChild(box);
|
card.AddChild(box);
|
||||||
|
|
||||||
box.AddChild(new Label { Text = clade.Name, MouseFilter = MouseFilterEnum.Ignore });
|
box.AddChild(new Label { Text = clade.Name });
|
||||||
box.AddChild(new Label
|
box.AddChild(new Label { Text = clade.Kind.ToUpperInvariant() });
|
||||||
{
|
|
||||||
Text = clade.Kind.ToUpperInvariant(),
|
|
||||||
MouseFilter = MouseFilterEnum.Ignore,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (clade.AbilityMods.Count > 0)
|
if (clade.AbilityMods.Count > 0)
|
||||||
{
|
{
|
||||||
var modsRow = new HBoxContainer { MouseFilter = MouseFilterEnum.Ignore };
|
var modsRow = new HBoxContainer();
|
||||||
modsRow.AddThemeConstantOverride("separation", 8);
|
modsRow.AddThemeConstantOverride("separation", 8);
|
||||||
box.AddChild(modsRow);
|
box.AddChild(modsRow);
|
||||||
foreach (var (k, v) in clade.AbilityMods)
|
foreach (var (k, v) in clade.AbilityMods)
|
||||||
modsRow.AddChild(new Label
|
modsRow.AddChild(new Label { Text = $"{k} {(v >= 0 ? "+" : "")}{v}" });
|
||||||
{
|
|
||||||
Text = $"{k} {(v >= 0 ? "+" : "")}{v}",
|
|
||||||
MouseFilter = MouseFilterEnum.Ignore,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clade.Traits.Length > 0 || clade.Detriments.Length > 0)
|
if (clade.Traits.Length > 0 || clade.Detriments.Length > 0)
|
||||||
@@ -132,26 +227,10 @@ public partial class StepClade : VBoxContainer, IStep
|
|||||||
chips.AddThemeConstantOverride("h_separation", 6);
|
chips.AddThemeConstantOverride("h_separation", 6);
|
||||||
chips.AddThemeConstantOverride("v_separation", 4);
|
chips.AddThemeConstantOverride("v_separation", 4);
|
||||||
box.AddChild(chips);
|
box.AddChild(chips);
|
||||||
|
|
||||||
foreach (var t in clade.Traits)
|
foreach (var t in clade.Traits)
|
||||||
{
|
chips.AddChild(new TraitChip { TraitName = t.Name, Description = t.Description });
|
||||||
var chip = new TraitChip
|
|
||||||
{
|
|
||||||
TraitName = t.Name,
|
|
||||||
Description = t.Description,
|
|
||||||
};
|
|
||||||
chips.AddChild(chip);
|
|
||||||
}
|
|
||||||
foreach (var d in clade.Detriments)
|
foreach (var d in clade.Detriments)
|
||||||
{
|
chips.AddChild(new TraitChip { TraitName = d.Name, Description = d.Description, Detriment = true });
|
||||||
var chip = new TraitChip
|
|
||||||
{
|
|
||||||
TraitName = d.Name,
|
|
||||||
Description = d.Description,
|
|
||||||
Detriment = true,
|
|
||||||
};
|
|
||||||
chips.AddChild(chip);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return card;
|
return card;
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
using Godot;
|
||||||
|
using System.Linq;
|
||||||
|
using Theriapolis.Core.Data;
|
||||||
|
using Theriapolis.GodotHost.Scenes.Widgets;
|
||||||
|
using Theriapolis.GodotHost.UI;
|
||||||
|
|
||||||
|
namespace Theriapolis.GodotHost.Scenes.Steps;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Step III — Calling. Direct port of <c>StepClass</c> in
|
||||||
|
/// <c>src/steps.jsx</c>: card per class showing hit die, primary
|
||||||
|
/// abilities, saves, and level-1 features (subclass-selection
|
||||||
|
/// stubs filtered out per the React prototype's contract). Class
|
||||||
|
/// change clears chosen skills and the previously-chosen subclass.
|
||||||
|
/// </summary>
|
||||||
|
public partial class StepClass : VBoxContainer, IStep
|
||||||
|
{
|
||||||
|
private CharacterDraft _draft = null!;
|
||||||
|
private GridContainer _grid = null!;
|
||||||
|
|
||||||
|
public void Bind(CharacterDraft draft)
|
||||||
|
{
|
||||||
|
_draft = draft;
|
||||||
|
// Defer Refresh so it runs after the click callback that triggered
|
||||||
|
// Changed completes (avoids the Free()-during-signal duplicate bug).
|
||||||
|
_draft.Changed += () => Callable.From(Refresh).CallDeferred();
|
||||||
|
Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Validate() =>
|
||||||
|
string.IsNullOrEmpty(_draft?.ClassId) ? "Pick a calling." : null;
|
||||||
|
|
||||||
|
private void Build()
|
||||||
|
{
|
||||||
|
AddThemeConstantOverride("separation", 16);
|
||||||
|
|
||||||
|
var intro = new VBoxContainer();
|
||||||
|
intro.AddThemeConstantOverride("separation", 6);
|
||||||
|
AddChild(intro);
|
||||||
|
intro.AddChild(new Label { Text = "FOLIO III · CALLING" });
|
||||||
|
intro.AddChild(new Label { Text = "Choose a Calling" });
|
||||||
|
intro.AddChild(new Label
|
||||||
|
{
|
||||||
|
Text = "Your character's path — fighter, hunter, scholar, or something stranger. "
|
||||||
|
+ "The calling fixes your hit die, primary abilities, saving-throw "
|
||||||
|
+ "proficiencies, and the level-1 feature set you start play with.",
|
||||||
|
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||||
|
});
|
||||||
|
|
||||||
|
_grid = new GridContainer { Columns = 3, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||||
|
_grid.AddThemeConstantOverride("h_separation", 16);
|
||||||
|
_grid.AddThemeConstantOverride("v_separation", 16);
|
||||||
|
AddChild(_grid);
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Refresh()
|
||||||
|
{
|
||||||
|
if (_grid is null) return;
|
||||||
|
foreach (var c in _grid.GetChildren()) c.QueueFree();
|
||||||
|
foreach (var cls in CodexContent.Classes)
|
||||||
|
_grid.AddChild(BuildCard(cls));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Control BuildCard(ClassDef cls)
|
||||||
|
{
|
||||||
|
bool selected = _draft.ClassId == cls.Id;
|
||||||
|
|
||||||
|
var card = new PanelContainer
|
||||||
|
{
|
||||||
|
CustomMinimumSize = new Vector2(200, 0),
|
||||||
|
MouseFilter = MouseFilterEnum.Stop,
|
||||||
|
};
|
||||||
|
if (selected) card.Modulate = new Color(1f, 0.95f, 0.85f);
|
||||||
|
|
||||||
|
card.GuiInput += (InputEvent e) =>
|
||||||
|
{
|
||||||
|
if (e is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
||||||
|
{
|
||||||
|
// Class change: reset subclass + chosen skills, mirroring
|
||||||
|
// app.jsx's useEffect on classId.
|
||||||
|
_draft.Patch(new Godot.Collections.Dictionary
|
||||||
|
{
|
||||||
|
{ "class_id", cls.Id },
|
||||||
|
{ "subclass_id", "" },
|
||||||
|
{ "chosen_skills", new Godot.Collections.Array<string>() },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var box = new VBoxContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
box.AddThemeConstantOverride("separation", 6);
|
||||||
|
card.AddChild(box);
|
||||||
|
|
||||||
|
box.AddChild(new Label { Text = cls.Name });
|
||||||
|
box.AddChild(new Label
|
||||||
|
{
|
||||||
|
Text = $"d{cls.HitDie} · {string.Join("/", cls.PrimaryAbility)}",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (cls.Saves.Length > 0)
|
||||||
|
{
|
||||||
|
var savesRow = new HBoxContainer();
|
||||||
|
savesRow.AddThemeConstantOverride("separation", 6);
|
||||||
|
box.AddChild(savesRow);
|
||||||
|
savesRow.AddChild(new Label { Text = "SAVES" });
|
||||||
|
foreach (var s in cls.Saves)
|
||||||
|
savesRow.AddChild(new Label { Text = s });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level-1 features. Filter out stubs and subclass-selection markers
|
||||||
|
// (the React prototype hides the subclass picker on the class card).
|
||||||
|
var lvl1 = cls.LevelTable.FirstOrDefault(e => e.Level == 1);
|
||||||
|
if (lvl1?.Features.Length > 0)
|
||||||
|
{
|
||||||
|
var featChips = new HFlowContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
featChips.AddThemeConstantOverride("h_separation", 6);
|
||||||
|
featChips.AddThemeConstantOverride("v_separation", 4);
|
||||||
|
box.AddChild(featChips);
|
||||||
|
|
||||||
|
foreach (var fid in lvl1.Features)
|
||||||
|
{
|
||||||
|
if (!cls.FeatureDefinitions.TryGetValue(fid, out var fd)) continue;
|
||||||
|
if (fd.Kind == "stub" || fid.StartsWith("subclass_")) continue;
|
||||||
|
featChips.AddChild(new TraitChip
|
||||||
|
{
|
||||||
|
TraitName = fd.Name,
|
||||||
|
Description = fd.Description,
|
||||||
|
Tag = fd.Kind,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
using Godot;
|
||||||
|
using Theriapolis.Core.Data;
|
||||||
|
using Theriapolis.GodotHost.Scenes.Widgets;
|
||||||
|
using Theriapolis.GodotHost.UI;
|
||||||
|
|
||||||
|
namespace Theriapolis.GodotHost.Scenes.Steps;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Step II — Species. Direct port of <c>StepSpecies</c> in
|
||||||
|
/// <c>src/steps.jsx</c> plus the Phase 6.5 hybrid extension: when
|
||||||
|
/// <see cref="CharacterDraft.IsHybrid"/> is true the step shows two
|
||||||
|
/// stacked grids, one filtered by SireCladeId and one by DamCladeId.
|
||||||
|
/// </summary>
|
||||||
|
public partial class StepSpecies : VBoxContainer, IStep
|
||||||
|
{
|
||||||
|
private CharacterDraft _draft = null!;
|
||||||
|
private VBoxContainer _purebredSection = null!;
|
||||||
|
private VBoxContainer _hybridSection = null!;
|
||||||
|
private GridContainer _purebredGrid = null!;
|
||||||
|
private GridContainer _sireGrid = null!;
|
||||||
|
private GridContainer _damGrid = null!;
|
||||||
|
|
||||||
|
public void Bind(CharacterDraft draft)
|
||||||
|
{
|
||||||
|
_draft = draft;
|
||||||
|
// Defer Refresh so it runs after the click callback that triggered
|
||||||
|
// Changed completes — Free() called on a card mid-callback returns
|
||||||
|
// without freeing, leaving a stale duplicate in the grid.
|
||||||
|
_draft.Changed += () => Callable.From(Refresh).CallDeferred();
|
||||||
|
Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Validate() => WizardValidation.Validate(1, _draft);
|
||||||
|
|
||||||
|
private void Build()
|
||||||
|
{
|
||||||
|
AddThemeConstantOverride("separation", 16);
|
||||||
|
|
||||||
|
var intro = new VBoxContainer();
|
||||||
|
intro.AddThemeConstantOverride("separation", 6);
|
||||||
|
AddChild(intro);
|
||||||
|
intro.AddChild(new Label { Text = "FOLIO II · SPECIES" });
|
||||||
|
intro.AddChild(new Label { Text = "Choose a Species" });
|
||||||
|
intro.AddChild(new Label
|
||||||
|
{
|
||||||
|
Text = "Refine your line. Species inherits the clade's traits and adds its "
|
||||||
|
+ "own — body size, base movement speed, and species-specific abilities. "
|
||||||
|
+ "Hybrid characters pick one species per parent lineage.",
|
||||||
|
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||||
|
});
|
||||||
|
|
||||||
|
_purebredSection = new VBoxContainer();
|
||||||
|
_purebredSection.AddThemeConstantOverride("separation", 6);
|
||||||
|
AddChild(_purebredSection);
|
||||||
|
_purebredGrid = MakeGrid();
|
||||||
|
_purebredSection.AddChild(_purebredGrid);
|
||||||
|
|
||||||
|
_hybridSection = new VBoxContainer();
|
||||||
|
_hybridSection.AddThemeConstantOverride("separation", 16);
|
||||||
|
AddChild(_hybridSection);
|
||||||
|
|
||||||
|
_hybridSection.AddChild(new Label { Text = "SIRE — Paternal Lineage" });
|
||||||
|
_sireGrid = MakeGrid();
|
||||||
|
_hybridSection.AddChild(_sireGrid);
|
||||||
|
|
||||||
|
_hybridSection.AddChild(new Label { Text = "DAM — Maternal Lineage" });
|
||||||
|
_damGrid = MakeGrid();
|
||||||
|
_hybridSection.AddChild(_damGrid);
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GridContainer MakeGrid()
|
||||||
|
{
|
||||||
|
var grid = new GridContainer { Columns = 3, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||||
|
grid.AddThemeConstantOverride("h_separation", 16);
|
||||||
|
grid.AddThemeConstantOverride("v_separation", 16);
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Refresh()
|
||||||
|
{
|
||||||
|
if (_purebredGrid is null) return;
|
||||||
|
bool hybrid = _draft.IsHybrid;
|
||||||
|
_purebredSection.Visible = !hybrid;
|
||||||
|
_hybridSection.Visible = hybrid;
|
||||||
|
|
||||||
|
if (hybrid)
|
||||||
|
{
|
||||||
|
RefreshGrid(_sireGrid, _draft.SireCladeId, _draft.SireSpeciesId,
|
||||||
|
spId => _draft.Patch(new Godot.Collections.Dictionary { { "sire_species_id", spId } }));
|
||||||
|
RefreshGrid(_damGrid, _draft.DamCladeId, _draft.DamSpeciesId,
|
||||||
|
spId => _draft.Patch(new Godot.Collections.Dictionary { { "dam_species_id", spId } }));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RefreshGrid(_purebredGrid, _draft.CladeId, _draft.SpeciesId,
|
||||||
|
spId => _draft.Patch(new Godot.Collections.Dictionary { { "species_id", spId } }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void RefreshGrid(GridContainer grid, string cladeId, string selectedSpecies, System.Action<string> onClick)
|
||||||
|
{
|
||||||
|
foreach (var c in grid.GetChildren()) c.Free();
|
||||||
|
if (string.IsNullOrEmpty(cladeId)) return;
|
||||||
|
foreach (var sp in CodexContent.SpeciesOfClade(cladeId))
|
||||||
|
grid.AddChild(BuildCard(sp, sp.Id == selectedSpecies, onClick));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Control BuildCard(SpeciesDef sp, bool selected, System.Action<string> onClick)
|
||||||
|
{
|
||||||
|
var card = new PanelContainer
|
||||||
|
{
|
||||||
|
CustomMinimumSize = new Vector2(200, 0),
|
||||||
|
MouseFilter = MouseFilterEnum.Stop,
|
||||||
|
};
|
||||||
|
if (selected) card.Modulate = new Color(1f, 0.95f, 0.85f);
|
||||||
|
|
||||||
|
card.GuiInput += (InputEvent e) =>
|
||||||
|
{
|
||||||
|
if (e is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
||||||
|
onClick(sp.Id);
|
||||||
|
};
|
||||||
|
|
||||||
|
var box = new VBoxContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
box.AddThemeConstantOverride("separation", 6);
|
||||||
|
card.AddChild(box);
|
||||||
|
|
||||||
|
box.AddChild(new Label { Text = sp.Name });
|
||||||
|
box.AddChild(new Label { Text = $"{sp.Size.ToUpperInvariant()} · {sp.BaseSpeedFt} FT/TURN" });
|
||||||
|
|
||||||
|
if (sp.AbilityMods.Count > 0)
|
||||||
|
{
|
||||||
|
var modsRow = new HBoxContainer();
|
||||||
|
modsRow.AddThemeConstantOverride("separation", 8);
|
||||||
|
box.AddChild(modsRow);
|
||||||
|
foreach (var (k, v) in sp.AbilityMods)
|
||||||
|
modsRow.AddChild(new Label { Text = $"{k} {(v >= 0 ? "+" : "")}{v}" });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sp.Traits.Length > 0 || sp.Detriments.Length > 0)
|
||||||
|
{
|
||||||
|
var chips = new HFlowContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
chips.AddThemeConstantOverride("h_separation", 6);
|
||||||
|
chips.AddThemeConstantOverride("v_separation", 4);
|
||||||
|
box.AddChild(chips);
|
||||||
|
foreach (var t in sp.Traits)
|
||||||
|
chips.AddChild(new TraitChip { TraitName = t.Name, Description = t.Description });
|
||||||
|
foreach (var d in sp.Detriments)
|
||||||
|
chips.AddChild(new TraitChip { TraitName = d.Name, Description = d.Description, Detriment = true });
|
||||||
|
}
|
||||||
|
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,9 +37,6 @@ public partial class StepStats : VBoxContainer, IStep
|
|||||||
private Button _rollBtn = null!;
|
private Button _rollBtn = null!;
|
||||||
private Button _rerollBtn = null!;
|
private Button _rerollBtn = null!;
|
||||||
private Button _autoBtn = null!;
|
private Button _autoBtn = null!;
|
||||||
private ScrollContainer? _scroll;
|
|
||||||
private int _savedScroll = -1;
|
|
||||||
private bool _scrollPending;
|
|
||||||
|
|
||||||
public void Bind(CharacterDraft draft)
|
public void Bind(CharacterDraft draft)
|
||||||
{
|
{
|
||||||
@@ -61,7 +58,7 @@ public partial class StepStats : VBoxContainer, IStep
|
|||||||
var intro = new VBoxContainer();
|
var intro = new VBoxContainer();
|
||||||
intro.AddThemeConstantOverride("separation", 6);
|
intro.AddThemeConstantOverride("separation", 6);
|
||||||
AddChild(intro);
|
AddChild(intro);
|
||||||
intro.AddChild(new Label { Text = "FOLIO V · ABILITIES" });
|
intro.AddChild(new Label { Text = "FOLIO VI · ABILITIES" });
|
||||||
intro.AddChild(new Label { Text = "Assign your Ability Scores" });
|
intro.AddChild(new Label { Text = "Assign your Ability Scores" });
|
||||||
intro.AddChild(new Label
|
intro.AddChild(new Label
|
||||||
{
|
{
|
||||||
@@ -139,15 +136,8 @@ public partial class StepStats : VBoxContainer, IStep
|
|||||||
private void Refresh()
|
private void Refresh()
|
||||||
{
|
{
|
||||||
if (_pool is null) return;
|
if (_pool is null) return;
|
||||||
|
// Scroll preservation now handled centrally by Wizard.UpdateChrome
|
||||||
// Tearing down + rebuilding child token trees triggers a layout
|
// / Wizard._Process, which snapshots before this Refresh fires.
|
||||||
// pass that resets the parent ScrollContainer's vertical scroll.
|
|
||||||
// Snapshot the scroll position and restore it after the new layout
|
|
||||||
// settles. The restore goes through a method (not SetDeferred on
|
|
||||||
// the property) so it runs reliably after layout finishes — the
|
|
||||||
// method is queued via CallDeferred at the end of Refresh.
|
|
||||||
_scroll = FindAncestorScroll();
|
|
||||||
_savedScroll = _scroll?.ScrollVertical ?? -1;
|
|
||||||
|
|
||||||
// Toolbar reflects current method and assignment state.
|
// Toolbar reflects current method and assignment state.
|
||||||
bool isRoll = _draft.StatMethod == "roll";
|
bool isRoll = _draft.StatMethod == "roll";
|
||||||
@@ -197,31 +187,6 @@ public partial class StepStats : VBoxContainer, IStep
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore scroll on the next _Process frame — after layout has fully
|
|
||||||
// converged. CallDeferred / SetDeferred / CreateTimer all proved
|
|
||||||
// racy because the ScrollContainer re-clamps scroll on later layout
|
|
||||||
// passes triggered by tree mutations elsewhere.
|
|
||||||
if (_savedScroll >= 0 && _scroll is not null) _scrollPending = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _Process(double delta)
|
|
||||||
{
|
|
||||||
if (_scrollPending && _scroll is not null && IsInstanceValid(_scroll))
|
|
||||||
{
|
|
||||||
_scroll.ScrollVertical = _savedScroll;
|
|
||||||
}
|
|
||||||
_scrollPending = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ScrollContainer? FindAncestorScroll()
|
|
||||||
{
|
|
||||||
Node? n = GetParent();
|
|
||||||
while (n is not null)
|
|
||||||
{
|
|
||||||
if (n is ScrollContainer sc) return sc;
|
|
||||||
n = n.GetParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
using Godot;
|
||||||
|
using System.Linq;
|
||||||
|
using Theriapolis.Core.Data;
|
||||||
|
using Theriapolis.GodotHost.Scenes.Widgets;
|
||||||
|
using Theriapolis.GodotHost.UI;
|
||||||
|
|
||||||
|
namespace Theriapolis.GodotHost.Scenes.Steps;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Step IV — Subclass. New vs the React prototype (which is pre-Phase
|
||||||
|
/// 6.5); per port plan §10, dedicated step rather than inline picker.
|
||||||
|
/// Cards filtered by the chosen class's <c>SubclassIds</c>. Selecting
|
||||||
|
/// commits via Patch(subclass_id).
|
||||||
|
/// </summary>
|
||||||
|
public partial class StepSubclass : VBoxContainer, IStep
|
||||||
|
{
|
||||||
|
private CharacterDraft _draft = null!;
|
||||||
|
private GridContainer _grid = null!;
|
||||||
|
|
||||||
|
public void Bind(CharacterDraft draft)
|
||||||
|
{
|
||||||
|
_draft = draft;
|
||||||
|
_draft.Changed += () => Callable.From(Refresh).CallDeferred();
|
||||||
|
Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? Validate()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_draft?.SubclassId)) return "Pick a subclass.";
|
||||||
|
var sub = System.Array.Find(CodexContent.Subclasses, s => s.Id == _draft.SubclassId);
|
||||||
|
if (sub is null || !string.Equals(sub.ClassId, _draft.ClassId, System.StringComparison.OrdinalIgnoreCase))
|
||||||
|
return "Selected subclass doesn't belong to the current calling.";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Build()
|
||||||
|
{
|
||||||
|
AddThemeConstantOverride("separation", 16);
|
||||||
|
|
||||||
|
var intro = new VBoxContainer();
|
||||||
|
intro.AddThemeConstantOverride("separation", 6);
|
||||||
|
AddChild(intro);
|
||||||
|
intro.AddChild(new Label { Text = "FOLIO IV · SUBCLASS" });
|
||||||
|
intro.AddChild(new Label { Text = "Choose a Subclass" });
|
||||||
|
intro.AddChild(new Label
|
||||||
|
{
|
||||||
|
Text = "Specialization within your calling. Subclass features unlock at "
|
||||||
|
+ "level 3 and beyond, but the choice is locked in now — only subclasses "
|
||||||
|
+ "available to your chosen calling are shown.",
|
||||||
|
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||||
|
});
|
||||||
|
|
||||||
|
_grid = new GridContainer { Columns = 3, SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||||
|
_grid.AddThemeConstantOverride("h_separation", 16);
|
||||||
|
_grid.AddThemeConstantOverride("v_separation", 16);
|
||||||
|
AddChild(_grid);
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Refresh()
|
||||||
|
{
|
||||||
|
if (_grid is null) return;
|
||||||
|
foreach (var c in _grid.GetChildren()) c.QueueFree();
|
||||||
|
|
||||||
|
var cls = CodexContent.Class(_draft.ClassId);
|
||||||
|
if (cls is null) return;
|
||||||
|
|
||||||
|
foreach (var subId in cls.SubclassIds)
|
||||||
|
{
|
||||||
|
var sub = System.Array.Find(CodexContent.Subclasses, s => s.Id == subId);
|
||||||
|
if (sub is not null) _grid.AddChild(BuildCard(sub));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Control BuildCard(SubclassDef sub)
|
||||||
|
{
|
||||||
|
bool selected = _draft.SubclassId == sub.Id;
|
||||||
|
|
||||||
|
var card = new PanelContainer
|
||||||
|
{
|
||||||
|
CustomMinimumSize = new Vector2(200, 0),
|
||||||
|
MouseFilter = MouseFilterEnum.Stop,
|
||||||
|
};
|
||||||
|
if (selected) card.Modulate = new Color(1f, 0.95f, 0.85f);
|
||||||
|
|
||||||
|
card.GuiInput += (InputEvent e) =>
|
||||||
|
{
|
||||||
|
if (e is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
|
||||||
|
_draft.Patch(new Godot.Collections.Dictionary { { "subclass_id", sub.Id } });
|
||||||
|
};
|
||||||
|
|
||||||
|
var box = new VBoxContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
box.AddThemeConstantOverride("separation", 6);
|
||||||
|
card.AddChild(box);
|
||||||
|
|
||||||
|
box.AddChild(new Label { Text = sub.Name });
|
||||||
|
if (!string.IsNullOrEmpty(sub.Flavor))
|
||||||
|
{
|
||||||
|
box.AddChild(new Label
|
||||||
|
{
|
||||||
|
Text = sub.Flavor,
|
||||||
|
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Level-3 features (the first unlock for any subclass).
|
||||||
|
var l3 = sub.LevelFeatures.FirstOrDefault(e => e.Level == 3);
|
||||||
|
if (l3?.Features.Length > 0)
|
||||||
|
{
|
||||||
|
var featChips = new HFlowContainer { MouseFilter = MouseFilterEnum.Pass };
|
||||||
|
featChips.AddThemeConstantOverride("h_separation", 6);
|
||||||
|
featChips.AddThemeConstantOverride("v_separation", 4);
|
||||||
|
box.AddChild(featChips);
|
||||||
|
|
||||||
|
foreach (var fid in l3.Features)
|
||||||
|
{
|
||||||
|
if (!sub.FeatureDefinitions.TryGetValue(fid, out var fd)) continue;
|
||||||
|
if (fd.Kind == "stub") continue;
|
||||||
|
featChips.AddChild(new TraitChip
|
||||||
|
{
|
||||||
|
TraitName = fd.Name,
|
||||||
|
Description = fd.Description,
|
||||||
|
Tag = "L3 · " + fd.Kind,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,18 +32,26 @@ public partial class Wizard : Control
|
|||||||
private Button _backBtn = null!;
|
private Button _backBtn = null!;
|
||||||
private Button _nextBtn = null!;
|
private Button _nextBtn = null!;
|
||||||
|
|
||||||
|
// Scroll preservation: snapshot scroll position when the draft changes
|
||||||
|
// (which fires before the active step's Refresh tears down + rebuilds
|
||||||
|
// child nodes), then restore on the next _Process frame so the user
|
||||||
|
// doesn't get punted to the top of the page when selecting a card.
|
||||||
|
private ScrollContainer? _scroll;
|
||||||
|
private int _savedScroll = -1;
|
||||||
|
private bool _scrollPending;
|
||||||
|
|
||||||
private int _step;
|
private int _step;
|
||||||
private Steps.IStep? _activeStep;
|
private Steps.IStep? _activeStep;
|
||||||
private static readonly System.Type?[] StepTypes =
|
private static readonly System.Type?[] StepTypes =
|
||||||
{
|
{
|
||||||
typeof(Steps.StepClade), // 0 Clade — implemented
|
typeof(Steps.StepClade), // 0 Clade
|
||||||
null, // 1 Species
|
typeof(Steps.StepSpecies), // 1 Species
|
||||||
null, // 2 Calling
|
typeof(Steps.StepClass), // 2 Calling
|
||||||
null, // 3 Subclass
|
typeof(Steps.StepSubclass), // 3 Subclass
|
||||||
null, // 4 History
|
typeof(Steps.StepBackground), // 4 History
|
||||||
typeof(Steps.StepStats), // 5 Abilities — implemented (M6.2)
|
typeof(Steps.StepStats), // 5 Abilities
|
||||||
null, // 6 Skills
|
null, // 6 Skills — M6.5
|
||||||
null, // 7 Sign
|
null, // 7 Sign — M6.6
|
||||||
};
|
};
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
@@ -57,6 +65,7 @@ public partial class Wizard : Control
|
|||||||
_navProgress = GetNode<Label>("%NavProgress");
|
_navProgress = GetNode<Label>("%NavProgress");
|
||||||
_backBtn = GetNode<Button>("%BackButton");
|
_backBtn = GetNode<Button>("%BackButton");
|
||||||
_nextBtn = GetNode<Button>("%NextButton");
|
_nextBtn = GetNode<Button>("%NextButton");
|
||||||
|
_scroll = GetNode<ScrollContainer>("%Scroll");
|
||||||
|
|
||||||
var aside = GetNode<Aside>("%Aside");
|
var aside = GetNode<Aside>("%Aside");
|
||||||
aside.SetDraft(Character);
|
aside.SetDraft(Character);
|
||||||
@@ -102,9 +111,11 @@ public partial class Wizard : Control
|
|||||||
private void OnStepperClicked(int index)
|
private void OnStepperClicked(int index)
|
||||||
{
|
{
|
||||||
if (index <= _step) { SwitchToStep(index); return; }
|
if (index <= _step) { SwitchToStep(index); return; }
|
||||||
// Forward jump requires current step satisfied. Unimplemented future
|
// Forward jump requires every step in [0..index-1] satisfied — not
|
||||||
// steps still accept the jump — SwitchToStep will show a placeholder.
|
// just the current step. Otherwise picking a clade would let you
|
||||||
if (_activeStep?.Validate() is not null) return;
|
// skip straight to Abilities without picking species/calling/etc.
|
||||||
|
for (int i = 0; i < index; i++)
|
||||||
|
if (UI.WizardValidation.Validate(i, Character) is not null) return;
|
||||||
SwitchToStep(index);
|
SwitchToStep(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,39 +135,76 @@ public partial class Wizard : Control
|
|||||||
|
|
||||||
private void UpdateChrome()
|
private void UpdateChrome()
|
||||||
{
|
{
|
||||||
|
// Snapshot scroll BEFORE the active step's Refresh handler fires
|
||||||
|
// (it's the next subscriber in the Changed chain). The scroll
|
||||||
|
// position then survives the rebuild via _Process below.
|
||||||
|
if (_scroll is not null)
|
||||||
|
{
|
||||||
|
_savedScroll = _scroll.ScrollVertical;
|
||||||
|
if (_savedScroll > 0) _scrollPending = true;
|
||||||
|
}
|
||||||
|
|
||||||
_folioLabel.Text = $"Folio {Roman(_step + 1)} of VIII — {StepNames[_step]}";
|
_folioLabel.Text = $"Folio {Roman(_step + 1)} of VIII — {StepNames[_step]}";
|
||||||
|
|
||||||
bool valid = _activeStep?.Validate() is null;
|
// Validate via the static helper so stepper-state propagation and
|
||||||
string? err = _activeStep?.Validate();
|
// the active-step banner share one source of truth.
|
||||||
|
string? err = UI.WizardValidation.Validate(_step, Character);
|
||||||
|
bool valid = err is null;
|
||||||
_validation.Text = err ?? (_step == StepKeys.Length - 1 ? "Ready to sign" : "Folio complete");
|
_validation.Text = err ?? (_step == StepKeys.Length - 1 ? "Ready to sign" : "Folio complete");
|
||||||
_nextBtn.Disabled = !valid;
|
_nextBtn.Disabled = !valid;
|
||||||
_nextBtn.Visible = _step < StepKeys.Length - 1;
|
_nextBtn.Visible = _step < StepKeys.Length - 1;
|
||||||
_backBtn.Text = _step == 0 ? "← Title" : "← Back";
|
_backBtn.Text = _step == 0 ? "← Title" : "← Back";
|
||||||
_navProgress.Text = $"{_step + 1} / {StepKeys.Length}";
|
_navProgress.Text = $"{_step + 1} / {StepKeys.Length}";
|
||||||
|
|
||||||
RebuildStepperStates(valid);
|
RebuildStepperStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RebuildStepperStates(bool currentSatisfied)
|
private void RebuildStepperStates()
|
||||||
{
|
{
|
||||||
// Mirrors app.jsx's lock semantics: a step is Locked iff some EARLIER
|
// Mirrors app.jsx's lock semantics exactly: a step is Locked iff
|
||||||
// step is unsatisfied. "Type not yet implemented" doesn't affect the
|
// some EARLIER step's validator fails. Use FirstIncomplete to find
|
||||||
// lock state — clicking an unimplemented step just shows a placeholder.
|
// the boundary, then state each step accordingly. This is what
|
||||||
|
// makes "pick a clade and skip straight to Abilities" impossible —
|
||||||
|
// any step after FirstIncomplete is Locked.
|
||||||
|
int firstIncomplete = UI.WizardValidation.FirstIncomplete(Character, StepNames.Length);
|
||||||
var states = new UI.Widgets.CodexStepper.StepState[StepNames.Length];
|
var states = new UI.Widgets.CodexStepper.StepState[StepNames.Length];
|
||||||
|
|
||||||
for (int i = 0; i < StepNames.Length; i++)
|
for (int i = 0; i < StepNames.Length; i++)
|
||||||
{
|
{
|
||||||
if (i == _step)
|
if (i == _step)
|
||||||
|
{
|
||||||
states[i] = UI.Widgets.CodexStepper.StepState.Active;
|
states[i] = UI.Widgets.CodexStepper.StepState.Active;
|
||||||
|
}
|
||||||
else if (i < _step)
|
else if (i < _step)
|
||||||
states[i] = UI.Widgets.CodexStepper.StepState.Complete;
|
{
|
||||||
else
|
// Already-visited step. Complete if it still validates,
|
||||||
states[i] = currentSatisfied
|
// Locked if the user has since invalidated it (e.g. cleared
|
||||||
? UI.Widgets.CodexStepper.StepState.Pending
|
// a field). Locked variants past _step also show.
|
||||||
|
states[i] = UI.WizardValidation.Validate(i, Character) is null
|
||||||
|
? UI.Widgets.CodexStepper.StepState.Complete
|
||||||
: UI.Widgets.CodexStepper.StepState.Locked;
|
: UI.Widgets.CodexStepper.StepState.Locked;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Future step. Locked iff some earlier step is incomplete.
|
||||||
|
bool locked = firstIncomplete != -1 && firstIncomplete < i;
|
||||||
|
states[i] = locked
|
||||||
|
? UI.Widgets.CodexStepper.StepState.Locked
|
||||||
|
: UI.Widgets.CodexStepper.StepState.Pending;
|
||||||
|
}
|
||||||
|
}
|
||||||
_stepper.SetSteps(StepNames, states);
|
_stepper.SetSteps(StepNames, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
if (_scrollPending && _scroll is not null && IsInstanceValid(_scroll))
|
||||||
|
{
|
||||||
|
_scroll.ScrollVertical = _savedScroll;
|
||||||
|
}
|
||||||
|
_scrollPending = false;
|
||||||
|
}
|
||||||
|
|
||||||
private static string Roman(int n) => n switch
|
private static string Roman(int n) => n switch
|
||||||
{
|
{
|
||||||
1 => "I", 2 => "II", 3 => "III", 4 => "IV",
|
1 => "I", 2 => "II", 3 => "III", 4 => "IV",
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ theme_override_constants/margin_top = 16
|
|||||||
theme_override_constants/margin_bottom = 16
|
theme_override_constants/margin_bottom = 16
|
||||||
|
|
||||||
[node name="Scroll" type="ScrollContainer" parent="Wrap/Layout/Page/PageMain"]
|
[node name="Scroll" type="ScrollContainer" parent="Wrap/Layout/Page/PageMain"]
|
||||||
|
unique_name_in_owner = true
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
horizontal_scroll_mode = 0
|
horizontal_scroll_mode = 0
|
||||||
|
|||||||
@@ -28,6 +28,54 @@ public partial class CharacterDraft : Resource
|
|||||||
[Export] public string SubclassId { get; set; } = "";
|
[Export] public string SubclassId { get; set; } = "";
|
||||||
[Export] public string BackgroundId { get; set; } = "";
|
[Export] public string BackgroundId { get; set; } = "";
|
||||||
|
|
||||||
|
// ── Phase 6.5 hybrid origin ────────────────────────────────────────
|
||||||
|
/// <summary>True when the PC is a hybrid (two parent lineages).</summary>
|
||||||
|
[Export] public bool IsHybrid { get; set; }
|
||||||
|
[Export] public string SireCladeId { get; set; } = "";
|
||||||
|
[Export] public string SireSpeciesId { get; set; } = "";
|
||||||
|
[Export] public string DamCladeId { get; set; } = "";
|
||||||
|
[Export] public string DamSpeciesId { get; set; } = "";
|
||||||
|
/// <summary>"sire" or "dam" — which parent the PC presents as.</summary>
|
||||||
|
[Export] public string DominantParent { get; set; } = "sire";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resolves the "active" clade for downstream steps (Class / Subclass
|
||||||
|
/// / Background). Purebred uses <see cref="CladeId"/>; hybrids use
|
||||||
|
/// the dominant parent's clade.
|
||||||
|
/// </summary>
|
||||||
|
public string EffectiveCladeId => IsHybrid
|
||||||
|
? (DominantParent == "sire" ? SireCladeId : DamCladeId)
|
||||||
|
: CladeId;
|
||||||
|
|
||||||
|
/// <summary>Same logic as <see cref="EffectiveCladeId"/>, for species.</summary>
|
||||||
|
public string EffectiveSpeciesId => IsHybrid
|
||||||
|
? (DominantParent == "sire" ? SireSpeciesId : DamSpeciesId)
|
||||||
|
: SpeciesId;
|
||||||
|
|
||||||
|
/// <summary>True iff the character includes <paramref name="cladeId"/>
|
||||||
|
/// in its lineage. Purebred matches CladeId; hybrid matches if either
|
||||||
|
/// Sire or Dam clade equals the id (case-insensitive).</summary>
|
||||||
|
public bool HasClade(string cladeId)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(cladeId)) return false;
|
||||||
|
if (IsHybrid)
|
||||||
|
return string.Equals(SireCladeId, cladeId, System.StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| string.Equals(DamCladeId, cladeId, System.StringComparison.OrdinalIgnoreCase);
|
||||||
|
return string.Equals(CladeId, cladeId, System.StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>True iff any clade in the character's lineage has the
|
||||||
|
/// given <paramref name="kind"/> ("predator" or "prey").</summary>
|
||||||
|
public bool HasAnyCladeOfKind(string kind)
|
||||||
|
{
|
||||||
|
if (IsHybrid)
|
||||||
|
{
|
||||||
|
return CodexContent.Clade(SireCladeId)?.Kind == kind
|
||||||
|
|| CodexContent.Clade(DamCladeId)?.Kind == kind;
|
||||||
|
}
|
||||||
|
return CodexContent.Clade(CladeId)?.Kind == kind;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>"array" or "roll" — assignment method for ability scores.</summary>
|
/// <summary>"array" or "roll" — assignment method for ability scores.</summary>
|
||||||
[Export] public string StatMethod { get; set; } = "array";
|
[Export] public string StatMethod { get; set; } = "array";
|
||||||
[Export] public Godot.Collections.Array<int> StatPool { get; set; }
|
[Export] public Godot.Collections.Array<int> StatPool { get; set; }
|
||||||
@@ -58,6 +106,12 @@ public partial class CharacterDraft : Resource
|
|||||||
case "stat_assign": StatAssign = (Godot.Collections.Dictionary)patch[key]; break;
|
case "stat_assign": StatAssign = (Godot.Collections.Dictionary)patch[key]; break;
|
||||||
case "chosen_skills": ChosenSkills = (Godot.Collections.Array<string>)patch[key]; break;
|
case "chosen_skills": ChosenSkills = (Godot.Collections.Array<string>)patch[key]; break;
|
||||||
case "character_name": CharacterName = (string)patch[key]; break;
|
case "character_name": CharacterName = (string)patch[key]; break;
|
||||||
|
case "is_hybrid": IsHybrid = (bool)patch[key]; break;
|
||||||
|
case "sire_clade_id": SireCladeId = (string)patch[key]; break;
|
||||||
|
case "sire_species_id": SireSpeciesId = (string)patch[key]; break;
|
||||||
|
case "dam_clade_id": DamCladeId = (string)patch[key]; break;
|
||||||
|
case "dam_species_id": DamSpeciesId = (string)patch[key]; break;
|
||||||
|
case "dominant_parent": DominantParent = (string)patch[key]; break;
|
||||||
default:
|
default:
|
||||||
GD.PushWarning($"[CharacterDraft] unknown patch key: {k}");
|
GD.PushWarning($"[CharacterDraft] unknown patch key: {k}");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
namespace Theriapolis.GodotHost.UI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Per-step validation against a CharacterDraft. Mirrors <c>app.jsx</c>'s
|
||||||
|
/// <c>validate(i)</c> exactly: returns null when step <c>i</c>'s
|
||||||
|
/// requirements are met, or a short error message otherwise. Static so
|
||||||
|
/// the Wizard can ask "is step N satisfied?" without instantiating each
|
||||||
|
/// step's UI — needed to compute Locked/Pending states across the whole
|
||||||
|
/// flow, not just the current step.
|
||||||
|
///
|
||||||
|
/// React prototype's app.jsx logic:
|
||||||
|
/// firstIncomplete = STEPS.findIndex(j => validate(j));
|
||||||
|
/// locked = i > step && firstIncomplete !== -1 && firstIncomplete < i;
|
||||||
|
///
|
||||||
|
/// (i.e. a step is locked iff some EARLIER step fails its validator).
|
||||||
|
/// </summary>
|
||||||
|
public static class WizardValidation
|
||||||
|
{
|
||||||
|
public static string? Validate(int step, CharacterDraft draft) => step switch
|
||||||
|
{
|
||||||
|
0 => ValidateClade(draft),
|
||||||
|
1 => ValidateSpecies(draft),
|
||||||
|
2 => string.IsNullOrEmpty(draft.ClassId) ? "Pick a calling." : null,
|
||||||
|
3 => string.IsNullOrEmpty(draft.SubclassId) ? "Pick a subclass." : null,
|
||||||
|
4 => string.IsNullOrEmpty(draft.BackgroundId) ? "Pick a history." : null,
|
||||||
|
5 => draft.StatAssign.Count == 6
|
||||||
|
? null
|
||||||
|
: $"Assign all six abilities ({draft.StatAssign.Count}/6).",
|
||||||
|
6 => ValidateSkills(draft),
|
||||||
|
7 => string.IsNullOrWhiteSpace(draft.CharacterName) ? "Enter a name." : null,
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
private static string? ValidateClade(CharacterDraft draft)
|
||||||
|
{
|
||||||
|
if (draft.IsHybrid)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(draft.SireCladeId)) return "Pick a sire clade.";
|
||||||
|
if (string.IsNullOrEmpty(draft.DamCladeId)) return "Pick a dam clade.";
|
||||||
|
if (draft.SireCladeId == draft.DamCladeId)
|
||||||
|
return "Sire and dam must be different clades.";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return string.IsNullOrEmpty(draft.CladeId) ? "Pick a clade." : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? ValidateSpecies(CharacterDraft draft)
|
||||||
|
{
|
||||||
|
if (draft.IsHybrid)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(draft.SireSpeciesId)) return "Pick a sire species.";
|
||||||
|
if (string.IsNullOrEmpty(draft.DamSpeciesId)) return "Pick a dam species.";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return string.IsNullOrEmpty(draft.SpeciesId) ? "Pick a species." : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string? ValidateSkills(CharacterDraft draft)
|
||||||
|
{
|
||||||
|
var cls = CodexContent.Class(draft.ClassId);
|
||||||
|
int need = cls?.SkillsChoose ?? 0;
|
||||||
|
int got = draft.ChosenSkills.Count;
|
||||||
|
if (need == 0) return null; // class has no skill picks (shouldn't happen, defensive)
|
||||||
|
if (got == need) return null;
|
||||||
|
return $"Pick {need} skill{(need == 1 ? "" : "s")} ({got}/{need}).";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Index of the lowest step whose validator currently fails, or -1 when
|
||||||
|
/// every step is satisfied. The forward-lock rule is: a step <c>i</c>
|
||||||
|
/// after the current step is locked iff <c>FirstIncomplete < i</c>.
|
||||||
|
/// </summary>
|
||||||
|
public static int FirstIncomplete(CharacterDraft draft, int stepCount = 8)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < stepCount; i++)
|
||||||
|
if (Validate(i, draft) is not null) return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user