From c493b1b50b22ded208062e8506f2c8dc4e6f1636 Mon Sep 17 00:00:00 2001 From: dingo Date: Fri, 27 Feb 2026 10:36:02 -0500 Subject: [PATCH] Admin portal: dark mode, account management, chat fixes, ability builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Light/dark mode toggle: Bootstrap 5.3 data-bs-theme, theme persisted to localStorage via admin.js, Moon/Sun icon button in sidebar, flash-free inline + diff --git a/Server/src/SOR.Admin/Components/Layout/NavMenu.razor b/Server/src/SOR.Admin/Components/Layout/NavMenu.razor index df8ffbf..cfc0133 100644 --- a/Server/src/SOR.Admin/Components/Layout/NavMenu.razor +++ b/Server/src/SOR.Admin/Components/Layout/NavMenu.razor @@ -1,3 +1,5 @@ +@inject IJSRuntime Js + + +@code { + private string _theme = "light"; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + _theme = await Js.InvokeAsync("sorAdmin.getTheme"); + StateHasChanged(); + } + } + + private async Task ToggleThemeAsync() + { + _theme = _theme == "light" ? "dark" : "light"; + await Js.InvokeVoidAsync("sorAdmin.setTheme", _theme); + } +} diff --git a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountCreate.razor b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountCreate.razor new file mode 100644 index 0000000..3a0bdd5 --- /dev/null +++ b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountCreate.razor @@ -0,0 +1,130 @@ +@page "/accounts/new" +@attribute [Authorize(Roles = "Admin,SuperAdmin")] +@inject UserManager UserManager +@inject RoleManager> RoleManager +@inject NavigationManager Nav +@using Microsoft.AspNetCore.Identity + +Create Account – SOR Admin + +
+ + Accounts + +

Create Account

