4d3db17a89
Per GODOT_PORTING_GUIDE.md §7, the highest-risk piece in the wizard.
Three reusable widgets + the orchestrating step.
Scenes/Widgets/AbilityToken.cs:
Draggable Control with Value + Origin metadata. _GetDragData returns
a Dictionary payload {kind, value, from, ability, idx} per guide
§7.1. MouseFilter = Pass so clicks propagate to the parent slot
for the click-to-return affordance (later removed; see commit body).
Drag preview is a dimmed duplicate.
Scenes/Widgets/AbilitySlot.cs:
PanelContainer drop target per guide §7.2. Accepts any
ability_value payload via _CanDropData / _DropData and emits
Dropped(payload). Each slot owns one ability id (STR/DEX/CON/INT/
WIS/CHA).
Scenes/Widgets/AbilityPool.cs:
HBoxContainer drop target per guide §7.3. Accepts only slot→pool
drops (returning an assigned value to the pool); pool→pool drops
are no-ops.
Scenes/Steps/StepStats.cs:
Direct port of StepStats in steps.jsx per guide §7.4. Standard
array (default) and roll-4d6-drop-lowest method tabs; Reroll
button visible in roll mode; Auto Assign sorts the remaining pool
descending and places the largest values into empty slots ordered
by class.PrimaryAbility. Three drag-drop cases (pool→slot,
slot→slot swap, slot→pool) all delegate to a single Patch call,
then the entire token tree rebuilds from the new draft state on
the Changed signal — handlers don't reparent anything manually.
Issues hit during development and resolved before commit:
- Initial click-to-return on slot pre-empted drag-from-slot every
time (the GuiInput fired on mouse-down, before Godot detected
the drag). Removed click-to-return — drag is the canonical
interaction; that matches the React prototype anyway.
- Token MouseFilter = Stop blocked clicks from reaching the slot
layer; switched to Pass which still works as a drag source.
- Refresh() teardown + rebuild reset the parent ScrollContainer's
scroll to 0 every drop. CallDeferred / SetDeferred / CreateTimer
all raced because layout settles over multiple frames; the fix
that worked was capturing scroll position pre-rebuild and
restoring in _Process the next frame.
Wizard.cs:
StepTypes[5] = typeof(StepStats); the Abilities step is now
reachable. (StepTypes[1..4, 6..7] still null — coming in M6.3+.)
Verified: all three drag scenarios + click handling + auto-assign
+ method switch + reroll work; scroll position holds across drops.
Closes M6.2. Next per guide §12: M6.3 — popover system (TraitChip +
shared PopoverLayer) before adding more easy card-grid steps.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using Godot;
|
|
|
|
namespace Theriapolis.GodotHost.Scenes.Widgets;
|
|
|
|
/// <summary>
|
|
/// Drop target for ability assignment. Per GODOT_PORTING_GUIDE.md §7.2:
|
|
/// accepts any drag payload tagged "ability_value" and emits
|
|
/// <see cref="Dropped"/> with the payload so the step orchestrates the
|
|
/// state change centrally. Visual content (the AbilityToken when filled,
|
|
/// or a placeholder dash when empty) is set by the step on every refresh.
|
|
///
|
|
/// Each slot owns exactly one ability id (STR/DEX/CON/INT/WIS/CHA). On
|
|
/// click of a filled slot, returns the value to the pool (synthesised
|
|
/// slot→pool payload) — matches the React prototype's "click to unbind"
|
|
/// affordance from <c>steps.jsx</c>.
|
|
/// </summary>
|
|
public partial class AbilitySlot : PanelContainer
|
|
{
|
|
[Signal] public delegate void DroppedEventHandler(Godot.Collections.Dictionary payload);
|
|
|
|
[Export] public string Ability { get; set; } = "STR";
|
|
|
|
public override void _Ready()
|
|
{
|
|
CustomMinimumSize = new Vector2(56, 56);
|
|
MouseFilter = MouseFilterEnum.Stop;
|
|
}
|
|
|
|
public override bool _CanDropData(Vector2 atPosition, Variant data)
|
|
{
|
|
if (data.VariantType != Variant.Type.Dictionary) return false;
|
|
var d = data.AsGodotDictionary();
|
|
return d.ContainsKey("kind") && d["kind"].AsString() == "ability_value";
|
|
}
|
|
|
|
public override void _DropData(Vector2 atPosition, Variant data)
|
|
{
|
|
EmitSignal(SignalName.Dropped, data);
|
|
}
|
|
}
|