feat(phase8): complete remaining 3 gaps -- pending types, StackDeck interactive, canvas builder
Pending interaction coverage:
- Add PendingTilePick model (tile-select pause for effects like CloneSpiritAsToken TargetTile)
- Add PendingPlayerPick model (player-select pause for ChannelCardFromZone UnderControlOf: Choice)
- Add PendingRevealChoicePick model (reveal-and-order pause for StackDeck interactive path)
- Add all three as nullable properties on GameState
StackDeckEffect interactive flow:
- Replace random-shuffle fallback with chooser-aware branching
- Self/Opponent chooser: remove top N from deck, emit PendingRevealChoicePick pause
- Random/empty chooser: random shuffle fallback (unchanged)
- Add ResumeRevealChoicePick(): restore deck in chooser's ordered indices; unspecified
cards placed beneath chosen cards preserving relative order
Canvas AbilityBuilder (Phase 4 spec):
- Add @inject IJSRuntime + @implements IAsyncDisposable to AbilityBuilder.razor
- Add sorAdmin.abilityBuilder JS shim in admin.js: non-passive wheel listener (zoom),
pinch-to-zoom via touch distance delta, cleanup on dispose
- Canvas mode toggle button in form toolbar ("Visual Canvas")
- Full canvas layout: left panel (ability list + node palette), main canvas, right inspector
- Dark canvas background (#111827), CSS transform pan+zoom (translate then scale)
- SVG bezier edge overlay connecting node flow (Meta→Range/Trigger→Cost→Cond→ActionGroup
→Actions→Effects, ActionGroup→SubGroups→their Actions→their Effects)
- Node types: Meta (blue), Range (teal), Trigger (purple), Cost (amber), Conditions (yellow),
ActionGroup (dark green), Action (green), Effect (red), SubGroup (dark green), SubGroupAction,
SubGroupEffect -- each draggable, click-to-select
- Inspector panel: inline editing for all node types (type/name/desc, range fields, trigger
event, group logic op, action target selector, effect type picker)
- AutoLayoutAbility() positions nodes on first focus; SetPos() preserves drag positions
- Zoom/pan: toolbar +/- buttons + scroll wheel (via JS) + middle-mouse drag
- OnCanvasWheel [JSInvokable] + DisposeAsync cleanup
- Form view toggle restores full form; JSON preview always visible
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
@* AbilityBuilder.razor — structured UI for AbilityDefinition[] / Action[] JSON *@
|
||||
@using Microsoft.AspNetCore.Components.Rendering
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using Microsoft.JSInterop
|
||||
@using SOR.Database.Contexts
|
||||
@using SOR.Database.Entities.Catalog
|
||||
@using SOR.Database.Enums
|
||||
@inject CatalogDbContext CatalogDb
|
||||
@inject IJSRuntime JS
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<div class="ability-builder">
|
||||
@if (!_canvasMode)
|
||||
{
|
||||
@if (_abilities.Count == 0)
|
||||
{
|
||||
<p class="text-muted fst-italic">No abilities defined. Click "Add Ability" to start.</p>
|
||||
@@ -865,14 +870,487 @@
|
||||
}
|
||||
}
|
||||
|
||||
<div class="d-flex gap-2 align-items-center mb-4">
|
||||
<button class="btn btn-outline-primary btn-sm" @onclick="AddAbility">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Ability
|
||||
</button>
|
||||
<button class="btn btn-outline-secondary btn-sm" @onclick="() => _showHelp = !_showHelp">
|
||||
<i class="bi bi-question-circle me-1"></i>Help
|
||||
</button>
|
||||
</div>
|
||||
<div class="d-flex gap-2 align-items-center mb-4">
|
||||
<button class="btn btn-outline-primary btn-sm" @onclick="AddAbility">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Ability
|
||||
</button>
|
||||
<button class="btn btn-outline-secondary btn-sm" @onclick="() => _showHelp = !_showHelp">
|
||||
<i class="bi bi-question-circle me-1"></i>Help
|
||||
</button>
|
||||
<button class="btn btn-outline-info btn-sm ms-auto" @onclick="EnterCanvasMode">
|
||||
<i class="bi bi-diagram-3 me-1"></i>Visual Canvas
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@* ── Canvas mode ──────────────────────────────────────────────────────────── *@
|
||||
@if (_canvasMode)
|
||||
{
|
||||
<style>
|
||||
.ab-blue-hd { background: #0d6efd; }
|
||||
.ab-teal-hd { background: #0d9488; }
|
||||
.ab-amber-hd { background: #b45309; }
|
||||
.ab-purple-hd { background: #7c3aed; }
|
||||
.ab-yellow-hd { background: #a16207; }
|
||||
.ab-gd-hd { background: #166534; }
|
||||
.ab-green-hd { background: #15803d; }
|
||||
.ab-red-hd { background: #b91c1c; }
|
||||
.ab-node { border-radius: 6px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.5); background: var(--bs-body-bg); border: 1px solid rgba(255,255,255,0.12); }
|
||||
.ab-node.selected { outline: 2px solid #4a9eff; outline-offset: 1px; }
|
||||
.ab-node-hd { padding: 4px 8px; display: flex; align-items: center; gap: 4px; font-size: 0.75rem; font-weight: 600; color: #fff; cursor: grab; user-select: none; white-space: nowrap; }
|
||||
.ab-node-body { padding: 4px 8px; font-size: 0.72rem; }
|
||||
</style>
|
||||
|
||||
<div class="d-flex gap-2 mb-2 align-items-center">
|
||||
<button class="btn btn-sm btn-outline-secondary" @onclick="() => _canvasMode = false">
|
||||
<i class="bi bi-list-ul me-1"></i>Form View
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-secondary" @onclick="() => _showHelp = !_showHelp">
|
||||
<i class="bi bi-question-circle me-1"></i>Help
|
||||
</button>
|
||||
<span class="text-muted small ms-auto">Canvas · @_abilities.Count abilit@(_abilities.Count == 1 ? "y" : "ies") · scroll=zoom · middle-drag=pan</span>
|
||||
</div>
|
||||
|
||||
<div class="d-flex border rounded mb-3" style="height: 72vh; overflow: hidden;">
|
||||
|
||||
@* ── Left panel: ability list + node palette ── *@
|
||||
<div class="flex-shrink-0 p-2 border-end" style="width:185px; overflow-y:auto; background:var(--bs-body-bg);">
|
||||
<div class="small fw-semibold text-muted mb-2 text-uppercase">Abilities</div>
|
||||
@for (int cai = 0; cai < _abilities.Count; cai++)
|
||||
{
|
||||
int aidx = cai;
|
||||
var aitem = _abilities[aidx];
|
||||
<div class="d-flex align-items-stretch gap-1 mb-1">
|
||||
<button class="btn btn-sm flex-grow-1 text-start text-truncate py-0 @(_focusedAbility == aidx ? "btn-primary" : "btn-outline-secondary")"
|
||||
style="font-size:0.75rem" title="@aitem.Name"
|
||||
@onclick="() => FocusAbility(aidx)">
|
||||
<span class="badge @AbilityTypeBadge(aitem.TypeStr) me-1" style="font-size:0.55rem">@(aitem.TypeStr.Length > 0 ? aitem.TypeStr[0].ToString() : "?")</span>
|
||||
@(string.IsNullOrEmpty(aitem.Name) ? "(unnamed)" : aitem.Name)
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger py-0 px-1"
|
||||
@onclick="() => { _abilities.RemoveAt(aidx); _focusedAbility = Math.Max(0, Math.Min(_focusedAbility, _abilities.Count - 1)); Compile(); }">
|
||||
<i class="bi bi-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
<button class="btn btn-sm btn-outline-primary w-100 mt-1 py-0"
|
||||
@onclick="() => { AddAbility(); FocusAbility(_abilities.Count - 1); }">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Ability
|
||||
</button>
|
||||
|
||||
@if (_focusedAbility >= 0 && _focusedAbility < _abilities.Count)
|
||||
{
|
||||
var fabpal = _abilities[_focusedAbility];
|
||||
<hr class="my-2" />
|
||||
<div class="small fw-semibold text-muted mb-1 text-uppercase">Add Node</div>
|
||||
<button class="btn btn-sm btn-outline-success w-100 mb-1 py-0"
|
||||
@onclick='() => { fabpal.Actions.Add(new ActionDraft()); var nk = $"action-{_focusedAbility}-{fabpal.Actions.Count-1}"; AutoPositionNew(nk, "action"); Compile(); }'>
|
||||
<i class="bi bi-plus me-1"></i>Action
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-danger w-100 mb-1 py-0"
|
||||
@onclick="AddEffectToSelected">
|
||||
<i class="bi bi-plus me-1"></i>Effect (to selected)
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-warning w-100 mb-1 py-0"
|
||||
@onclick="() => { fabpal.Costs.Add(new CostDraft()); AutoLayoutAbility(_focusedAbility); Compile(); }">
|
||||
<i class="bi bi-plus me-1"></i>Cost Entry
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline-secondary w-100 py-0"
|
||||
@onclick="() => { fabpal.SubGroups.Add(new ActionGroupDraft()); AutoLayoutAbility(_focusedAbility); Compile(); }">
|
||||
<i class="bi bi-plus me-1"></i>Sub-Group
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
|
||||
@* ── Canvas area ── *@
|
||||
<div id="@_canvasId" class="flex-grow-1 position-relative overflow-hidden"
|
||||
style="cursor:@(_draggingNode != null || _isPanning ? "grabbing" : "default"); background:#111827;"
|
||||
@onmousemove="OnCanvasMouseMove" @onmousemove:preventDefault="true"
|
||||
@onmouseup="OnCanvasMouseUp"
|
||||
@onmousedown="OnCanvasMouseDown">
|
||||
|
||||
@* Canvas toolbar *@
|
||||
<div class="position-absolute d-flex gap-1 align-items-center"
|
||||
style="top:8px;left:8px;z-index:10;background:rgba(0,0,0,0.55);border-radius:6px;padding:3px 7px;">
|
||||
<button class="btn btn-sm border-0 py-0 px-2 text-white" style="background:transparent"
|
||||
@onclick="() => { _zoom = Math.Min(3.0, _zoom * 1.2); }"
|
||||
@onclick:stopPropagation="true" title="Zoom in"><i class="bi bi-zoom-in"></i></button>
|
||||
<button class="btn btn-sm border-0 py-0 px-2 text-white" style="background:transparent"
|
||||
@onclick="() => { _zoom = Math.Max(0.2, _zoom / 1.2); }"
|
||||
@onclick:stopPropagation="true" title="Zoom out"><i class="bi bi-zoom-out"></i></button>
|
||||
<button class="btn btn-sm border-0 py-0 px-2 text-white" style="background:transparent"
|
||||
@onclick="ResetCanvas"
|
||||
@onclick:stopPropagation="true" title="Reset view"><i class="bi bi-fullscreen"></i></button>
|
||||
<span class="text-white-50 small">@((_zoom * 100).ToString("F0"))%</span>
|
||||
</div>
|
||||
|
||||
@* Transform wrapper *@
|
||||
<div style="position:absolute;top:0;left:0;transform-origin:0 0;transform:translate(@Px(_panX),@Px(_panY)) scale(@Pf(_zoom));width:8000px;height:6000px;pointer-events:none;">
|
||||
|
||||
@* SVG edge layer *@
|
||||
<svg style="position:absolute;top:0;left:0;width:8000px;height:6000px;overflow:visible;pointer-events:none;">
|
||||
@foreach (var (efrom, eto) in GetEdges())
|
||||
{
|
||||
@if (_nodePos.TryGetValue(efrom, out var efp) && _nodePos.TryGetValue(eto, out var etp))
|
||||
{
|
||||
var (efx, efy) = GetOutputPort(efrom);
|
||||
var (etx, ety) = GetInputPort(eto);
|
||||
<path d="@BezierPath(efx, efy, etx, ety)"
|
||||
fill="none" stroke="#4a9eff" stroke-width="1.5"
|
||||
stroke-dasharray="5 3" opacity="0.5" />
|
||||
}
|
||||
}
|
||||
</svg>
|
||||
|
||||
@* Nodes layer (re-enable pointer-events) *@
|
||||
<div style="position:absolute;top:0;left:0;pointer-events:all;">
|
||||
@if (_focusedAbility >= 0 && _focusedAbility < _abilities.Count)
|
||||
{
|
||||
var fabi = _abilities[_focusedAbility];
|
||||
int fai = _focusedAbility;
|
||||
|
||||
@* Meta *@
|
||||
var mk = $"meta-{fai}";
|
||||
var mp = _nodePos.GetValueOrDefault(mk, (80.0, 80.0));
|
||||
<div class="ab-node @(_selectedNode==mk?"selected":"")" style="@NS(mp,META_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,mk)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-blue-hd">
|
||||
<span class="badge @AbilityTypeBadge(fabi.TypeStr)" style="font-size:0.6rem">@fabi.TypeStr</span>
|
||||
<span class="text-truncate flex-grow-1">@(string.IsNullOrEmpty(fabi.Name)?"(unnamed)":fabi.Name)</span>
|
||||
</div>
|
||||
<div class="ab-node-body text-muted text-truncate" style="max-width:@(META_W-4)px">@fabi.Description</div>
|
||||
</div>
|
||||
|
||||
@* Range (Active) *@
|
||||
@if (fabi.TypeStr == "Active")
|
||||
{
|
||||
var rk = $"range-{fai}"; var rp = _nodePos.GetValueOrDefault(rk,(320,80));
|
||||
<div class="ab-node @(_selectedNode==rk?"selected":"")" style="@NS(rp,RANGE_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,rk)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-teal-hd"><i class="bi bi-crosshair me-1"></i>Range</div>
|
||||
<div class="ab-node-body">
|
||||
<span class="text-muted">R </span>@(fabi.RangeMin??1)–@(fabi.RangeMax??1)
|
||||
@if (fabi.RangeRequiresLos){<span class="badge bg-secondary ms-1" style="font-size:0.55rem">LOS</span>}
|
||||
@if (fabi.RangeLinearOnly){<span class="badge bg-secondary ms-1" style="font-size:0.55rem">Lin</span>}
|
||||
@if (fabi.UsesPerTurn!=1){<div class="text-muted">×@fabi.UsesPerTurn/turn</div>}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@* Trigger (Triggered) *@
|
||||
@if (fabi.TypeStr == "Triggered")
|
||||
{
|
||||
var tk = $"trigger-{fai}"; var tp = _nodePos.GetValueOrDefault(tk,(320,80));
|
||||
<div class="ab-node @(_selectedNode==tk?"selected":"")" style="@NS(tp,TRIGGER_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,tk)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-purple-hd"><i class="bi bi-lightning me-1"></i>Trigger</div>
|
||||
<div class="ab-node-body text-truncate">@(string.IsNullOrEmpty(fabi.TriggerType)?"(none)":fabi.TriggerType)</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@* Cost *@
|
||||
@if (fabi.Costs.Count > 0)
|
||||
{
|
||||
var ck = $"cost-{fai}"; var cp = _nodePos.GetValueOrDefault(ck,(560,80));
|
||||
<div class="ab-node @(_selectedNode==ck?"selected":"")" style="@NS(cp,COST_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,ck)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-amber-hd">
|
||||
<i class="bi bi-coin me-1"></i>Cost
|
||||
<span class="badge bg-dark ms-auto">@fabi.Costs.Count</span>
|
||||
</div>
|
||||
@foreach (var ce in fabi.Costs.Take(3))
|
||||
{
|
||||
<div class="ab-node-body border-top border-secondary text-truncate">@ce.TypeStr @(ce.Amount>0?ce.Amount:"")</div>
|
||||
}
|
||||
@if (fabi.Costs.Count > 3){<div class="ab-node-body text-muted">+@(fabi.Costs.Count-3) more…</div>}
|
||||
</div>
|
||||
}
|
||||
|
||||
@* Conditions *@
|
||||
@if (fabi.Conditions.Count > 0)
|
||||
{
|
||||
var condK = $"cond-{fai}"; var condP = _nodePos.GetValueOrDefault(condK,(760,80));
|
||||
<div class="ab-node @(_selectedNode==condK?"selected":"")" style="@NS(condP,COND_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,condK)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-yellow-hd">
|
||||
<i class="bi bi-funnel me-1"></i>Conditions
|
||||
<span class="badge bg-dark ms-auto">@fabi.Conditions.Count</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@* ActionGroup *@
|
||||
var agk = $"group-{fai}";
|
||||
var agp = _nodePos.GetValueOrDefault(agk, (960.0, 80.0));
|
||||
<div class="ab-node @(_selectedNode==agk?"selected":"")" style="@NS(agp,GROUP_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,agk)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-gd-hd">
|
||||
<i class="bi bi-diagram-3 me-1"></i>Actions
|
||||
<span class="badge bg-dark ms-1">@fabi.ActionGroupLogicOp</span>
|
||||
</div>
|
||||
<div class="ab-node-body text-muted">
|
||||
@fabi.Actions.Count act@(fabi.Actions.Count==1?"":"s")
|
||||
@if(fabi.SubGroups.Count>0){<text>, @fabi.SubGroups.Count grp@(fabi.SubGroups.Count==1?"":"s")</text>}
|
||||
@if(fabi.ActionGroupLogicOp!="And"){<div>Chooser: @fabi.ActionGroupChooserRole</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Action nodes *@
|
||||
@for (int cj = 0; cj < fabi.Actions.Count; cj++)
|
||||
{
|
||||
int jidx = cj;
|
||||
var act = fabi.Actions[jidx];
|
||||
var actK = $"action-{fai}-{jidx}";
|
||||
var actP = _nodePos.GetValueOrDefault(actK,(960+jidx*250,260));
|
||||
<div class="ab-node @(_selectedNode==actK?"selected":"")" style="@NS(actP,ACTION_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,actK)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-green-hd">
|
||||
<i class="bi bi-cursor me-1"></i>Action @(jidx+1)
|
||||
<button class="btn border-0 p-0 ms-auto text-danger opacity-75"
|
||||
style="font-size:0.7rem;line-height:1;background:transparent"
|
||||
@onclick='()=>{fabi.Actions.RemoveAt(jidx);Compile();}'
|
||||
@onclick:stopPropagation="true">
|
||||
<i class="bi bi-x-lg"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ab-node-body">
|
||||
<span class="text-muted">→ </span>@act.Ownership @act.TargetType
|
||||
@if(act.All){<span class="badge bg-secondary ms-1" style="font-size:0.55rem">All</span>}
|
||||
else{<span class="text-muted"> ×@act.Count</span>}
|
||||
<div class="text-muted">@act.Scope</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* Effect nodes for this action *@
|
||||
@for (int ck = 0; ck < act.Effects.Count; ck++)
|
||||
{
|
||||
int kidx = ck;
|
||||
var eff = act.Effects[kidx];
|
||||
var effK = $"effect-{fai}-{jidx}-{kidx}";
|
||||
var effP = _nodePos.GetValueOrDefault(effK,(960+jidx*250,260+(kidx+1)*160));
|
||||
<div class="ab-node @(_selectedNode==effK?"selected":"")" style="@NS(effP,EFFECT_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,effK)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-red-hd">
|
||||
<i class="bi bi-lightning-charge me-1"></i>
|
||||
<span class="text-truncate flex-grow-1">@eff.TypeKey</span>
|
||||
<button class="btn border-0 p-0 ms-auto text-danger opacity-75"
|
||||
style="font-size:0.7rem;line-height:1;background:transparent"
|
||||
@onclick='()=>{act.Effects.RemoveAt(kidx);Compile();}'
|
||||
@onclick:stopPropagation="true">
|
||||
<i class="bi bi-x-lg"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ab-node-body text-muted text-truncate">@EffectSummary(eff)</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@* Sub-group nodes *@
|
||||
@for (int csgi = 0; csgi < fabi.SubGroups.Count; csgi++)
|
||||
{
|
||||
int sgiIdx = csgi;
|
||||
var sg = fabi.SubGroups[sgiIdx];
|
||||
var sgK = $"subgroup-{fai}-{sgiIdx}";
|
||||
var sgP = _nodePos.GetValueOrDefault(sgK,(960+(fabi.Actions.Count+sgiIdx)*250,260));
|
||||
<div class="ab-node @(_selectedNode==sgK?"selected":"")" style="@NS(sgP,GROUP_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,sgK)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-gd-hd" style="opacity:0.8">
|
||||
<i class="bi bi-folder me-1"></i>Sub-Group @(sgiIdx+1)
|
||||
<span class="badge bg-dark ms-1">@sg.LogicOp</span>
|
||||
<button class="btn border-0 p-0 ms-auto text-danger opacity-75"
|
||||
style="font-size:0.7rem;line-height:1;background:transparent"
|
||||
@onclick='()=>{fabi.SubGroups.RemoveAt(sgiIdx);Compile();}'
|
||||
@onclick:stopPropagation="true">
|
||||
<i class="bi bi-x-lg"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="ab-node-body text-muted">@sg.Actions.Count act@(sg.Actions.Count==1?"":"s")</div>
|
||||
</div>
|
||||
|
||||
@for (int sgj = 0; sgj < sg.Actions.Count; sgj++)
|
||||
{
|
||||
int sgjIdx = sgj;
|
||||
var sgAct = sg.Actions[sgjIdx];
|
||||
var sgActK = $"subgroupaction-{fai}-{sgiIdx}-{sgjIdx}";
|
||||
var sgActP = _nodePos.GetValueOrDefault(sgActK,(960+(fabi.Actions.Count+sgiIdx)*250,260+(sgjIdx+1)*160));
|
||||
<div class="ab-node @(_selectedNode==sgActK?"selected":"")" style="@NS(sgActP,ACTION_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,sgActK)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-green-hd" style="opacity:0.8">
|
||||
<i class="bi bi-cursor me-1"></i>SG@(sgiIdx+1) · Act @(sgjIdx+1)
|
||||
</div>
|
||||
<div class="ab-node-body">
|
||||
<span class="text-muted">→ </span>@sgAct.Ownership @sgAct.TargetType
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@for (int sgk = 0; sgk < sgAct.Effects.Count; sgk++)
|
||||
{
|
||||
int sgkIdx = sgk;
|
||||
var sgEff = sgAct.Effects[sgkIdx];
|
||||
var sgEffK = $"subgroupeffect-{fai}-{sgiIdx}-{sgjIdx}-{sgkIdx}";
|
||||
var sgEffP = _nodePos.GetValueOrDefault(sgEffK,(960+(fabi.Actions.Count+sgiIdx)*250,260+(sgjIdx+1)*160+(sgkIdx+1)*160));
|
||||
<div class="ab-node @(_selectedNode==sgEffK?"selected":"")" style="@NS(sgEffP,EFFECT_W)"
|
||||
@onmousedown="e=>OnNodeMouseDown(e,sgEffK)" @onmousedown:stopPropagation="true">
|
||||
<div class="ab-node-hd ab-red-hd" style="opacity:0.8">
|
||||
<i class="bi bi-lightning-charge me-1"></i>
|
||||
<span class="text-truncate flex-grow-1">@sgEff.TypeKey</span>
|
||||
</div>
|
||||
<div class="ab-node-body text-muted">@EffectSummary(sgEff)</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@* ── Right panel: inspector ── *@
|
||||
<div class="flex-shrink-0 p-2 border-start" style="width:270px;overflow-y:auto;background:var(--bs-body-bg);">
|
||||
<div class="small fw-semibold text-muted mb-2 text-uppercase">Inspector</div>
|
||||
@if (_selectedNode == null || _focusedAbility < 0 || _focusedAbility >= _abilities.Count)
|
||||
{
|
||||
<p class="text-muted small fst-italic">Click a node to inspect.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
ParseNodeKey(_selectedNode, out var inKind, out var inAi, out var inJ, out var inK, out var inL);
|
||||
@if (inAi >= 0 && inAi < _abilities.Count)
|
||||
{
|
||||
var inAb = _abilities[inAi];
|
||||
@if (inKind == "meta")
|
||||
{
|
||||
<label class="form-label small mb-0">Type</label>
|
||||
<select class="form-select form-select-sm mb-2" @bind="inAb.TypeStr" @bind:after="Compile">
|
||||
@foreach (var t in AbilityTypes) { <option value="@t">@t</option> }
|
||||
</select>
|
||||
<label class="form-label small mb-0">Name</label>
|
||||
<input class="form-control form-control-sm mb-2" @bind="inAb.Name" @bind:after="Compile" />
|
||||
<label class="form-label small mb-0">Description</label>
|
||||
<textarea class="form-control form-control-sm mb-2" rows="3" @bind="inAb.Description" @bind:after="Compile"></textarea>
|
||||
}
|
||||
else if (inKind == "range")
|
||||
{
|
||||
<label class="form-label small mb-0">Min Range</label>
|
||||
<input type="number" class="form-control form-control-sm mb-2" @bind="inAb.RangeMin" @bind:after="Compile" />
|
||||
<label class="form-label small mb-0">Max Range</label>
|
||||
<input type="number" class="form-control form-control-sm mb-2" @bind="inAb.RangeMax" @bind:after="Compile" />
|
||||
<div class="form-check mb-1">
|
||||
<input class="form-check-input" type="checkbox" id="inLos" @bind="inAb.RangeRequiresLos" @bind:after="Compile" />
|
||||
<label class="form-check-label small" for="inLos">Requires LOS</label>
|
||||
</div>
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="inLin" @bind="inAb.RangeLinearOnly" @bind:after="Compile" />
|
||||
<label class="form-check-label small" for="inLin">Linear Only</label>
|
||||
</div>
|
||||
<label class="form-label small mb-0">Uses/Turn</label>
|
||||
<input type="number" class="form-control form-control-sm" @bind="inAb.UsesPerTurn" @bind:after="Compile" min="1" />
|
||||
}
|
||||
else if (inKind == "trigger")
|
||||
{
|
||||
<label class="form-label small mb-0">Trigger Event</label>
|
||||
<select class="form-select form-select-sm mb-2" @bind="inAb.TriggerType" @bind:after="Compile">
|
||||
<option value="">(none)</option>
|
||||
@foreach (var tt in TriggerTypesList) { <option value="@tt">@tt</option> }
|
||||
</select>
|
||||
<label class="form-label small mb-0">Limit/Turn</label>
|
||||
<input type="number" class="form-control form-control-sm" @bind="inAb.TriggerLimitPerTurn" @bind:after="Compile" />
|
||||
}
|
||||
else if (inKind == "group")
|
||||
{
|
||||
<label class="form-label small mb-0">Logic Op</label>
|
||||
<select class="form-select form-select-sm mb-2" @bind="inAb.ActionGroupLogicOp" @bind:after="Compile">
|
||||
@foreach (var op in LogicOpValues) { <option value="@op">@op</option> }
|
||||
</select>
|
||||
@if (inAb.ActionGroupLogicOp != "And")
|
||||
{
|
||||
<label class="form-label small mb-0">Chooser Role</label>
|
||||
<select class="form-select form-select-sm" @bind="inAb.ActionGroupChooserRole" @bind:after="Compile">
|
||||
@foreach (var r in ChooserRoleValues) { <option value="@r">@r</option> }
|
||||
</select>
|
||||
}
|
||||
}
|
||||
else if (inKind == "subgroup" && inJ >= 0 && inJ < inAb.SubGroups.Count)
|
||||
{
|
||||
var inSg = inAb.SubGroups[inJ];
|
||||
<label class="form-label small mb-0">Logic Op</label>
|
||||
<select class="form-select form-select-sm mb-2" @bind="inSg.LogicOp" @bind:after="Compile">
|
||||
@foreach (var op in LogicOpValues) { <option value="@op">@op</option> }
|
||||
</select>
|
||||
@if (inSg.LogicOp != "And")
|
||||
{
|
||||
<label class="form-label small mb-0">Chooser Role</label>
|
||||
<select class="form-select form-select-sm" @bind="inSg.ChooserRole" @bind:after="Compile">
|
||||
@foreach (var r in ChooserRoleValues) { <option value="@r">@r</option> }
|
||||
</select>
|
||||
}
|
||||
}
|
||||
else if ((inKind == "action" || inKind == "sgaction") && inJ >= 0)
|
||||
{
|
||||
ActionDraft? inAct = null;
|
||||
if (inKind == "action" && inJ < inAb.Actions.Count)
|
||||
inAct = inAb.Actions[inJ];
|
||||
else if (inKind == "sgaction" && inJ < inAb.SubGroups.Count && inK >= 0 && inK < inAb.SubGroups[inJ].Actions.Count)
|
||||
inAct = inAb.SubGroups[inJ].Actions[inK];
|
||||
|
||||
@if (inAct != null)
|
||||
{
|
||||
<label class="form-label small mb-0">Scope</label>
|
||||
<select class="form-select form-select-sm mb-1" @bind="inAct.Scope" @bind:after="Compile">
|
||||
@foreach (var s in TargetScopes) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
<label class="form-label small mb-0">Target Type</label>
|
||||
<select class="form-select form-select-sm mb-1" @bind="inAct.TargetType" @bind:after="Compile">
|
||||
@foreach (var s in TargetTypes) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
<label class="form-label small mb-0">Ownership</label>
|
||||
<select class="form-select form-select-sm mb-1" @bind="inAct.Ownership" @bind:after="Compile">
|
||||
@foreach (var s in TargetOwnerships) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
<label class="form-label small mb-0">Chooser</label>
|
||||
<select class="form-select form-select-sm mb-1" @bind="inAct.Chooser" @bind:after="Compile">
|
||||
@foreach (var s in ChooserRoleValues) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
<div class="form-check mb-1">
|
||||
<input class="form-check-input" type="checkbox" id="inAll" @bind="inAct.All" @bind:after="Compile" />
|
||||
<label class="form-check-label small" for="inAll">All targets</label>
|
||||
</div>
|
||||
@if (!inAct.All)
|
||||
{
|
||||
<label class="form-label small mb-0">Count</label>
|
||||
<input type="number" class="form-control form-control-sm" @bind="inAct.Count" @bind:after="Compile" min="1" />
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((inKind == "effect" || inKind == "sgeffect") && inJ >= 0)
|
||||
{
|
||||
EffectDraft? inEff = null;
|
||||
if (inKind == "effect" && inJ < inAb.Actions.Count && inK >= 0 && inK < inAb.Actions[inJ].Effects.Count)
|
||||
inEff = inAb.Actions[inJ].Effects[inK];
|
||||
else if (inKind == "sgeffect" && inJ < inAb.SubGroups.Count && inK >= 0 && inK < inAb.SubGroups[inJ].Actions.Count && inL >= 0 && inL < inAb.SubGroups[inJ].Actions[inK].Effects.Count)
|
||||
inEff = inAb.SubGroups[inJ].Actions[inK].Effects[inL];
|
||||
|
||||
@if (inEff != null)
|
||||
{
|
||||
<label class="form-label small mb-0">Effect Type</label>
|
||||
<select class="form-select form-select-sm mb-2" @bind="inEff.TypeKey" @bind:after="() => { SelectEffectType(inEff, inEff.TypeKey); }">
|
||||
@foreach (var grp in EffectGroups)
|
||||
{
|
||||
<optgroup label="@grp.Label">
|
||||
@foreach (var et in grp.Types)
|
||||
{ <option value="@et">@et</option> }
|
||||
</optgroup>
|
||||
}
|
||||
</select>
|
||||
<p class="text-muted small fst-italic mb-0">Switch to Form View for full effect parameters.</p>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- JSON output / raw edit -->
|
||||
<div class="border rounded p-3">
|
||||
@@ -1093,6 +1571,39 @@
|
||||
private bool _showRaw;
|
||||
private bool _showHelp;
|
||||
|
||||
// ── Canvas mode state ─────────────────────────────────────────────────────
|
||||
|
||||
private bool _canvasMode = false;
|
||||
private bool _needsJsInit = false;
|
||||
private int _focusedAbility = 0;
|
||||
private double _zoom = 1.0, _panX = 60, _panY = 60;
|
||||
private bool _isPanning;
|
||||
private double _lastMouseX, _lastMouseY;
|
||||
|
||||
// Node positions: key → (X, Y) canvas coords
|
||||
private readonly Dictionary<string, (double X, double Y)> _nodePos = new();
|
||||
|
||||
// Drag state
|
||||
private string? _draggingNode;
|
||||
|
||||
// Inspector selection
|
||||
private string? _selectedNode;
|
||||
|
||||
// JS cleanup
|
||||
private DotNetObjectReference<AbilityBuilder>? _jsRef;
|
||||
private readonly string _canvasId = $"ab-canvas-{Guid.NewGuid():N}";
|
||||
|
||||
// Canvas node width constants (px in canvas-space)
|
||||
private const double META_W = 200;
|
||||
private const double RANGE_W = 200;
|
||||
private const double COST_W = 200;
|
||||
private const double TRIGGER_W = 200;
|
||||
private const double COND_W = 180;
|
||||
private const double GROUP_W = 220;
|
||||
private const double ACTION_W = 210;
|
||||
private const double EFFECT_W = 200;
|
||||
private const double NODE_H = 34.0; // node header height for port midpoint
|
||||
|
||||
// ── Spirit card list for "Existing Card" token mode ───────────────────────
|
||||
|
||||
private sealed record SpiritCardEntry(Guid Id, string Name, string Affinity,
|
||||
@@ -3192,6 +3703,315 @@
|
||||
Compile();
|
||||
}
|
||||
|
||||
// ── Canvas mode methods ───────────────────────────────────────────────────
|
||||
|
||||
private async Task EnterCanvasMode()
|
||||
{
|
||||
_canvasMode = true;
|
||||
_focusedAbility = Math.Max(0, Math.Min(_focusedAbility, _abilities.Count - 1));
|
||||
AutoLayoutAbility(_focusedAbility);
|
||||
_needsJsInit = true;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (_needsJsInit && _canvasMode)
|
||||
{
|
||||
_needsJsInit = false;
|
||||
_jsRef ??= DotNetObjectReference.Create(this);
|
||||
try { await JS.InvokeVoidAsync("sorAdmin.abilityBuilder.init", _canvasId, _jsRef); }
|
||||
catch { /* JS not loaded in pre-render */ }
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public void OnCanvasWheel(double factor)
|
||||
{
|
||||
_zoom = Math.Clamp(_zoom * factor, 0.2, 3.0);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_jsRef != null)
|
||||
{
|
||||
try { await JS.InvokeVoidAsync("sorAdmin.abilityBuilder.dispose", _canvasId); }
|
||||
catch { /* ignore during dispose */ }
|
||||
_jsRef.Dispose();
|
||||
_jsRef = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void FocusAbility(int ai)
|
||||
{
|
||||
_focusedAbility = ai;
|
||||
_selectedNode = null;
|
||||
AutoLayoutAbility(ai);
|
||||
}
|
||||
|
||||
private void AutoLayoutAbility(int ai)
|
||||
{
|
||||
if (ai < 0 || ai >= _abilities.Count) return;
|
||||
var ab = _abilities[ai];
|
||||
double x = 80, y = 80;
|
||||
|
||||
SetPos($"meta-{ai}", x, y); x += META_W + 60;
|
||||
|
||||
if (ab.TypeStr == "Active") { SetPos($"range-{ai}", x, y); x += RANGE_W + 60; }
|
||||
if (ab.TypeStr == "Triggered"){ SetPos($"trigger-{ai}", x, y); x += TRIGGER_W + 60; }
|
||||
if (ab.Costs.Count > 0) { SetPos($"cost-{ai}", x, y); x += COST_W + 60; }
|
||||
if (ab.Conditions.Count > 0) { SetPos($"cond-{ai}", x, y); x += COND_W + 60; }
|
||||
|
||||
double groupX = x;
|
||||
SetPos($"group-{ai}", groupX, y);
|
||||
|
||||
for (int j = 0; j < ab.Actions.Count; j++)
|
||||
{
|
||||
double ax = groupX + j * (ACTION_W + 50);
|
||||
SetPos($"action-{ai}-{j}", ax, y + 220);
|
||||
for (int k = 0; k < ab.Actions[j].Effects.Count; k++)
|
||||
SetPos($"effect-{ai}-{j}-{k}", ax, y + 220 + (k + 1) * 170);
|
||||
}
|
||||
|
||||
for (int sgi = 0; sgi < ab.SubGroups.Count; sgi++)
|
||||
{
|
||||
double sgx = groupX + (ab.Actions.Count + sgi) * (ACTION_W + 50);
|
||||
SetPos($"subgroup-{ai}-{sgi}", sgx, y + 220);
|
||||
var sg = ab.SubGroups[sgi];
|
||||
for (int j = 0; j < sg.Actions.Count; j++)
|
||||
{
|
||||
SetPos($"subgroupaction-{ai}-{sgi}-{j}", sgx, y + 220 + (j + 1) * 170);
|
||||
for (int k = 0; k < sg.Actions[j].Effects.Count; k++)
|
||||
SetPos($"subgroupeffect-{ai}-{sgi}-{j}-{k}", sgx, y + 220 + (j + 1) * 170 + (k + 1) * 160);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Only sets position if not already placed (preserves user-drag positions).</summary>
|
||||
private void SetPos(string key, double x, double y)
|
||||
{
|
||||
if (!_nodePos.ContainsKey(key))
|
||||
_nodePos[key] = (x, y);
|
||||
}
|
||||
|
||||
/// <summary>Sets position unconditionally — used for newly-added nodes.</summary>
|
||||
private void AutoPositionNew(string key, string kind)
|
||||
{
|
||||
// Drop new nodes near the center-bottom of any sibling group
|
||||
_nodePos[key] = kind switch
|
||||
{
|
||||
"action" => (960, 260),
|
||||
_ => (200, 200),
|
||||
};
|
||||
}
|
||||
|
||||
private void AddEffectToSelected()
|
||||
{
|
||||
if (_selectedNode is null) return;
|
||||
ParseNodeKey(_selectedNode, out var kind, out var ai, out var j, out _, out _);
|
||||
if (ai < 0 || ai >= _abilities.Count) return;
|
||||
|
||||
ActionDraft? act = null;
|
||||
string newEffKey;
|
||||
if (kind == "action" && j >= 0 && j < _abilities[ai].Actions.Count)
|
||||
{
|
||||
act = _abilities[ai].Actions[j];
|
||||
newEffKey = $"effect-{ai}-{j}-{act.Effects.Count}";
|
||||
}
|
||||
else return;
|
||||
|
||||
act.Effects.Add(new EffectDraft());
|
||||
AutoPositionNew(newEffKey, "effect");
|
||||
Compile();
|
||||
}
|
||||
|
||||
private void OnNodeMouseDown(MouseEventArgs e, string nodeId)
|
||||
{
|
||||
if (e.Button != 0) return;
|
||||
_draggingNode = nodeId;
|
||||
_lastMouseX = e.ClientX;
|
||||
_lastMouseY = e.ClientY;
|
||||
_selectedNode = nodeId;
|
||||
}
|
||||
|
||||
private void OnCanvasMouseMove(MouseEventArgs e)
|
||||
{
|
||||
double dx = e.ClientX - _lastMouseX;
|
||||
double dy = e.ClientY - _lastMouseY;
|
||||
_lastMouseX = e.ClientX;
|
||||
_lastMouseY = e.ClientY;
|
||||
|
||||
if (_isPanning)
|
||||
{
|
||||
_panX += dx;
|
||||
_panY += dy;
|
||||
}
|
||||
else if (_draggingNode != null && _nodePos.ContainsKey(_draggingNode))
|
||||
{
|
||||
var (ox, oy) = _nodePos[_draggingNode];
|
||||
_nodePos[_draggingNode] = (ox + dx / _zoom, oy + dy / _zoom);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCanvasMouseUp(MouseEventArgs e)
|
||||
{
|
||||
_draggingNode = null;
|
||||
_isPanning = false;
|
||||
}
|
||||
|
||||
private void OnCanvasMouseDown(MouseEventArgs e)
|
||||
{
|
||||
_lastMouseX = e.ClientX;
|
||||
_lastMouseY = e.ClientY;
|
||||
if (e.Button == 1) // middle mouse = pan
|
||||
_isPanning = true;
|
||||
else if (e.Button == 0)
|
||||
_selectedNode = null; // click canvas background = deselect
|
||||
}
|
||||
|
||||
private void ResetCanvas()
|
||||
{
|
||||
_zoom = 1.0; _panX = 60; _panY = 60;
|
||||
// Remove node positions so AutoLayout re-fires
|
||||
_nodePos.Clear();
|
||||
AutoLayoutAbility(_focusedAbility);
|
||||
}
|
||||
|
||||
// ── Canvas edge helpers ───────────────────────────────────────────────────
|
||||
|
||||
private IEnumerable<(string From, string To)> GetEdges()
|
||||
{
|
||||
int ai = _focusedAbility;
|
||||
if (ai < 0 || ai >= _abilities.Count) yield break;
|
||||
var ab = _abilities[ai];
|
||||
|
||||
string prev = $"meta-{ai}";
|
||||
|
||||
if (ab.TypeStr == "Active") { yield return (prev, $"range-{ai}"); prev = $"range-{ai}"; }
|
||||
if (ab.TypeStr == "Triggered"){ yield return (prev, $"trigger-{ai}"); prev = $"trigger-{ai}"; }
|
||||
if (ab.Costs.Count > 0) { yield return (prev, $"cost-{ai}"); prev = $"cost-{ai}"; }
|
||||
if (ab.Conditions.Count > 0) { yield return (prev, $"cond-{ai}"); prev = $"cond-{ai}"; }
|
||||
|
||||
yield return (prev, $"group-{ai}");
|
||||
|
||||
for (int j = 0; j < ab.Actions.Count; j++)
|
||||
{
|
||||
yield return ($"group-{ai}", $"action-{ai}-{j}");
|
||||
for (int k = 0; k < ab.Actions[j].Effects.Count; k++)
|
||||
yield return (k == 0 ? $"action-{ai}-{j}" : $"effect-{ai}-{j}-{k-1}",
|
||||
$"effect-{ai}-{j}-{k}");
|
||||
}
|
||||
|
||||
for (int sgi = 0; sgi < ab.SubGroups.Count; sgi++)
|
||||
{
|
||||
yield return ($"group-{ai}", $"subgroup-{ai}-{sgi}");
|
||||
var sg = ab.SubGroups[sgi];
|
||||
for (int j = 0; j < sg.Actions.Count; j++)
|
||||
{
|
||||
yield return ($"subgroup-{ai}-{sgi}", $"subgroupaction-{ai}-{sgi}-{j}");
|
||||
for (int k = 0; k < sg.Actions[j].Effects.Count; k++)
|
||||
yield return (k == 0 ? $"subgroupaction-{ai}-{sgi}-{j}" : $"subgroupeffect-{ai}-{sgi}-{j}-{k-1}",
|
||||
$"subgroupeffect-{ai}-{sgi}-{j}-{k}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private (double X, double Y) GetOutputPort(string nodeId)
|
||||
{
|
||||
var (x, y) = _nodePos.GetValueOrDefault(nodeId, (0, 0));
|
||||
return (x + GetNodeWidth(nodeId), y + NODE_H / 2);
|
||||
}
|
||||
|
||||
private (double X, double Y) GetInputPort(string nodeId)
|
||||
{
|
||||
var (x, y) = _nodePos.GetValueOrDefault(nodeId, (0, 0));
|
||||
return (x, y + NODE_H / 2);
|
||||
}
|
||||
|
||||
private static double GetNodeWidth(string nodeId)
|
||||
{
|
||||
if (nodeId.StartsWith("meta-")) return META_W;
|
||||
if (nodeId.StartsWith("range-")) return RANGE_W;
|
||||
if (nodeId.StartsWith("cost-")) return COST_W;
|
||||
if (nodeId.StartsWith("trigger-")) return TRIGGER_W;
|
||||
if (nodeId.StartsWith("cond-")) return COND_W;
|
||||
if (nodeId.StartsWith("subgroupaction-") || nodeId.StartsWith("action-")) return ACTION_W;
|
||||
if (nodeId.StartsWith("subgroupeffect-") || nodeId.StartsWith("effect-")) return EFFECT_W;
|
||||
return GROUP_W; // group- and subgroup-
|
||||
}
|
||||
|
||||
private static string BezierPath(double fx, double fy, double tx, double ty)
|
||||
{
|
||||
var ic = System.Globalization.CultureInfo.InvariantCulture;
|
||||
double c = Math.Abs(tx - fx) * 0.5;
|
||||
return $"M {fx.ToString("F0",ic)} {fy.ToString("F0",ic)} " +
|
||||
$"C {(fx+c).ToString("F0",ic)} {fy.ToString("F0",ic)}, " +
|
||||
$"{(tx-c).ToString("F0",ic)} {ty.ToString("F0",ic)}, " +
|
||||
$"{tx.ToString("F0",ic)} {ty.ToString("F0",ic)}";
|
||||
}
|
||||
|
||||
// ── Canvas style helpers ──────────────────────────────────────────────────
|
||||
|
||||
private static string NS((double X, double Y) pos, double w)
|
||||
{
|
||||
var ic = System.Globalization.CultureInfo.InvariantCulture;
|
||||
return $"position:absolute;left:{pos.X.ToString("F0",ic)}px;top:{pos.Y.ToString("F0",ic)}px;" +
|
||||
$"width:{w.ToString("F0",ic)}px;";
|
||||
}
|
||||
|
||||
private static string Px(double v)
|
||||
{
|
||||
return v.ToString("F0", System.Globalization.CultureInfo.InvariantCulture) + "px";
|
||||
}
|
||||
|
||||
private static string Pf(double v)
|
||||
{
|
||||
return v.ToString("F3", System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
// ── Node key parsing ──────────────────────────────────────────────────────
|
||||
|
||||
private static void ParseNodeKey(string? key,
|
||||
out string kind, out int ai, out int j, out int k, out int l)
|
||||
{
|
||||
kind = "none"; ai = j = k = l = -1;
|
||||
if (key is null) return;
|
||||
var p = key.Split('-');
|
||||
if (p.Length < 2) return;
|
||||
kind = p[0];
|
||||
int.TryParse(p[1], out ai);
|
||||
if (p.Length >= 3) int.TryParse(p[2], out j);
|
||||
if (p.Length >= 4) int.TryParse(p[3], out k);
|
||||
if (p.Length >= 5) int.TryParse(p[4], out l);
|
||||
}
|
||||
|
||||
// ── Effect summary (canvas node body) ────────────────────────────────────
|
||||
|
||||
private static string EffectSummary(EffectDraft d) => d.TypeKey switch
|
||||
{
|
||||
"DealDamage" or "DealDamagePlusStat" or "DOT"
|
||||
=> $"dmg {(string.IsNullOrEmpty(d.AmountRef) ? d.Amount.ToString() : "@" + d.AmountRef)}",
|
||||
"RestoreHealth" or "HOT" => $"heal {d.Amount}",
|
||||
"ModifyStat" or "ModifyMaxStat"
|
||||
=> $"{d.StatTarget} {d.Stat} {(d.Amount >= 0 ? "+" : "")}{d.Amount}",
|
||||
"DrawCards" => $"draw {d.N}",
|
||||
"DiscardCards" => $"discard {d.N}",
|
||||
"GainSP" or "SpendSP" or "ModifySPAccumulation"
|
||||
=> $"SP {(d.Amount >= 0 ? "+" : "")}{d.Amount}",
|
||||
"GainST" or "SpendST"
|
||||
=> $"ST {(d.Amount >= 0 ? "+" : "")}{d.Amount}",
|
||||
"MoveUnit" => $"move {d.Tiles} tiles",
|
||||
"PushUnit" => $"push {d.Tiles}",
|
||||
"PullUnit" => $"pull {d.Tiles}",
|
||||
"SummonToken" => "summon token",
|
||||
"DestroyToken" => "destroy token",
|
||||
"KillUnit" or "DestroyUnit" => "kill",
|
||||
"SkipTurn" => "skip turn",
|
||||
"DrawCards_Player" => $"draw {d.N} ({d.Player})",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
private void ApplyRawJson()
|
||||
{
|
||||
ParseJson(_compiledJson);
|
||||
|
||||
@@ -2,6 +2,61 @@ window.sorAdmin = {
|
||||
getTheme: function () {
|
||||
return localStorage.getItem('sor-admin-theme') || 'light';
|
||||
},
|
||||
|
||||
// ── Ability Builder canvas wheel/pan JS shim ──────────────────────────────
|
||||
// Registers a non-passive wheel listener so we can prevent page scroll and
|
||||
// forward zoom deltas to the Blazor component via JSInvokable.
|
||||
abilityBuilder: {
|
||||
_refs: {},
|
||||
|
||||
init(canvasId, dotnetRef) {
|
||||
this.dispose(canvasId);
|
||||
const el = document.getElementById(canvasId);
|
||||
if (!el) return;
|
||||
|
||||
const onWheel = e => {
|
||||
e.preventDefault();
|
||||
const factor = e.deltaY > 0 ? 0.9 : 1.1;
|
||||
dotnetRef.invokeMethodAsync('OnCanvasWheel', factor);
|
||||
};
|
||||
|
||||
// Pinch zoom via touch (two-finger).
|
||||
let lastPinchDist = 0;
|
||||
const onTouchStart = e => {
|
||||
if (e.touches.length === 2)
|
||||
lastPinchDist = Math.hypot(
|
||||
e.touches[0].clientX - e.touches[1].clientX,
|
||||
e.touches[0].clientY - e.touches[1].clientY);
|
||||
};
|
||||
const onTouchMove = e => {
|
||||
if (e.touches.length === 2) {
|
||||
e.preventDefault();
|
||||
const d = Math.hypot(
|
||||
e.touches[0].clientX - e.touches[1].clientX,
|
||||
e.touches[0].clientY - e.touches[1].clientY);
|
||||
if (lastPinchDist > 0) {
|
||||
const factor = d / lastPinchDist;
|
||||
dotnetRef.invokeMethodAsync('OnCanvasWheel', factor);
|
||||
}
|
||||
lastPinchDist = d;
|
||||
}
|
||||
};
|
||||
|
||||
el.addEventListener('wheel', onWheel, { passive: false });
|
||||
el.addEventListener('touchstart', onTouchStart, { passive: true });
|
||||
el.addEventListener('touchmove', onTouchMove, { passive: false });
|
||||
this._refs[canvasId] = { el, onWheel, onTouchStart, onTouchMove };
|
||||
},
|
||||
|
||||
dispose(canvasId) {
|
||||
const r = this._refs[canvasId];
|
||||
if (!r) return;
|
||||
r.el.removeEventListener('wheel', r.onWheel);
|
||||
r.el.removeEventListener('touchstart', r.onTouchStart);
|
||||
r.el.removeEventListener('touchmove', r.onTouchMove);
|
||||
delete this._refs[canvasId];
|
||||
}
|
||||
},
|
||||
setTheme: function (theme) {
|
||||
localStorage.setItem('sor-admin-theme', theme);
|
||||
document.documentElement.setAttribute('data-bs-theme', theme);
|
||||
|
||||
@@ -987,6 +987,62 @@ public static class AbilitySystem
|
||||
return state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resumes execution after the chooser has responded to a <c>game.reveal_choice_pick</c>.
|
||||
/// <paramref name="orderedIndices"/> is the chooser's desired ordering of the revealed cards
|
||||
/// (0-based indices into <see cref="Models.PendingRevealChoicePick.RevealedCardsJson"/>).
|
||||
/// Unspecified cards are placed beneath the chosen cards in their original relative order.
|
||||
/// </summary>
|
||||
public static GameState ResumeRevealChoicePick(
|
||||
GameState state,
|
||||
string actorId,
|
||||
string requestId,
|
||||
int[] orderedIndices)
|
||||
{
|
||||
var pending = state.PendingRevealChoicePick
|
||||
?? throw new GameException("NO_PENDING_REVEAL_CHOICE_PICK");
|
||||
|
||||
if (pending.RequestId != requestId)
|
||||
throw new GameException("REQUEST_ID_MISMATCH");
|
||||
|
||||
if (actorId != pending.ActorId && actorId != pending.ChooserActorId)
|
||||
throw new GameException("NOT_YOUR_REVEAL_CHOICE_PICK");
|
||||
|
||||
state.PendingRevealChoicePick = null;
|
||||
|
||||
if (pending.EffectType == "StackDeck")
|
||||
{
|
||||
var revealed = JsonSerializer.Deserialize<CardInstance[]>(
|
||||
pending.RevealedCardsJson, _jsonOpts) ?? [];
|
||||
|
||||
if (!state.Players.TryGetValue(pending.TargetPlayerAccountId, out var ps))
|
||||
return state;
|
||||
|
||||
// Validate indices (deduplicate, clamp to valid range).
|
||||
var validIndices = orderedIndices
|
||||
.Where(i => i >= 0 && i < revealed.Length)
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
||||
var usedSet = new HashSet<int>(validIndices);
|
||||
|
||||
// Unspecified cards go at the bottom of the returned block (drawn last).
|
||||
var bottom = Enumerable.Range(0, revealed.Length)
|
||||
.Where(i => !usedSet.Contains(i))
|
||||
.Select(i => revealed[i])
|
||||
.ToList();
|
||||
|
||||
// Specified cards go on top (drawn first) in the chooser's order.
|
||||
var top = validIndices.Select(i => revealed[i]).ToList();
|
||||
|
||||
// Deck is stored with index 0 = bottom; top of deck is last element.
|
||||
ps.Deck.AddRange(bottom);
|
||||
ps.Deck.AddRange(top);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
// ── Action execution ──────────────────────────────────────────────────────
|
||||
|
||||
private static void ExecuteActions(
|
||||
@@ -2358,17 +2414,45 @@ public static class AbilitySystem
|
||||
// ── §5.18 Zone operations ──────────────────────────────────────────
|
||||
case StackDeckEffect stkDe when target is PlayerState stackPs:
|
||||
{
|
||||
// TODO(Phase5-full): requires PendingRevealChoicePick interactive pause.
|
||||
// For now: shuffle top N randomly as a non-interactive fallback.
|
||||
int n = Math.Min(stkDe.Count, stackPs.Deck.Count);
|
||||
var topN = stackPs.Deck.TakeLast(n).ToList();
|
||||
for (int si = topN.Count - 1; si > 0; si--)
|
||||
if (n == 0) break;
|
||||
|
||||
// Determine chooser account id.
|
||||
string chooserAccountId = stkDe.Chooser switch
|
||||
{
|
||||
int sj = Random.Shared.Next(si + 1);
|
||||
(topN[si], topN[sj]) = (topN[sj], topN[si]);
|
||||
"Opponent" => ctx.State.GetEnemyIds(ctx.ActorId).FirstOrDefault() ?? ctx.ActorId,
|
||||
"Random" => "",
|
||||
_ => ctx.ActorId, // "Self"
|
||||
};
|
||||
|
||||
if (stkDe.Chooser == "Random" || string.IsNullOrEmpty(chooserAccountId))
|
||||
{
|
||||
// Non-interactive: shuffle top N randomly.
|
||||
var topN = stackPs.Deck.TakeLast(n).ToList();
|
||||
for (int si = topN.Count - 1; si > 0; si--)
|
||||
{
|
||||
int sj = Random.Shared.Next(si + 1);
|
||||
(topN[si], topN[sj]) = (topN[sj], topN[si]);
|
||||
}
|
||||
for (int si = 0; si < n; si++)
|
||||
stackPs.Deck[stackPs.Deck.Count - n + si] = topN[si];
|
||||
break;
|
||||
}
|
||||
for (int si = 0; si < n; si++)
|
||||
stackPs.Deck[stackPs.Deck.Count - n + si] = topN[si];
|
||||
|
||||
// Interactive: remove top N from deck and pause for chooser to order them.
|
||||
var revealed = stackPs.Deck.TakeLast(n).ToList();
|
||||
stackPs.Deck.RemoveRange(stackPs.Deck.Count - n, n);
|
||||
|
||||
ctx.State.PendingRevealChoicePick = new Models.PendingRevealChoicePick
|
||||
{
|
||||
ActorId = ctx.ActorId,
|
||||
ChooserActorId = chooserAccountId,
|
||||
SourceInstanceId = ctx.Source?.InstanceId ?? "",
|
||||
EffectType = "StackDeck",
|
||||
RevealedCardsJson = JsonSerializer.Serialize(revealed, _jsonOpts),
|
||||
Count = n,
|
||||
TargetPlayerAccountId = stackPs.AccountId,
|
||||
};
|
||||
break;
|
||||
}
|
||||
case SearchAndPlaceEffect sape when target is PlayerState sapPs:
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Pauses execution when an effect needs a human to select a player
|
||||
/// (e.g. ChannelCardFromZoneEffect with UnderControlOf: Choice).
|
||||
/// Resumed by <c>game.player_pick</c> message.
|
||||
/// </summary>
|
||||
public sealed class PendingPlayerPick
|
||||
{
|
||||
public string RequestId { get; set; } = Guid.NewGuid().ToString("N");
|
||||
public string ActorId { get; set; } = string.Empty;
|
||||
public string ChooserActorId { get; set; } = string.Empty;
|
||||
public string SourceInstanceId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Discriminator used by ResumeXxx to know what to do with the picked player.</summary>
|
||||
public string EffectType { get; set; } = string.Empty;
|
||||
|
||||
// ── Candidate pool (sent to client for display) ───────────────────────────
|
||||
|
||||
/// <summary>"Self" | "Opponent" | "Any" — ownership filter on valid player choices.</summary>
|
||||
public string Ownership { get; set; } = "Any";
|
||||
/// <summary>Account IDs of the valid choices (populated by engine at pause time).</summary>
|
||||
public List<string> ValidPlayerIds { get; set; } = new();
|
||||
|
||||
// ── Continuation ─────────────────────────────────────────────────────────
|
||||
|
||||
public string ContinuationActionsJson { get; set; } = "[]";
|
||||
public string? RangeJson { get; set; }
|
||||
public string? ForceDurationJson { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Pauses execution when cards are revealed face-up and a player must choose
|
||||
/// an ordering or selection from them (e.g. StackDeckEffect chooser).
|
||||
/// Resumed by <c>game.reveal_choice_pick</c> message carrying an ordered array of indices.
|
||||
/// </summary>
|
||||
public sealed class PendingRevealChoicePick
|
||||
{
|
||||
public string RequestId { get; set; } = Guid.NewGuid().ToString("N");
|
||||
public string ActorId { get; set; } = string.Empty;
|
||||
public string ChooserActorId { get; set; } = string.Empty;
|
||||
public string SourceInstanceId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Discriminator: "StackDeck" | future uses.</summary>
|
||||
public string EffectType { get; set; } = string.Empty;
|
||||
|
||||
// ── Revealed card set ─────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Serialized CardInstance[] — the revealed cards the chooser sees and orders.
|
||||
/// Temporarily removed from the deck while this state is pending.
|
||||
/// </summary>
|
||||
public string RevealedCardsJson { get; set; } = "[]";
|
||||
|
||||
/// <summary>How many cards the chooser must include in their response ordering.</summary>
|
||||
public int Count { get; set; } = 1;
|
||||
|
||||
// ── Context ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>AccountId of the player whose deck receives the ordered cards.</summary>
|
||||
public string TargetPlayerAccountId { get; set; } = string.Empty;
|
||||
|
||||
// ── Continuation ─────────────────────────────────────────────────────────
|
||||
|
||||
public string ContinuationActionsJson { get; set; } = "[]";
|
||||
public string? RangeJson { get; set; }
|
||||
public string? ForceDurationJson { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Game.Abilities.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Pauses execution when an effect needs a human to select a specific tile
|
||||
/// (e.g. CloneSpiritAsToken with TargetTile destination, RelocateRuin).
|
||||
/// Resumed by <c>game.tile_pick</c> message.
|
||||
/// </summary>
|
||||
public sealed class PendingTilePick
|
||||
{
|
||||
public string RequestId { get; set; } = Guid.NewGuid().ToString("N");
|
||||
public string ActorId { get; set; } = string.Empty;
|
||||
public string ChooserActorId { get; set; } = string.Empty;
|
||||
public string SourceInstanceId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Discriminator used by ResumeXxx to know what to do with the picked tile.</summary>
|
||||
public string EffectType { get; set; } = string.Empty;
|
||||
|
||||
// ── Tile constraints (sent to client for validation) ─────────────────────
|
||||
|
||||
/// <summary>Tile must be empty (no occupant).</summary>
|
||||
public bool RequireEmpty { get; set; }
|
||||
/// <summary>Tile must have an occupant.</summary>
|
||||
public bool RequireOccupied { get; set; }
|
||||
/// <summary>"Owner" | "Ally" | "Enemy" | "Any" — ownership of occupant when RequireOccupied.</summary>
|
||||
public string? OccupantOwnership { get; set; }
|
||||
/// <summary>Max tiles from source; 0 = unlimited.</summary>
|
||||
public int MaxRange { get; set; }
|
||||
|
||||
// ── Continuation ─────────────────────────────────────────────────────────
|
||||
|
||||
public string ContinuationActionsJson { get; set; } = "[]";
|
||||
public string? RangeJson { get; set; }
|
||||
public string? ForceDurationJson { get; set; }
|
||||
}
|
||||
@@ -126,6 +126,27 @@ public sealed class GameState
|
||||
/// player must select a branch. Paused until chooser submits a <c>game.branch_pick</c>.
|
||||
/// </summary>
|
||||
public Abilities.Models.PendingBranchPick? PendingBranchPick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Non-null when an effect needs a human to select a specific tile
|
||||
/// (e.g. CloneSpiritAsToken TargetTile destination, RelocateRuin).
|
||||
/// Paused until the chooser submits a <c>game.tile_pick</c> response.
|
||||
/// </summary>
|
||||
public Abilities.Models.PendingTilePick? PendingTilePick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Non-null when an effect needs a human to select a player
|
||||
/// (e.g. ChannelCardFromZone with UnderControlOf: Choice).
|
||||
/// Paused until the chooser submits a <c>game.player_pick</c> response.
|
||||
/// </summary>
|
||||
public Abilities.Models.PendingPlayerPick? PendingPlayerPick { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Non-null when cards have been revealed face-up and a player must choose their
|
||||
/// ordering (e.g. StackDeckEffect interactive path).
|
||||
/// Paused until the chooser submits a <c>game.reveal_choice_pick</c> response.
|
||||
/// </summary>
|
||||
public Abilities.Models.PendingRevealChoicePick? PendingRevealChoicePick { get; set; }
|
||||
}
|
||||
|
||||
public sealed class PlayerState
|
||||
|
||||
Reference in New Issue
Block a user