M6.6: StepReview signing + hybrid math revision
- New Step VIII (Review): name input and Confirm button that saves the finalized character to user://character.tres. - Hybrid lineage rules simplified per project decision: drop the "no-stack on overlap, take +1 free elsewhere" rule from theriapolis-rpg-clades.md. Hybrids now pick one ability mod from each parent clade and they sum if they overlap. Removes HybridFreeAbility, the free-bonus picker row, and the overlap special case from AbilityCalc + WizardValidation. - StepClade bonus rows now mutate in place (sync ButtonPressed) instead of tearing down on every Refresh — the old path freed the very button mid-Pressed-signal, leaving stale buttons next to the new ones. - StepSkills drops the redundant "Calling: X · History: Y" meta line; both are already shown in the Aside summary. - Aside hybrid section adds dual-species traits and the universal-hybrid detriment pills. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -26,10 +26,25 @@ public partial class StepClade : VBoxContainer, IStep
|
||||
private VBoxContainer _hybridSection = null!;
|
||||
private OptionButton _dominantToggle = null!;
|
||||
|
||||
// Lineage-bonus pickers (per theriapolis-rpg-clades.md hybrid rules,
|
||||
// simplified to allow stacking on the same ability).
|
||||
private VBoxContainer _bonusSection = null!;
|
||||
private HBoxContainer _sireBonusRow = null!;
|
||||
private HBoxContainer _damBonusRow = null!;
|
||||
|
||||
private readonly Dictionary<string, PanelContainer> _purebredCards = new();
|
||||
private readonly Dictionary<string, PanelContainer> _sireCards = new();
|
||||
private readonly Dictionary<string, PanelContainer> _damCards = new();
|
||||
|
||||
// Bonus rows are mutated in place too: when the clade hasn't changed
|
||||
// since the last build, we only flip ButtonPressed states. Rebuilding
|
||||
// would Free() the very button whose Pressed callback we're inside,
|
||||
// which Godot defers — leaving stale buttons next to the new ones.
|
||||
private readonly Dictionary<string, Button> _sireBonusButtons = new();
|
||||
private readonly Dictionary<string, Button> _damBonusButtons = new();
|
||||
private string _sireBonusBuiltFor = "";
|
||||
private string _damBonusBuiltFor = "";
|
||||
|
||||
public void Bind(CharacterDraft draft)
|
||||
{
|
||||
_draft = draft;
|
||||
@@ -86,6 +101,21 @@ public partial class StepClade : VBoxContainer, IStep
|
||||
_hybridSection.AddChild(damGrid);
|
||||
PopulateGrid(damGrid, _damCards, id => OnLineageCladePicked("dam", id));
|
||||
|
||||
// Lineage bonus pickers — hybrids pick ONE ability mod from each
|
||||
// parent clade. Stacking on the same ability is allowed; mods sum.
|
||||
_bonusSection = new VBoxContainer();
|
||||
_bonusSection.AddThemeConstantOverride("separation", 8);
|
||||
_hybridSection.AddChild(_bonusSection);
|
||||
_bonusSection.AddChild(new Label { Text = "LINEAGE BONUSES" });
|
||||
|
||||
_sireBonusRow = new HBoxContainer();
|
||||
_sireBonusRow.AddThemeConstantOverride("separation", 8);
|
||||
_bonusSection.AddChild(_sireBonusRow);
|
||||
|
||||
_damBonusRow = new HBoxContainer();
|
||||
_damBonusRow.AddThemeConstantOverride("separation", 8);
|
||||
_bonusSection.AddChild(_damBonusRow);
|
||||
|
||||
var dominantRow = new HBoxContainer();
|
||||
dominantRow.AddThemeConstantOverride("separation", 8);
|
||||
_hybridSection.AddChild(dominantRow);
|
||||
@@ -131,6 +161,8 @@ public partial class StepClade : VBoxContainer, IStep
|
||||
patch["sire_species_id"] = "";
|
||||
patch["dam_clade_id"] = "";
|
||||
patch["dam_species_id"] = "";
|
||||
patch["sire_chosen_ability"] = "";
|
||||
patch["dam_chosen_ability"] = "";
|
||||
}
|
||||
ClearBackgroundIfInvalidated(patch);
|
||||
_draft.Patch(patch);
|
||||
@@ -159,6 +191,63 @@ public partial class StepClade : VBoxContainer, IStep
|
||||
|
||||
int dominantIdx = _draft.DominantParent == "dam" ? 1 : 0;
|
||||
if (_dominantToggle.Selected != dominantIdx) _dominantToggle.Select(dominantIdx);
|
||||
|
||||
if (hybrid) RebuildBonusPickers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Syncs the lineage-bonus button rows with the current sire/dam
|
||||
/// clade picks. When the clade hasn't changed since the last build
|
||||
/// we only update each button's ButtonPressed state — see field
|
||||
/// comment above for why a full rebuild here is unsafe.
|
||||
/// </summary>
|
||||
private void RebuildBonusPickers()
|
||||
{
|
||||
SyncLineageBonusRow(_sireBonusRow, _sireBonusButtons, ref _sireBonusBuiltFor, "sire",
|
||||
_draft.SireCladeId, _draft.SireChosenAbility);
|
||||
SyncLineageBonusRow(_damBonusRow, _damBonusButtons, ref _damBonusBuiltFor, "dam",
|
||||
_draft.DamCladeId, _draft.DamChosenAbility);
|
||||
}
|
||||
|
||||
private void SyncLineageBonusRow(HBoxContainer row, Dictionary<string, Button> cache,
|
||||
ref string builtFor, string lineage,
|
||||
string cladeId, string chosen)
|
||||
{
|
||||
if (cladeId == builtFor)
|
||||
{
|
||||
foreach (var (ab, btn) in cache)
|
||||
{
|
||||
bool want = ab == chosen;
|
||||
if (btn.ButtonPressed != want) btn.SetPressedNoSignal(want);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var c in row.GetChildren()) c.Free();
|
||||
cache.Clear();
|
||||
builtFor = cladeId;
|
||||
|
||||
var clade = CodexContent.Clade(cladeId);
|
||||
if (clade is null)
|
||||
{
|
||||
row.AddChild(new Label { Text = "(pick a clade above)" });
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var (ab, value) in clade.AbilityMods)
|
||||
{
|
||||
string captured = ab;
|
||||
var btn = new Button
|
||||
{
|
||||
Text = $"{ab} {(value >= 0 ? "+" : "")}{value}",
|
||||
ToggleMode = true,
|
||||
ButtonPressed = ab == chosen,
|
||||
FocusMode = Control.FocusModeEnum.None,
|
||||
};
|
||||
btn.Pressed += () => OnLineageBonusPicked(lineage, captured);
|
||||
row.AddChild(btn);
|
||||
cache[ab] = btn;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateSelection(Dictionary<string, PanelContainer> cards, string selectedId)
|
||||
@@ -192,10 +281,23 @@ public partial class StepClade : VBoxContainer, IStep
|
||||
var sp = CodexContent.SpeciesById(currentSpecies);
|
||||
if (sp is null || !string.Equals(sp.CladeId, cladeId, System.StringComparison.OrdinalIgnoreCase))
|
||||
patch[lineage + "_species_id"] = "";
|
||||
|
||||
// Clade swap invalidates the previously-picked lineage bonus
|
||||
// (different clade has different mod options).
|
||||
patch[lineage + "_chosen_ability"] = "";
|
||||
|
||||
ClearBackgroundIfInvalidated(patch);
|
||||
_draft.Patch(patch);
|
||||
}
|
||||
|
||||
private void OnLineageBonusPicked(string lineage, string ability)
|
||||
{
|
||||
_draft.Patch(new Godot.Collections.Dictionary
|
||||
{
|
||||
{ lineage + "_chosen_ability", ability },
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clade changes can make a previously-valid background unavailable
|
||||
/// (e.g. picking Felidae while Pack-Raised is selected). Build the
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
using Godot;
|
||||
using Theriapolis.GodotHost.UI;
|
||||
|
||||
namespace Theriapolis.GodotHost.Scenes.Steps;
|
||||
|
||||
/// <summary>
|
||||
/// Step VIII — Sign. Direct port of <c>StepReview</c> in
|
||||
/// <c>src/steps.jsx</c>: name entry plus the Confirm button that
|
||||
/// composes the final character and emits the handoff signal per
|
||||
/// GODOT_PORTING_GUIDE.md §11.
|
||||
///
|
||||
/// The full per-step review already lives in the Aside summary, so
|
||||
/// this step focuses on what's new at this stage: the name input
|
||||
/// and the Confirm action. Bottom of the page mirrors the React
|
||||
/// prototype — single big primary button.
|
||||
/// </summary>
|
||||
public partial class StepReview : VBoxContainer, IStep
|
||||
{
|
||||
/// <summary>Fired when Confirm is pressed and every step validates.
|
||||
/// The parent Wizard catches this and persists the draft + advances
|
||||
/// the harness; the rest of the game-side handoff lands in a future
|
||||
/// milestone (intro scene, world load, etc.).</summary>
|
||||
[Signal] public delegate void CharacterConfirmedEventHandler(CharacterDraft draft);
|
||||
|
||||
private CharacterDraft _draft = null!;
|
||||
private LineEdit _nameField = null!;
|
||||
private Button _confirmBtn = null!;
|
||||
private Label _confirmStatus = null!;
|
||||
|
||||
public void Bind(CharacterDraft draft)
|
||||
{
|
||||
_draft = draft;
|
||||
_draft.Changed += () => Callable.From(Refresh).CallDeferred();
|
||||
Build();
|
||||
}
|
||||
|
||||
public string? Validate() => WizardValidation.Validate(7, _draft);
|
||||
|
||||
private void Build()
|
||||
{
|
||||
AddThemeConstantOverride("separation", 18);
|
||||
|
||||
var intro = new VBoxContainer();
|
||||
intro.AddThemeConstantOverride("separation", 6);
|
||||
AddChild(intro);
|
||||
intro.AddChild(new Label { Text = "FOLIO VIII · SIGN" });
|
||||
intro.AddChild(new Label { Text = "Sign the Codex" });
|
||||
intro.AddChild(new Label
|
||||
{
|
||||
Text = "Review the right-rail summary, then sign your name. "
|
||||
+ "The name you sign here is the one the world will speak.",
|
||||
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||
});
|
||||
|
||||
// Name field.
|
||||
var nameBlock = new VBoxContainer();
|
||||
nameBlock.AddThemeConstantOverride("separation", 6);
|
||||
AddChild(nameBlock);
|
||||
nameBlock.AddChild(new Label { Text = "NAME" });
|
||||
_nameField = new LineEdit
|
||||
{
|
||||
PlaceholderText = "Enter your character's name...",
|
||||
Text = _draft.CharacterName,
|
||||
CustomMinimumSize = new Vector2(360, 0),
|
||||
};
|
||||
_nameField.TextChanged += OnNameChanged;
|
||||
nameBlock.AddChild(_nameField);
|
||||
|
||||
// Confirm action — disabled until every step validates.
|
||||
var actionBlock = new VBoxContainer();
|
||||
actionBlock.AddThemeConstantOverride("separation", 8);
|
||||
AddChild(actionBlock);
|
||||
|
||||
_confirmStatus = new Label
|
||||
{
|
||||
Text = "",
|
||||
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||
};
|
||||
actionBlock.AddChild(_confirmStatus);
|
||||
|
||||
_confirmBtn = new Button
|
||||
{
|
||||
Text = "Confirm & Begin",
|
||||
CustomMinimumSize = new Vector2(220, 0),
|
||||
};
|
||||
_confirmBtn.Pressed += OnConfirmPressed;
|
||||
actionBlock.AddChild(_confirmBtn);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnNameChanged(string newText)
|
||||
{
|
||||
// Patch only when the field actually differs from the draft —
|
||||
// otherwise the Changed signal would refresh us in a loop.
|
||||
if (newText == _draft.CharacterName) return;
|
||||
_draft.Patch(new Godot.Collections.Dictionary { { "character_name", newText } });
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
if (_nameField is null) return;
|
||||
// Sync the field if external state changed without going through
|
||||
// the LineEdit (e.g. loading a saved draft someday).
|
||||
if (_nameField.Text != _draft.CharacterName)
|
||||
_nameField.Text = _draft.CharacterName;
|
||||
|
||||
int firstUnmet = WizardValidation.FirstIncomplete(_draft);
|
||||
bool allValid = firstUnmet == -1;
|
||||
_confirmBtn.Disabled = !allValid;
|
||||
if (allValid)
|
||||
{
|
||||
_confirmStatus.Text = $"Ready: {_draft.CharacterName} stands at the threshold.";
|
||||
}
|
||||
else if (firstUnmet == 7)
|
||||
{
|
||||
_confirmStatus.Text = "Enter a name to sign.";
|
||||
}
|
||||
else
|
||||
{
|
||||
_confirmStatus.Text = $"Some folios remain — see Folio {Roman(firstUnmet + 1)}.";
|
||||
}
|
||||
}
|
||||
|
||||
private void OnConfirmPressed()
|
||||
{
|
||||
if (WizardValidation.FirstIncomplete(_draft) != -1) return;
|
||||
|
||||
// Persist the draft so a future load path can pick it up.
|
||||
const string SavePath = "user://character.tres";
|
||||
var err = ResourceSaver.Save(_draft, SavePath);
|
||||
if (err != Error.Ok)
|
||||
GD.PushWarning($"[review] ResourceSaver.Save failed: {err}");
|
||||
else
|
||||
GD.Print($"[review] Saved character draft to {SavePath}");
|
||||
|
||||
GD.Print($"[review] Confirmed: {Summarise(_draft)}");
|
||||
|
||||
EmitSignal(SignalName.CharacterConfirmed, _draft);
|
||||
|
||||
_confirmBtn.Disabled = true;
|
||||
_confirmStatus.Text = $"{_draft.CharacterName} steps into Theriapolis.";
|
||||
}
|
||||
|
||||
private static string Summarise(CharacterDraft d)
|
||||
{
|
||||
string lineage = d.IsHybrid
|
||||
? $"hybrid {d.SireCladeId}/{d.SireSpeciesId} × {d.DamCladeId}/{d.DamSpeciesId} (dom={d.DominantParent})"
|
||||
: $"{d.CladeId}/{d.SpeciesId}";
|
||||
return $"{d.CharacterName} — {lineage}, {d.ClassId}/{d.SubclassId}, bg={d.BackgroundId}, "
|
||||
+ $"skills=[{string.Join(",", d.ChosenSkills)}]";
|
||||
}
|
||||
|
||||
private static string Roman(int n) => n switch
|
||||
{
|
||||
1 => "I", 2 => "II", 3 => "III", 4 => "IV",
|
||||
5 => "V", 6 => "VI", 7 => "VII", 8 => "VIII",
|
||||
_ => n.ToString(),
|
||||
};
|
||||
}
|
||||
@@ -23,7 +23,6 @@ public partial class StepSkills : VBoxContainer, IStep
|
||||
{
|
||||
private CharacterDraft _draft = null!;
|
||||
private Label _countLabel = null!;
|
||||
private Label _classBgLabel = null!;
|
||||
private GridContainer _groupsGrid = null!;
|
||||
|
||||
public void Bind(CharacterDraft draft)
|
||||
@@ -52,15 +51,8 @@ public partial class StepSkills : VBoxContainer, IStep
|
||||
AutowrapMode = TextServer.AutowrapMode.WordSmart,
|
||||
});
|
||||
|
||||
var meta = new HBoxContainer();
|
||||
meta.AddThemeConstantOverride("separation", 24);
|
||||
AddChild(meta);
|
||||
_countLabel = new Label { Text = "0 / 0 chosen" };
|
||||
meta.AddChild(_countLabel);
|
||||
var spacer = new Control { SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
meta.AddChild(spacer);
|
||||
_classBgLabel = new Label { Text = "" };
|
||||
meta.AddChild(_classBgLabel);
|
||||
AddChild(_countLabel);
|
||||
|
||||
_groupsGrid = new GridContainer
|
||||
{
|
||||
@@ -86,9 +78,9 @@ public partial class StepSkills : VBoxContainer, IStep
|
||||
var classOptions = new HashSet<string>(cls?.SkillOptions ?? System.Array.Empty<string>());
|
||||
var chosen = new HashSet<string>(_draft.ChosenSkills);
|
||||
|
||||
_countLabel.Text = $"{chosen.Count} / {required} chosen +{lockedFromBg.Count} sealed by background";
|
||||
_classBgLabel.Text = (cls is null ? "Pick a calling first." :
|
||||
$"Calling: {cls.Name} · History: {bg?.Name ?? "—"}").ToUpperInvariant();
|
||||
_countLabel.Text = cls is null
|
||||
? "Pick a calling first."
|
||||
: $"{chosen.Count} / {required} chosen +{lockedFromBg.Count} sealed by background";
|
||||
|
||||
foreach (var c in _groupsGrid.GetChildren()) c.QueueFree();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user