+
+ +@if (_message != null) +{ +
@_message
+} + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+ + +
+ + +
+
+
+
+ +
+
+ +@code { + private string _email = ""; + private string _displayName = ""; + private string _password = ""; + private string _confirmPassword = ""; + private bool _assignAdmin = false; + private bool _assignSuperAdmin = false; + private bool _saving; + private string? _message; + private bool _isError; + + private async Task CreateAsync() + { + _message = null; + _isError = false; + + if (string.IsNullOrWhiteSpace(_email)) + { + _message = "Email is required."; + _isError = true; + return; + } + + if (string.IsNullOrWhiteSpace(_password)) + { + _message = "Password is required."; + _isError = true; + return; + } + + if (_password != _confirmPassword) + { + _message = "Passwords do not match."; + _isError = true; + return; + } + + _saving = true; + + var account = new Account + { + UserName = _email, + Email = _email, + DisplayName = string.IsNullOrWhiteSpace(_displayName) ? null : _displayName, + CreatedAt = DateTimeOffset.UtcNow, + }; + + var result = await UserManager.CreateAsync(account, _password); + + if (!result.Succeeded) + { + _message = string.Join(" ", result.Errors.Select(e => e.Description)); + _isError = true; + _saving = false; + return; + } + + if (_assignAdmin) + await UserManager.AddToRoleAsync(account, "Admin"); + + if (_assignSuperAdmin) + await UserManager.AddToRoleAsync(account, "SuperAdmin"); + + Nav.NavigateTo($"/accounts/{account.Id}"); + } +} diff --git a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor index fb62c86..db076d6 100644 --- a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor +++ b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor @@ -3,6 +3,7 @@ @inject SorIdentityDbContext Db @inject UserManager UserManager @inject NavigationManager Nav +@using Microsoft.AspNetCore.Identity Account – SOR Admin @@ -54,17 +55,53 @@ else
Roles
- @if (_roles.Count == 0) - { -

No roles assigned.

- } - else - { - @foreach (var role in _roles) +
+ @if (_roles.Count == 0) { - @role +

No roles assigned.

} - } + else + { +
+ @foreach (var role in _roles) + { + @role + } +
+ } +
+ +
+ @if (_roles.Contains("Admin")) + { + + } + else + { + + } + + + + @if (_roles.Contains("SuperAdmin")) + { + + } + else + { + + } + + +
@@ -128,6 +165,30 @@ else + + +
+
+
Reset Password
+
+
+ + +
+
+ + +
+ +
+ Bypasses current password check. The user must log in with this new password. +
+
+
+
} @@ -136,14 +197,17 @@ else private Account? _account; private List _roles = new(); - private bool _isRestricted; // LockoutEnd is in the future (ban or auto-lockout) - private bool _isBan; // Admin-set ban (LockoutEnd > 1 hour away) - private bool _isLockedOut; // Auto-lockout from failed attempts (≤ 1 hour away) - private int _lockedOutMinutesLeft; - private int _banDays = 30; + private bool _isRestricted; + private bool _isBan; + private bool _isLockedOut; + private int _lockedOutMinutesLeft; + private int _banDays = 30; private string? _message; private bool _isError; + private string _newPassword = ""; + private string _confirmPassword = ""; + protected override async Task OnInitializedAsync() { _account = await UserManager.FindByIdAsync(Id.ToString()); @@ -171,6 +235,53 @@ else } } + private async Task ChangeRoleAsync(string role, bool add) + { + if (_account == null) return; + if (add) + await UserManager.AddToRoleAsync(_account, role); + else + await UserManager.RemoveFromRoleAsync(_account, role); + + _roles = (await UserManager.GetRolesAsync(_account)).ToList(); + _message = add ? $"{role} role added." : $"{role} role removed."; + _isError = false; + } + + private async Task ResetPasswordAsync() + { + if (_account == null) return; + + if (string.IsNullOrWhiteSpace(_newPassword)) + { + _message = "New password cannot be empty."; + _isError = true; + return; + } + + if (_newPassword != _confirmPassword) + { + _message = "Passwords do not match."; + _isError = true; + return; + } + + await UserManager.RemovePasswordAsync(_account); + var result = await UserManager.AddPasswordAsync(_account, _newPassword); + + if (result.Succeeded) + { + _message = "Password reset successfully."; + _isError = false; + _newPassword = _confirmPassword = ""; + } + else + { + _message = string.Join(" ", result.Errors.Select(e => e.Description)); + _isError = true; + } + } + private async Task BanAsync() { if (_account == null) return; diff --git a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountList.razor b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountList.razor index 7873e0a..607d9b7 100644 --- a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountList.razor +++ b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountList.razor @@ -7,6 +7,9 @@
diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor new file mode 100644 index 0000000..c9dd2aa --- /dev/null +++ b/Server/src/SOR.Admin/Components/Pages/Cards/AbilityBuilder.razor @@ -0,0 +1,734 @@ +@* AbilityBuilder.razor — structured UI for AbilityDefinition[] / Action[] JSON *@ + +
+ @if (_abilities.Count == 0) + { +

No abilities defined. Click "Add Ability" to start.

+ } + else + { + @for (int ai = 0; ai < _abilities.Count; ai++) + { + var idx = ai; + var ab = _abilities[idx]; + +
+
+ + @ab.TypeStr + @(string.IsNullOrEmpty(ab.Name) ? "(unnamed)" : ab.Name) + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + @if (ab.TypeStr == "Active") + { +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ } + else if (ab.TypeStr == "Aura") + { +
+
+ + +
+
+ + +
+
+ } + else if (ab.TypeStr == "Triggered") + { +
+ +
+
+ +
+
+ +
+
+
+ } + + +
+ + +
+ + +
+ Actions + (each action = one targeting context + one or more effects) +
+ + @for (int aci = 0; aci < ab.Actions.Count; aci++) + { + var actionIdx = aci; + var action = ab.Actions[actionIdx]; + +
+
+ Action @(actionIdx + 1) + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+ + + + + @for (int ei = 0; ei < action.Effects.Count; ei++) + { + var effectIdx = ei; + var effect = action.Effects[effectIdx]; + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ } + + + + +
+ + +
+
+
+ } + + +
+
+ } + } + + + + +
+
+ + Compiled JSON + + +
+ + @if (_showRaw) + { + +
+ + Parses raw JSON and rebuilds builder state. +
+ } + else + { +
@_compiledJson
+ } +
+
+ +@code { + [Parameter] public string AbilitiesJson { get; set; } = "[]"; + [Parameter] public EventCallback AbilitiesJsonChanged { get; set; } + + private readonly List _abilities = new(); + private string _compiledJson = "[]"; + private string _lastJson = ""; + private bool _showRaw; + + // ── Enum string options ────────────────────────────────────────────────────── + + private static readonly string[] AbilityTypes = + ["Active", "Passive", "Aura", "Triggered"]; + + private static readonly string[] TargetScopes = + ["Hand", "Deck", "Discard", "Battlefield", "Player", "AnyZone"]; + + private static readonly string[] TargetTypes = + ["Unit", "ArchSpirit", "Spirit", "SpiritToken", "Ruin", "Tile", "Card", "Player"]; + + private static readonly string[] TargetOwnerships = + ["Self", "Owner", "Ally", "Enemy", "Any", "Random", "Target"]; + + private static readonly string[] TriggerTypesList = + [ + "OnTurnStart", "OnTurnEnd", + "OnChanneled", "OnAscend", "OnTransition", + "OnUnitMove", "OnUnitAttack", "OnUnitAbilityActivated", "OnUnitMPSpent", + "OnDamageDealt", "OnDamagePrevented", "OnHealed", + "OnUnitEnterBattlefield", "OnUnitLeaveBattlefield", "OnUnitDeath", + "OnUnitSentToDiscard", "OnSpiritSacrificed", "OnTokenSummoned", + "OnStatModified", "OnAbilityAdded", "OnAbilityRemoved", "OnGenusChanged", + "OnRuinActivation", "OnUnitOccupyRuin", "OnTileAffinityChanged", + "OnSPGained", "OnSPSpent", "OnSTGained", "OnSTSpent", + "OnCardDrawn", "OnCardDiscarded", "OnCardReturnedToHand", "OnCardReturnedToDeck", + "OnDeckShuffled", "OnCardsRevealed", + "OnTargetedByAbility", "OnEffectApplied", "OnEnterAuraRange", "OnLeaveAuraRange", + ]; + + // ── Effect groups and templates ────────────────────────────────────────────── + + private sealed record EffectGroup(string Label, string[] Types); + + private static readonly EffectGroup[] EffectGroups = + [ + new("Damage & Healing", ["DealDamage", "Heal", "DealDamageToSelf", "DOT", "HOT"]), + new("Stat Modification", ["ModifyHealth", "ModifyDefense", "ModifyDamage", "ModifyMP", + "GrantAdditionalAttack", "SetAttackRange", "SetMovementType", + "ModifyCost", "SetStatModMultiplier"]), + new("Player Resources", ["ModifySP", "ModifyST", "ModifyCardsDrawnPerTurn", "ModifySPAccumulation"]), + new("Unit Flags", ["SetCanMove", "SetCanAttack", "SetCanDefend", "SetCanBeAttacked", + "SetCanBeBlocked", "SetCanBeObstructed", "SetCanUseAbility", "SetCanBeSacrificed"]), + new("Player Flags", ["SetCanDrawCards", "SetAccumulatesSP", "SetCanChannelSpirit", + "SetCanSacrificeSpirit", "SetCanAscendArchSpirit", "SetCanTransitionArchSpirit", + "SetCanChannelRepentance", "SetCanChannelInstinct", "SetCanChannelRuin", + "SetCanChannelTerramorphaMono", "SetCanChannelTerramorphaDi", "SetCanChannelTerramorphaTri"]), + new("Zone Operations", ["DrawCards", "DiscardCards", "ReturnToHand", "ReturnToDeck", "SendToDiscard", + "ShuffleDeck", "ReturnToBattlefield", "SearchDeck", "RevealCards", + "PlaceOnDeck", "ChannelCard"]), + new("Genus & Affinity", ["AddGenus", "RemoveGenus", "SetAffinity", + "SetBaseAffinity1", "SetBaseAffinity2", "PushAffinity", "PushFinalAffinity"]), + new("Ability Mgmt", ["AddAbility", "RemoveAbility", "EnableAbility", "DisableAbility"]), + new("Displacement", ["PushUnit", "PullUnit", "DisplaceUnit"]), + new("Control", ["TakeControl", "GrantMovementControl", "SetFixedSacrificeReturn"]), + new("Token & Deferred", ["SummonToken", "ApplyOnEvent"]), + ]; + + private static readonly Dictionary EffectTemplates = new() + { + ["DealDamage"] = """{"Amount":{"Fixed":1},"BypassDefense":false}""", + ["Heal"] = """{"Amount":{"Fixed":1}}""", + ["DealDamageToSelf"] = """{"Amount":{"Fixed":1},"BypassDefense":false}""", + ["DOT"] = """{"Amount":{"Fixed":1},"BypassDefense":false,"Duration":{"Type":"UntilEndOfTurn"}}""", + ["HOT"] = """{"Amount":{"Fixed":1},"Duration":{"Type":"UntilEndOfTurn"}}""", + ["ModifyHealth"] = """{"Amount":{"Fixed":1},"StatTarget":"Current"}""", + ["ModifyDefense"] = """{"Amount":{"Fixed":1},"StatTarget":"Current"}""", + ["ModifyDamage"] = """{"Amount":{"Fixed":1}}""", + ["ModifyMP"] = """{"Amount":{"Fixed":1},"StatTarget":"Current"}""", + ["ModifySP"] = """{"Amount":{"Fixed":1}}""", + ["ModifyST"] = """{"Amount":{"Fixed":1}}""", + ["GrantAdditionalAttack"] = """{"N":1}""", + ["SetAttackRange"] = """{"Min":1,"Max":2}""", + ["SetMovementType"] = """{"MovementType":"Walk"}""", + ["ModifyCost"] = """{"Sp":null,"St":null}""", + ["SetStatModMultiplier"] = """{"Stat":"Damage","Multiplier":1.5}""", + ["SetCanMove"] = """{"Value":true}""", + ["SetCanAttack"] = """{"Value":true}""", + ["SetCanDefend"] = """{"Value":true}""", + ["SetCanBeAttacked"] = """{"Value":true}""", + ["SetCanBeBlocked"] = """{"Value":true}""", + ["SetCanBeObstructed"] = """{"Value":true}""", + ["SetCanUseAbility"] = """{"Value":true}""", + ["SetCanBeSacrificed"] = """{"Value":true}""", + ["SetCanDrawCards"] = """{"Value":true}""", + ["SetAccumulatesSP"] = """{"Value":true}""", + ["SetCanChannelSpirit"] = """{"Value":true}""", + ["SetCanSacrificeSpirit"] = """{"Value":true}""", + ["SetCanAscendArchSpirit"] = """{"Value":true}""", + ["SetCanTransitionArchSpirit"] = """{"Value":true}""", + ["SetCanChannelRepentance"] = """{"Value":true}""", + ["SetCanChannelInstinct"] = """{"Value":true}""", + ["SetCanChannelRuin"] = """{"Value":true}""", + ["SetCanChannelTerramorphaMono"] = """{"Value":true}""", + ["SetCanChannelTerramorphaDi"] = """{"Value":true}""", + ["SetCanChannelTerramorphaTri"] = """{"Value":true}""", + ["ModifyCardsDrawnPerTurn"] = """{"Amount":{"Fixed":1}}""", + ["ModifySPAccumulation"] = """{"Amount":{"Fixed":1}}""", + ["DrawCards"] = """{"N":1,"Player":"Owner"}""", + ["DiscardCards"] = """{"N":1,"Player":"Owner"}""", + ["ReturnToHand"] = """{}""", + ["ReturnToDeck"] = """{"Position":"top"}""", + ["SendToDiscard"] = """{}""", + ["ShuffleDeck"] = """{"Player":"Owner"}""", + ["ReturnToBattlefield"] = """{"Controller":"Owner"}""", + ["SearchDeck"] = """{"Count":1}""", + ["RevealCards"] = """{"N":1}""", + ["PlaceOnDeck"] = """{"Position":"top"}""", + ["ChannelCard"] = """{"PayCost":true}""", + ["AddGenus"] = """{"Tag":"Elemental"}""", + ["RemoveGenus"] = """{"Tag":"Elemental"}""", + ["SetAffinity"] = """{"Affinity":{"Fixed":"Aether"}}""", + ["SetBaseAffinity1"] = """{"Affinity":{"Fixed":"Aether"}}""", + ["SetBaseAffinity2"] = """{"Affinity":{"Fixed":"Lake"}}""", + ["PushAffinity"] = """{"Affinity":{"Fixed":"Aether"}}""", + ["PushFinalAffinity"] = """{"Affinity":{"Fixed":"Aether"}}""", + ["AddAbility"] = """{"AbilityDef":{"Type":"Passive","Actions":[]}}""", + ["RemoveAbility"] = """{"AbilityRef":"AbilityName"}""", + ["EnableAbility"] = """{"AbilityRef":"AbilityName"}""", + ["DisableAbility"] = """{"AbilityRef":"AbilityName"}""", + ["PushUnit"] = """{"Tiles":1}""", + ["PullUnit"] = """{"Tiles":1}""", + ["DisplaceUnit"] = """{"Tiles":1,"Direction":"North"}""", + ["TakeControl"] = """{"Duration":{"Type":"UntilEndOfTurn"}}""", + ["GrantMovementControl"] = """{"N":1}""", + ["SetFixedSacrificeReturn"] = """{"StAmount":1}""", + ["SummonToken"] = """{"TokenDefJson":"{}"}""", + ["ApplyOnEvent"] = """{"Trigger":{"$type":"OnTurnStart","Player":"Owner"},"Effects":[]}""", + }; + + private static readonly Dictionary TriggerTemplates = new() + { + ["OnTurnStart"] = """{"$type":"OnTurnStart","Player":"Owner"}""", + ["OnTurnEnd"] = """{"$type":"OnTurnEnd","Player":"Owner"}""", + ["OnChanneled"] = """{"$type":"OnChanneled","CardType":"Spirit","Ownership":"Owner"}""", + ["OnAscend"] = """{"$type":"OnAscend","Ownership":"Owner"}""", + ["OnTransition"] = """{"$type":"OnTransition","Ownership":"Owner"}""", + ["OnUnitMove"] = """{"$type":"OnUnitMove","Ownership":"Owner"}""", + ["OnUnitAttack"] = """{"$type":"OnUnitAttack","Ownership":"Owner"}""", + ["OnUnitAbilityActivated"] = """{"$type":"OnUnitAbilityActivated","Ownership":"Owner"}""", + ["OnUnitMPSpent"] = """{"$type":"OnUnitMPSpent","Ownership":"Owner"}""", + ["OnDamageDealt"] = """{"$type":"OnDamageDealt","SourceOwnership":"Any","TargetOwnership":"Any"}""", + ["OnDamagePrevented"] = """{"$type":"OnDamagePrevented","TargetOwnership":"Any"}""", + ["OnHealed"] = """{"$type":"OnHealed","TargetOwnership":"Any"}""", + ["OnUnitEnterBattlefield"] = """{"$type":"OnUnitEnterBattlefield","UnitType":"Unit","Ownership":"Any"}""", + ["OnUnitLeaveBattlefield"] = """{"$type":"OnUnitLeaveBattlefield","UnitType":"Unit","Ownership":"Any"}""", + ["OnUnitDeath"] = """{"$type":"OnUnitDeath","UnitType":"Unit","Ownership":"Any"}""", + ["OnUnitSentToDiscard"] = """{"$type":"OnUnitSentToDiscard","UnitType":"Unit","Ownership":"Any"}""", + ["OnSpiritSacrificed"] = """{"$type":"OnSpiritSacrificed","Ownership":"Any"}""", + ["OnTokenSummoned"] = """{"$type":"OnTokenSummoned","Ownership":"Owner"}""", + ["OnStatModified"] = """{"$type":"OnStatModified","Ownership":"Any"}""", + ["OnAbilityAdded"] = """{"$type":"OnAbilityAdded","Ownership":"Any"}""", + ["OnAbilityRemoved"] = """{"$type":"OnAbilityRemoved","Ownership":"Any"}""", + ["OnGenusChanged"] = """{"$type":"OnGenusChanged","Ownership":"Any"}""", + ["OnRuinActivation"] = """{"$type":"OnRuinActivation","RuinOwnership":"Any"}""", + ["OnUnitOccupyRuin"] = """{"$type":"OnUnitOccupyRuin","UnitOwnership":"Any"}""", + ["OnTileAffinityChanged"] = """{"$type":"OnTileAffinityChanged"}""", + ["OnSPGained"] = """{"$type":"OnSPGained","Player":"Owner"}""", + ["OnSPSpent"] = """{"$type":"OnSPSpent","Player":"Owner"}""", + ["OnSTGained"] = """{"$type":"OnSTGained","Player":"Owner"}""", + ["OnSTSpent"] = """{"$type":"OnSTSpent","Player":"Owner"}""", + ["OnCardDrawn"] = """{"$type":"OnCardDrawn","Player":"Owner"}""", + ["OnCardDiscarded"] = """{"$type":"OnCardDiscarded","Player":"Owner"}""", + ["OnCardReturnedToHand"] = """{"$type":"OnCardReturnedToHand","Player":"Owner"}""", + ["OnCardReturnedToDeck"] = """{"$type":"OnCardReturnedToDeck","Player":"Owner"}""", + ["OnDeckShuffled"] = """{"$type":"OnDeckShuffled","Player":"Owner"}""", + ["OnCardsRevealed"] = """{"$type":"OnCardsRevealed","Player":"Owner"}""", + ["OnTargetedByAbility"] = """{"$type":"OnTargetedByAbility","TargetOwnership":"Owner","SourceOwnership":"Any"}""", + ["OnEffectApplied"] = """{"$type":"OnEffectApplied","TargetOwnership":"Owner","SourceOwnership":"Any"}""", + ["OnEnterAuraRange"] = """{"$type":"OnEnterAuraRange","AuraOwnership":"Owner","UnitOwnership":"Any"}""", + ["OnLeaveAuraRange"] = """{"$type":"OnLeaveAuraRange","AuraOwnership":"Owner","UnitOwnership":"Any"}""", + }; + + // ── Lifecycle ──────────────────────────────────────────────────────────────── + + protected override void OnParametersSet() + { + if (!string.IsNullOrWhiteSpace(AbilitiesJson) && AbilitiesJson != _lastJson) + { + _lastJson = AbilitiesJson; + ParseJson(AbilitiesJson); + } + } + + // ── Parse ──────────────────────────────────────────────────────────────────── + + private void ParseJson(string json) + { + try + { + _abilities.Clear(); + var arr = JsonNode.Parse(json) as JsonArray ?? new JsonArray(); + + foreach (var node in arr.OfType()) + { + var ab = new AbilityDraft + { + TypeStr = node["Type"]?.GetValue() ?? "Active", + Name = node["Name"]?.GetValue() ?? "", + Description = node["Description"]?.GetValue() ?? "", + UsesPerTurn = node["UsesPerTurn"]?.GetValue() ?? 1, + RangeMin = node["Range"]?["Min"]?.GetValue(), + RangeMax = node["Range"]?["Max"]?.GetValue(), + AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue(), + AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue(), + CostJson = node["Cost"] is JsonNode cost ? cost.ToJsonString() : "", + ConditionsJson = node["ActivationConditions"] is JsonNode cond + ? cond.ToJsonString() : "", + }; + + if (node["TriggerEvent"] is JsonNode trig) + { + ab.TriggerJson = trig.ToJsonString(); + ab.TriggerType = trig["$type"]?.GetValue() ?? ""; + } + + if (node["Actions"] is JsonArray actions) + { + foreach (var actionNode in actions.OfType()) + { + var target = actionNode["Target"] as JsonObject; + var act = new ActionDraft + { + Scope = target?["Scope"]?.GetValue() ?? "Battlefield", + TargetType = target?["Type"]?.GetValue() ?? "Unit", + Ownership = target?["Ownership"]?.GetValue() ?? "Enemy", + Count = target?["Count"]?["N"]?.GetValue() ?? 1, + All = target?["Count"]?["All"]?.GetValue() ?? false, + ConditionsJson = actionNode["Conditions"] is JsonNode ac ? ac.ToJsonString() : "", + }; + + if (actionNode["Effects"] is JsonArray effects) + { + foreach (var eff in effects.OfType()) + { + var typeKey = eff["$type"]?.GetValue() ?? ""; + var fields = new JsonObject(); + foreach (var prop in eff) + if (prop.Key != "$type") + fields[prop.Key] = prop.Value?.DeepClone(); + + act.Effects.Add(new EffectDraft + { + TypeKey = typeKey, + FieldsJson = fields.ToJsonString(), + }); + } + } + + ab.Actions.Add(act); + } + } + + _abilities.Add(ab); + } + + _compiledJson = json; + } + catch + { + // Invalid JSON — keep existing state. + } + } + + // ── Compile ────────────────────────────────────────────────────────────────── + + private void Compile() + { + try + { + var arr = new JsonArray(); + + foreach (var ab in _abilities) + { + var node = new JsonObject + { + ["Type"] = ab.TypeStr, + ["Name"] = ab.Name, + ["Description"] = ab.Description, + }; + + if (ab.TypeStr == "Active") + { + if (ab.RangeMin.HasValue || ab.RangeMax.HasValue) + node["Range"] = new JsonObject + { + ["Min"] = ab.RangeMin ?? 1, + ["Max"] = ab.RangeMax ?? 1, + }; + node["UsesPerTurn"] = ab.UsesPerTurn; + if (!string.IsNullOrWhiteSpace(ab.CostJson)) + try { node["Cost"] = JsonNode.Parse(ab.CostJson); } catch { } + } + else if (ab.TypeStr == "Aura") + { + if (ab.AuraRangeMin.HasValue || ab.AuraRangeMax.HasValue) + node["AuraRange"] = new JsonObject + { + ["Min"] = ab.AuraRangeMin ?? 1, + ["Max"] = ab.AuraRangeMax ?? 1, + }; + } + else if (ab.TypeStr == "Triggered" && !string.IsNullOrWhiteSpace(ab.TriggerJson)) + { + try { node["TriggerEvent"] = JsonNode.Parse(ab.TriggerJson); } catch { } + } + + if (!string.IsNullOrWhiteSpace(ab.ConditionsJson)) + try { node["ActivationConditions"] = JsonNode.Parse(ab.ConditionsJson); } catch { } + + var actionsArr = new JsonArray(); + foreach (var action in ab.Actions) + { + var actionNode = new JsonObject + { + ["Target"] = new JsonObject + { + ["Scope"] = action.Scope, + ["Type"] = action.TargetType, + ["Ownership"] = action.Ownership, + ["Count"] = new JsonObject + { + ["N"] = action.All ? 1 : action.Count, + ["UpTo"] = false, + ["All"] = action.All, + }, + }, + }; + + if (!string.IsNullOrWhiteSpace(action.ConditionsJson)) + try { actionNode["Conditions"] = JsonNode.Parse(action.ConditionsJson); } catch { } + + var effectsArr = new JsonArray(); + foreach (var eff in action.Effects) + { + try + { + var effNode = new JsonObject { ["$type"] = eff.TypeKey }; + if (!string.IsNullOrWhiteSpace(eff.FieldsJson)) + { + var fields = JsonNode.Parse(eff.FieldsJson)?.AsObject(); + if (fields != null) + foreach (var prop in fields) + effNode[prop.Key] = prop.Value?.DeepClone(); + } + effectsArr.Add(effNode); + } + catch + { + effectsArr.Add(new JsonObject { ["$type"] = eff.TypeKey }); + } + } + actionNode["Effects"] = effectsArr; + actionsArr.Add(actionNode); + } + + node["Actions"] = actionsArr; + arr.Add(node); + } + + _compiledJson = arr.ToJsonString(new JsonSerializerOptions { WriteIndented = true }); + _ = AbilitiesJsonChanged.InvokeAsync(_compiledJson); + } + catch { /* keep last valid */ } + } + + // ── Event helpers (extracted from Razor to avoid raw-string / brace parse errors) ── + + private void SelectTrigger(AbilityDraft ab, string triggerType) + { + ab.TriggerType = triggerType; + if (!string.IsNullOrEmpty(triggerType)) + ab.TriggerJson = TriggerTemplates.GetValueOrDefault( + triggerType, "{\"$type\":\"" + triggerType + "\"}"); + Compile(); + } + + private void SelectEffectType(EffectDraft effect, string typeKey) + { + effect.TypeKey = typeKey; + effect.FieldsJson = EffectTemplates.GetValueOrDefault(typeKey, "{}"); + Compile(); + } + + // ── Actions ────────────────────────────────────────────────────────────────── + + private void AddAbility() + { + _abilities.Add(new AbilityDraft()); + Compile(); + } + + private void ApplyRawJson() + { + ParseJson(_compiledJson); + _showRaw = false; + _ = AbilitiesJsonChanged.InvokeAsync(_compiledJson); + } + + private static string AbilityTypeBadge(string t) => t switch + { + "Active" => "bg-primary", + "Passive" => "bg-success", + "Aura" => "bg-info text-dark", + "Triggered" => "bg-warning text-dark", + _ => "bg-secondary", + }; + + // ── Draft models ───────────────────────────────────────────────────────────── + + private sealed class AbilityDraft + { + public string TypeStr { get; set; } = "Active"; + public string Name { get; set; } = ""; + public string Description { get; set; } = ""; + public int? RangeMin { get; set; } + public int? RangeMax { get; set; } + public int UsesPerTurn { get; set; } = 1; + public string CostJson { get; set; } = ""; + public int? AuraRangeMin { get; set; } + public int? AuraRangeMax { get; set; } + public string TriggerType { get; set; } = ""; + public string TriggerJson { get; set; } = ""; + public string ConditionsJson { get; set; } = ""; + public List Actions { get; set; } = new(); + } + + 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 string ConditionsJson { get; set; } = ""; + public List Effects { get; set; } = new(); + } + + private sealed class EffectDraft + { + public string TypeKey { get; set; } = "DealDamage"; + public string FieldsJson { get; set; } = """{"Amount":{"Fixed":1},"BypassDefense":false}"""; + } +} diff --git a/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor b/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor index 5103fd6..359e04c 100644 --- a/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor +++ b/Server/src/SOR.Admin/Components/Pages/Cards/CardEditor.razor @@ -231,19 +231,20 @@ else else if (_activeTab == "Abilities") { -
- @if (_card.CardType is CardType.Repentance or CardType.Instinct or CardType.Terramorpha) - { - Effects JSON (Action[] array) — see abilities.md for schema. - } - else - { - Abilities JSON (AbilityDefinition[] array) — see abilities.md for schema. - } +
+ + @if (_card.CardType is CardType.Repentance or CardType.Instinct or CardType.Terramorpha) + { + Effects (Action[] array) for @_card.CardType cards. + } + else + { + Abilities (AbilityDefinition[] array) for @_card.CardType cards. + } +
- + } diff --git a/Server/src/SOR.Admin/Components/Pages/Chat/ChatChannelViewer.razor b/Server/src/SOR.Admin/Components/Pages/Chat/ChatChannelViewer.razor index b3e4fc1..259a61e 100644 --- a/Server/src/SOR.Admin/Components/Pages/Chat/ChatChannelViewer.razor +++ b/Server/src/SOR.Admin/Components/Pages/Chat/ChatChannelViewer.razor @@ -40,7 +40,7 @@ else @if (_channel.ChannelType != SOR.Database.Enums.ChatChannelType.Match) {
-
+
Post System Message
@@ -65,9 +65,9 @@ else
-
+
Messages (newest first) - @_messages.Count shown + @_messages.Count shown
diff --git a/Server/src/SOR.Admin/Components/Pages/Chat/ChatOverview.razor b/Server/src/SOR.Admin/Components/Pages/Chat/ChatOverview.razor index a1621e1..b268a02 100644 --- a/Server/src/SOR.Admin/Components/Pages/Chat/ChatOverview.razor +++ b/Server/src/SOR.Admin/Components/Pages/Chat/ChatOverview.razor @@ -21,7 +21,7 @@ else
-
Total Channels
+
Total Channels
@_totalChannels
@@ -29,7 +29,7 @@ else
-
Total Messages
+
Total Messages
@_totalMessages
@@ -37,7 +37,7 @@ else
-
Friendships
+
Friendships
@_friendships
@@ -45,7 +45,7 @@ else
-
Blocked Pairs
+
Blocked Pairs
@_blockedPairs
@@ -54,7 +54,7 @@ else
-
+
Channels
} diff --git a/Server/src/SOR.Admin/Components/_Imports.razor b/Server/src/SOR.Admin/Components/_Imports.razor index 2e45fd0..8878178 100644 --- a/Server/src/SOR.Admin/Components/_Imports.razor +++ b/Server/src/SOR.Admin/Components/_Imports.razor @@ -1,5 +1,8 @@ @using System.Net.Http @using System.Net.Http.Json +@using System.Text.Json +@using System.Text.Json.Nodes +@using Microsoft.JSInterop @using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Components.Authorization diff --git a/Server/src/SOR.Admin/wwwroot/admin.js b/Server/src/SOR.Admin/wwwroot/admin.js new file mode 100644 index 0000000..15f4c16 --- /dev/null +++ b/Server/src/SOR.Admin/wwwroot/admin.js @@ -0,0 +1,9 @@ +window.sorAdmin = { + getTheme: function () { + return localStorage.getItem('sor-admin-theme') || 'light'; + }, + setTheme: function (theme) { + localStorage.setItem('sor-admin-theme', theme); + document.documentElement.setAttribute('data-bs-theme', theme); + } +}; diff --git a/Server/src/SOR.Admin/wwwroot/app.css b/Server/src/SOR.Admin/wwwroot/app.css index d985075..15f1567 100644 --- a/Server/src/SOR.Admin/wwwroot/app.css +++ b/Server/src/SOR.Admin/wwwroot/app.css @@ -21,7 +21,7 @@ html, body { .sor-admin-content { flex: 1; overflow-y: auto; - background: #f8f9fa; + background: var(--bs-body-bg); } /* Active nav link highlight */ diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 1ab1783..720362c 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -20,6 +20,7 @@ public static class AbilitySystem private static readonly JsonSerializerOptions _jsonOpts = new() { PropertyNameCaseInsensitive = true, + Converters = { new System.Text.Json.Serialization.JsonStringEnumConverter() }, }; // ── Parsing ──────────────────────────────────────────────────────────────── diff --git a/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs b/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs index f7b06b7..b4283e9 100644 --- a/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs +++ b/Server/src/SOR.Game/Abilities/Models/AbilityDefinition.cs @@ -44,4 +44,10 @@ public sealed class AbilityDefinition /// Not required for game logic. /// public string? Name { get; set; } + + /// + /// Plain-English description of what this ability does. + /// Used in the admin ability builder. Not used by game logic. + /// + public string? Description { get; set; } }
@ch.MessageCount @ch.CreatedAt.ToString("yyyy-MM-dd HH:mm") - View + + View & Post +