-
-@code {
-
-// ══════════════════════════════════════════════════════════════════
-// DRAFT MODEL
-// ══════════════════════════════════════════════════════════════════
-
-private sealed class AbilityDraft
-{
- public string Name { get; set; } = "New Ability";
- public string Description { get; set; } = "";
- public string Type { get; set; } = "Active";
-
- // Common limits
- public int? LimitPerTurn { get; set; }
- public int? LimitPerGame { get; set; }
- public int UsesPerTurn { get; set; } = 1;
-
- // Presentation
- public string? AnimKey { get; set; }
- public string? CastSfx { get; set; }
- public string? ImpactSfx { get; set; }
-
- // Active
- public int RangeMin { get; set; } = 1;
- public int RangeMax { get; set; } = 1;
- public bool RequiresLos { get; set; }
- public bool LinearOnly { get; set; }
-
- // Triggered
- public string TriggerFamily { get; set; } = "Unit — Lifecycle";
- public string TriggerEvent { get; set; } = "OnUnitEnterBattlefield";
- public List SourceZoneGate { get; set; } = ["Battlefield"];
- public string TriggerLimitMode { get; set; } = "Unlimited";
- public int? TriggerLimitAmount { get; set; }
- public string TriggerOwnership { get; set; } = "Any";
- // Extra trigger params (shared across triggers that have them)
- public string? TriggerOwnership2 { get; set; } // SourceOwnership / TargetOwnership
- public string? TriggerUnitType { get; set; } = "Unit";
- public int? TriggerAmount { get; set; }
- public string? TriggerDamageType { get; set; } = "Any";
- public string? TriggerPlayer { get; set; } = "Owner";
- public string? TriggerStat { get; set; }
- public string? TriggerCause { get; set; }
-
- // Passive
- public string PassiveScope { get; set; } = "Battlefield";
- public string PassiveCadence { get; set; } = "OnAnyEvent";
- public string PassiveLeavePolicy { get; set; } = "Remove";
-
- // Aura
- public int AuraRangeMin { get; set; } = 1;
- public int AuraRangeMax { get; set; } = 2;
- public bool AuraClearOnLeave { get; set; }
- public string AuraLingerDurationType { get; set; } = "";
- public int? AuraLingerN { get; set; }
-
- // Logic groups
- public LogicGroupDraft ActivationConditions { get; set; } = new();
-
- // Costs & Actions
- public List Costs { get; set; } = new();
- public List Actions { get; set; } = new();
-}
-
-private sealed class LogicGroupDraft
-{
- public string Logic { get; set; } = "AND";
- public List Rules { get; set; } = new();
- public List Groups { get; set; } = new();
-}
-
-private sealed class CondDraft
-{
- public string Domain { get; set; } = "Unit";
- public string Field { get; set; } = "HasGenus";
- public string Comparator { get; set; } = "==";
- public string Value { get; set; } = "";
- public string Subject { get; set; } = "Self"; // Self | Target
-}
-
-private sealed class CostDraft
-{
- public string TypeStr { get; set; } = "SpiritPoints";
- public int Amount { get; set; } = 1;
- public string PickMode { get; set; } = "";
- public string? FilterGenusTag { get; set; }
-}
-
-private sealed class ActionDraft
-{
- public string Scope { get; set; } = "Battlefield";
- public string TargetType { get; set; } = "Unit";
- public string Ownership { get; set; } = "Enemy";
- public int Count { get; set; } = 1;
- public bool All { get; set; }
- public bool UpTo { get; set; }
-
- public LogicGroupDraft Conditions { get; set; } = new();
- public List Effects { get; set; } = new();
- public List Branches { get; set; } = new();
-
- public string DurationType { get; set; } = "";
- public int? DurationN { get; set; }
- public string DurationPlayerScope { get; set; } = "";
-}
-
-private sealed class EffectDraft
-{
- public string TypeKey { get; set; } = "DealDamage";
- // Stat mod fields
- public int? Amount { get; set; } = 1;
- public string? AmountRef { get; set; } // dynamic ValueExpr.Ref
- public string StatModOp { get; set; } = "Add";
- public string StatTarget { get; set; } = "Current";
- // Bool flag effects
- public bool BoolValue { get; set; } = true;
- // String param effects
- public string? StringParam { get; set; } // genus tag, ability name, affinity, etc.
- // Zone effects
- public string DeckPosition { get; set; } = "top";
- // Duration (for DOT/HOT/TakeControl)
- public string DurationType { get; set; } = "UntilEndOfTurn";
- public int? DurationN { get; set; }
- // Drawing / milling counts
- public int? CountN { get; set; } = 1;
- // Displacement
- public int? Tiles { get; set; } = 1;
- public string Direction { get; set; } = "North";
- public int? BlockedDamage { get; set; }
- // BypassDefense
- public bool BypassDefense { get; set; }
- // Controller override
- public string? Controller { get; set; }
- // Multiplier
- public double? CostMultiplier { get; set; }
- public bool PayCost { get; set; } = true;
- // Player targeting for zone effects
- public string TargetPlayer { get; set; } = "Owner";
- // SetStatModMultiplier
- public string? StatName { get; set; }
- public double Multiplier { get; set; } = 1.0;
- // MinAttackRange/Max
- public int? RangeMin { get; set; }
- public int? RangeMax { get; set; }
- // Cost mod
- public int? SpMod { get; set; }
- public int? StMod { get; set; }
- // Health minimum
- public int? Minimum { get; set; } = 1;
- // SetFixedSacrificeReturn
- public int? StAmount { get; set; }
- // GrantAdditionalAttack
- public int AttackCount { get; set; } = 1;
- // SummonToken
- public string? TokenJson { get; set; }
-}
-
-private sealed class BranchDraft
-{
- public string Label { get; set; } = "Branch";
-}
-
-// ══════════════════════════════════════════════════════════════════
-// STATIC CATALOG DATA
-// ══════════════════════════════════════════════════════════════════
-
-private record Entry(string Key, string Display);
-
-private static readonly Dictionary> TriggerFamilies = new()
-{
- ["Turn / Timing"] = [new("OnTurnStart","On Turn Start"), new("OnTurnEnd","On Turn End")],
- ["Channeling"] = [new("OnChanneled","On Channeled")],
- ["ArchSpirit"] = [new("OnAscend","On Ascend"), new("OnTransition","On Transition")],
- ["Unit — Actions"] = [new("OnUnitMove","On Unit Move"), new("OnUnitAttack","On Unit Attack"),
- new("OnUnitAbilityActivated","On Unit Ability Activated"), new("OnUnitMPSpent","On Unit MP Spent")],
- ["Damage & Healing"] = [new("OnDamageDealt","On Damage Dealt"), new("OnDamagePrevented","On Damage Prevented"),
- new("OnHealed","On Healed"), new("BeforeUnitDeath","Before Unit Death"),
- new("BeforeDamageApplied","Before Damage Applied")],
- ["Unit — Lifecycle"] = [new("OnUnitEnterBattlefield","On Unit Enter Battlefield"),
- new("OnUnitLeaveBattlefield","On Unit Leave Battlefield"),
- new("OnUnitDeath","On Unit Death"), new("OnUnitSentToDiscard","On Unit Sent To Discard"),
- new("OnSpiritSacrificed","On Spirit Sacrificed"), new("OnTokenSummoned","On Token Summoned")],
- ["Unit — State"] = [new("OnStatModified","On Stat Modified"), new("OnAbilityAdded","On Ability Added"),
- new("OnAbilityRemoved","On Ability Removed"), new("OnGenusChanged","On Genus Changed")],
- ["Ruin"] = [new("OnRuinActivation","On Ruin Activation"), new("OnUnitOccupyRuin","On Unit Occupy Ruin")],
- ["Tile"] = [new("OnTileAffinityChanged","On Tile Affinity Changed")],
- ["Player Resources"] = [new("OnSPGained","On SP Gained"), new("OnSPSpent","On SP Spent"),
- new("OnSTGained","On ST Gained"), new("OnSTSpent","On ST Spent")],
- ["Card Zone"] = [new("OnCardDrawn","On Card Drawn"), new("OnCardDiscarded","On Card Discarded"),
- new("OnCardReturnedToHand","On Card Returned To Hand"),
- new("OnCardReturnedToDeck","On Card Returned To Deck"),
- new("OnDeckShuffled","On Deck Shuffled"), new("OnCardsRevealed","On Cards Revealed")],
- ["Effect Lifecycle"] = [new("OnTargetedByAbility","On Targeted By Ability"),
- new("OnEffectApplied","On Effect Applied"),
- new("OnEnterAuraRange","On Enter Aura Range"), new("OnLeaveAuraRange","On Leave Aura Range")],
-};
-
-private static readonly Dictionary> EffectGroups = new()
-{
- ["Stat Modification"] = [
- new("ModifyHealth","Modify Health"), new("ModifyDefense","Modify Defense"),
- new("ModifyDamage","Modify Damage"), new("ModifyMP","Modify MP"),
- new("ModifyMinAttackRange","Modify Min Attack Range"), new("ModifyMaxAttackRange","Modify Max Attack Range"),
- new("SetAttackRange","Set Attack Range"), new("SetMovementType","Set Movement Type"),
- new("ModifyCost","Modify SP/ST Cost"), new("SetAffinity","Set Affinity"),
- new("GrantAdditionalAttack","Grant Additional Attack"), new("SetStatModMultiplier","Set Stat Mod Multiplier"),
- ],
- ["Unit Flags"] = [
- new("SetCanMove","Set Can Move"), new("SetCanAttack","Set Can Attack"),
- new("SetCanDefend","Set Can Defend"), new("SetCanBeAttacked","Set Can Be Attacked"),
- new("SetCanBeBlocked","Set Can Be Blocked"), new("SetCanBeObstructed","Set Can Be Obstructed"),
- new("SetCanUseAbility","Set Can Use Ability"), new("SetCanBeSacrificed","Set Can Be Sacrificed"),
- ],
- ["Player Flags"] = [
- new("SetCanDrawCards","Set Can Draw Cards"), new("SetAccumulatesSP","Set Accumulates SP"),
- new("SetCanChannelSpirit","Set Can Channel Spirit"), new("SetCanSacrificeSpirit","Set Can Sacrifice Spirit"),
- new("SetCanAscendArchSpirit","Set Can Ascend ArchSpirit"), new("SetCanTransitionArchSpirit","Set Can Transition ArchSpirit"),
- new("SetCanChannelRepentance","Set Can Channel Repentance"), new("SetCanChannelInstinct","Set Can Channel Instinct"),
- new("SetCanChannelRuin","Set Can Channel Ruin"),
- new("SetCanChannelTerramorphaMono","Set Can Channel Terramorpha Mono"),
- new("SetCanChannelTerramorphaDi","Set Can Channel Terramorpha Di"),
- new("SetCanChannelTerramorphaTri","Set Can Channel Terramorpha Tri"),
- ],
- ["Ability Modification"] = [
- new("AddAbility","Add Ability"), new("RemoveAbility","Remove Ability"),
- new("EnableAbility","Enable Ability"), new("DisableAbility","Disable Ability"),
- ],
- ["Genus"] = [
- new("AddGenus","Add Genus"), new("RemoveGenus","Remove Genus"),
- ],
- ["Player Resources"] = [
- new("ModifySP","Modify SP"), new("ModifySPAccumulation","Modify SP Accumulation"),
- new("ModifyST","Modify ST"), new("ModifyCardsDrawnPerTurn","Modify Cards Drawn Per Turn"),
- ],
- ["Tile"] = [
- new("SetBaseAffinity1","Set Base Affinity 1"), new("SetBaseAffinity2","Set Base Affinity 2"),
- new("PushAffinity","Push Affinity"), new("PushFinalAffinity","Push Final Affinity"),
- ],
- ["Zone / Cards"] = [
- new("DrawCards","Draw Cards"), new("DiscardCards","Discard Cards"),
- new("ReturnToHand","Return To Hand"), new("ReturnToDeck","Return To Deck"),
- new("ReturnToBattlefield","Return To Battlefield"), new("SendToDiscard","Send To Discard"),
- new("SearchDeck","Search Deck"), new("ShuffleDeck","Shuffle Deck"),
- new("RevealCards","Reveal Cards"), new("PlaceOnDeck","Place On Deck"),
- new("ChannelCard","Channel Card"),
- ],
- ["Combat / Damage"] = [
- new("DealDamage","Deal Damage"), new("Heal","Heal"),
- new("DealDamageToSelf","Deal Damage To Self"), new("DOT","Damage Over Time"),
- new("HOT","Heal Over Time"), new("PreventDeath","Prevent Death"),
- new("PreventNextDamage","Prevent Next Damage"), new("SetHealthMinimum","Set Health Minimum"),
- ],
- ["Displacement"] = [
- new("PushUnit","Push Unit"), new("PullUnit","Pull Unit"),
- new("DisplaceUnit","Displace Unit"), new("RepositionUnit","Reposition Unit"),
- ],
- ["Control"] = [
- new("TakeControl","Take Control"), new("GrantMovementControl","Grant Movement Control"),
- new("SetFixedSacrificeReturn","Set Fixed Sacrifice Return"),
- ],
- ["Token"] = [
- new("SummonToken","Summon Token"),
- ],
- ["Deferred"] = [
- new("ApplyOnEvent","Apply On Event"),
- ],
-};
-
-private static readonly Entry[] NodeTypes =
-[
- new("Trigger","⚡ Trigger"), new("ConditionGroup","◆ Conditions"), new("CostGroup","◉ Costs"),
- new("ActionGroup","▶ Actions"), new("Effect","✦ Effect"),
-];
-
-private static readonly string[] StatModOps = ["Add","Subtract","Multiply","Divide","Percent"];
-private static readonly string[] Affinities = ["Fire","Water","Earth","Air","Void","Neutral"];
-private static readonly string[] MovementTypes = ["Walk","Fly","Burrow","Swim","Phase"];
-private static readonly string[] Ownerships = ["Owner","Enemy","Any","Ally"];
-private static readonly string[] DurationTypes = ["Instant","UntilEndOfTurn","UntilStartOfOwnerTurn",
- "UntilStartOfSourceOwnerTurn","ForNTurns","UntilEndOfSequence","WhileCondition",
- "WhileSourceOnBattlefield","PermanentInMatch"];
-
-// ══════════════════════════════════════════════════════════════════
-// STATE
-// ══════════════════════════════════════════════════════════════════
-
-private AbilityDraft _draft = new();
-private string _mode = "form";
-private string _compiledJson = "// Click Compile";
-private int _mermaidKey = 0;
-private record ValidationError(string Sev, string Message);
-private List _errors = new();
-
-// Canvas state
-private sealed class CanvasNode
-{
- public string Id { get; set; } = Guid.NewGuid().ToString("N")[..8];
- public string Kind { get; set; } = "Effect";
- public string? Label { get; set; }
- public double X { get; set; }
- public double Y { get; set; }
- public bool Selected { get; set; }
- public string? EffectTypeKey { get; set; } = "DealDamage";
- public int? Amount { get; set; }
- public string? TriggerEventKey { get; set; } = "OnUnitEnterBattlefield";
-}
-private sealed class CanvasConnection
-{
- public string FromId { get; set; } = "";
- public string ToId { get; set; } = "";
- public string Label { get; set; } = "";
-}
-private List _nodes = new();
-private List _connections = new();
-private CanvasNode? _selectedNode;
-private CanvasNode? _draggingNode;
-private CanvasNode? _wiringFrom;
-private double _wireX, _wireY;
-private double _dragOffX, _dragOffY;
-private string _paletteDragKind = "";
-
-// ══════════════════════════════════════════════════════════════════
-// LIFECYCLE
-// ══════════════════════════════════════════════════════════════════
-
-protected override async Task OnAfterRenderAsync(bool firstRender)
-{
- if (_mode == "mermaid")
- {
- try { await JS.InvokeVoidAsync("mermaid.run"); } catch { }
- }
-}
-
-// ══════════════════════════════════════════════════════════════════
-// HELPERS
-// ══════════════════════════════════════════════════════════════════
-
-private IEnumerable CurrentFamilyEvents =>
- TriggerFamilies.TryGetValue(_draft.TriggerFamily, out var list) ? list : [];
-
-private void OnTypeChanged(ChangeEventArgs e)
-{
- _draft.Type = e.Value?.ToString() ?? "Active";
- Compile();
-}
-
-private void OnFamilyChanged(ChangeEventArgs e)
-{
- _draft.TriggerFamily = e.Value?.ToString() ?? TriggerFamilies.Keys.First();
- _draft.TriggerEvent = CurrentFamilyEvents.FirstOrDefault()?.Key ?? "";
-}
-
-private void ToggleZoneGate(string zone, bool on)
-{
- if (on) { if (!_draft.SourceZoneGate.Contains(zone)) _draft.SourceZoneGate.Add(zone); }
- else _draft.SourceZoneGate.Remove(zone);
-}
-
-private void SetMode(string m) { _mode = m; if (m == "mermaid") { _mermaidKey++; } }
-
-private void AddCost() => _draft.Costs.Add(new());
-private void AddAction() => _draft.Actions.Add(new());
-
-private static IEnumerable GetTargetTypes(string scope) => scope switch
-{
- "Battlefield" => ["Unit","ArchSpirit","Spirit","SpiritToken","Ruin","Tile"],
- "Player" => ["Player"],
- _ => ["Card","Spirit","ArchSpirit","SpiritToken","Ruin","Unit"],
-};
-
-private static string NodeColor(string kind) => kind switch
-{
- "Trigger" => "#4a0070",
- "ConditionGroup" => "#00305a",
- "CostGroup" => "#5a3000",
- "ActionGroup" => "#004a30",
- "Effect" => "#5a0020",
- _ => "#333",
-};
-
-// ══════════════════════════════════════════════════════════════════
-// CANVAS INTERACTIVITY
-// ══════════════════════════════════════════════════════════════════
-
-private void OnPaletteDragStart(string kind) => _paletteDragKind = kind;
-
-private void OnCanvasDrop(DragEventArgs e)
-{
- if (string.IsNullOrEmpty(_paletteDragKind)) return;
- _nodes.Add(new CanvasNode { Kind = _paletteDragKind, X = e.OffsetX - 60, Y = e.OffsetY - 20 });
- _paletteDragKind = "";
-}
-
-private void OnNodeMouseDown(MouseEventArgs e, CanvasNode node)
-{
- if (e.Button == 0)
- {
- foreach (var n in _nodes) n.Selected = false;
- node.Selected = true;
- _selectedNode = node;
- _draggingNode = node;
- _dragOffX = e.OffsetX - node.X;
- _dragOffY = e.OffsetY - node.Y;
- }
-}
-
-private void OnPortMouseDown(MouseEventArgs e, CanvasNode node)
-{
- _wiringFrom = node;
- _wireX = node.X + 120;
- _wireY = node.Y + 20;
-}
-
-private void OnCanvasMouseDown(MouseEventArgs e)
-{
- if (e.Button == 0 && _draggingNode == null)
- {
- foreach (var n in _nodes) n.Selected = false;
- _selectedNode = null;
- }
-}
-
-private void OnCanvasMouseMove(MouseEventArgs e)
-{
- if (_draggingNode != null)
- {
- _draggingNode.X = e.OffsetX - _dragOffX;
- _draggingNode.Y = e.OffsetY - _dragOffY;
- }
- if (_wiringFrom != null)
- {
- _wireX = e.OffsetX;
- _wireY = e.OffsetY;
- }
-}
-
-private void OnCanvasMouseUp(MouseEventArgs e)
-{
- if (_wiringFrom != null)
- {
- // Find if mouse is over another node
- var target = _nodes.FirstOrDefault(n =>
- n.Id != _wiringFrom.Id &&
- e.OffsetX >= n.X && e.OffsetX <= n.X + 120 &&
- e.OffsetY >= n.Y && e.OffsetY <= n.Y + 40);
- if (target != null)
- _connections.Add(new CanvasConnection { FromId = _wiringFrom.Id, ToId = target.Id });
- _wiringFrom = null;
- }
- _draggingNode = null;
-}
-
-private void DeleteSelectedNode()
-{
- if (_selectedNode == null) return;
- _connections.RemoveAll(c => c.FromId == _selectedNode.Id || c.ToId == _selectedNode.Id);
- _nodes.Remove(_selectedNode);
- _selectedNode = null;
-}
-
-// ══════════════════════════════════════════════════════════════════
-// FORM RENDERERS
-// ══════════════════════════════════════════════════════════════════
-
-private RenderFragment RenderLogicGroup(LogicGroupDraft group, string key) => __builder =>
-{
-
-
-
-
-
- @foreach (var (rule, ri) in group.Rules.Select((r,i)=>(r,i)))
- {
-
-
-
-
-
-
-
-
-
-
- }
-
-
- @foreach (var sub in group.Groups)
- {
-
- @RenderLogicGroup(sub, key + "_sub")
-
- }
-
-};
-
-private RenderFragment RenderTriggerParams() => __builder =>
-{
- var ev = _draft.TriggerEvent;
-
- // Ownership (most triggers have it)
- if (ev is not ("OnTileAffinityChanged"))
- {
-
-
-
- }
-
- // Unit Type (lifecycle triggers)
- if (ev is "OnUnitEnterBattlefield" or "OnUnitLeaveBattlefield" or "OnUnitDeath"
- or "OnUnitSentToDiscard" or "BeforeUnitDeath")
- {
-
- }
-
- // Amount (damage/heal/resource triggers)
- if (ev is "OnDamageDealt" or "OnHealed" or "OnSPGained" or "OnSPSpent"
- or "OnSTGained" or "OnSTSpent" or "OnUnitMPSpent")
- {
-
-
-
- }
-
- // Player (turn/resource/card-zone triggers)
- if (ev is "OnTurnStart" or "OnTurnEnd" or "OnSPGained" or "OnSPSpent"
- or "OnSTGained" or "OnSTSpent" or "OnCardDrawn" or "OnCardDiscarded"
- or "OnCardReturnedToHand" or "OnCardReturnedToDeck" or "OnDeckShuffled" or "OnCardsRevealed")
- {
-
-
-
- }
-
- // Aura Ownership (aura triggers)
- if (ev is "OnEnterAuraRange" or "OnLeaveAuraRange")
- {
-
- }
-};
-
-private RenderFragment RenderEffectParams(EffectDraft eff) => __builder =>
-{
- var t = eff.TypeKey;
-
- // Stat mod effects: Amount + Operator + StatTarget
- if (t is "ModifyHealth" or "ModifyDefense" or "ModifyDamage" or "ModifyMP"
- or "ModifyMinAttackRange" or "ModifyMaxAttackRange")
- {
-
-
-
-
-
-
- if (t is "ModifyHealth" or "ModifyDefense" or "ModifyMP")
- {
-
- }
-
- // Movement type
- else if (t == "SetMovementType")
- {
-
-
-
- }
-
- // Affinity effects
- else if (t is "SetAffinity" or "SetBaseAffinity1" or "SetBaseAffinity2"
- or "PushAffinity" or "PushFinalAffinity")
- {
-
-
-
- }
-
- // Bool flag effects (unit/player)
- else if (t.StartsWith("SetCan") || t == "SetAccumulatesSP")
- {
-
-
-
- }
-
- // Ability mod effects
- else if (t is "RemoveAbility" or "EnableAbility" or "DisableAbility" or "AddGenus" or "RemoveGenus")
- {
-