Admin portal: dark mode, account management, chat fixes, ability builder
• 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 <script> in App.razor applies saved theme before first render.
• Account management: Add "Create Account" button + new /accounts/new page
(email, display name, password, role checkboxes). AccountDetail now has
interactive role assignment (Add/Remove Admin/SuperAdmin — SuperAdmin
actions gated with <AuthorizeView Roles="SuperAdmin">) and a force-reset
password section (RemovePasswordAsync + AddPasswordAsync, no current
password required).
• Chat fixes: stat card labels changed from text-muted → text-white-50 for
readability on bg-dark; card-headers now have border-bottom border-secondary
to visually separate from card bodies; "View" button relabeled "View & Post"
to surface the hidden compose feature.
• Ability builder (AbilityBuilder.razor): structured UI replacing the raw
textarea in CardEditor. Supports all 4 ability types (Active/Passive/Aura/
Triggered) with type-specific fields (range, uses/turn, aura range, trigger
dropdown). Each ability holds structured actions (scope/type/ownership/count
dropdowns) and effects (59 types in 11 grouped optgroups; each auto-populates
a JSON fields template on type selection). Description field stores plain-
English text in the JSON. Raw JSON toggle + Apply for power users. Live
compiled JSON preview.
• AbilitySystem: added JsonStringEnumConverter so JSONB enums serialize as
human-readable strings ("Active" vs 0, "Battlefield" vs 3, etc.).
• AbilityDefinition: added optional Description property (admin-only metadata).
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:
@@ -4,6 +4,8 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<base href="/" />
|
||||
<!-- Apply saved theme immediately to avoid flash of wrong theme. -->
|
||||
<script>(function(){var t=localStorage.getItem('sor-admin-theme')||'light';document.documentElement.setAttribute('data-bs-theme',t);})();</script>
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
|
||||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
|
||||
@@ -16,5 +18,6 @@
|
||||
<body>
|
||||
<Routes @rendermode="InteractiveServer" />
|
||||
<script src="_framework/blazor.web.js"></script>
|
||||
<script src="admin.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@inject IJSRuntime Js
|
||||
|
||||
<nav class="sor-admin-sidebar d-flex flex-column bg-dark text-white p-3">
|
||||
<a class="navbar-brand text-white fw-bold fs-5 mb-4 text-decoration-none" href="/">
|
||||
<i class="bi bi-lightning-charge-fill text-warning me-2"></i>SOR Admin
|
||||
@@ -108,6 +110,18 @@
|
||||
</ul>
|
||||
|
||||
<div class="mt-auto pt-3 border-top border-secondary">
|
||||
<!-- Theme toggle -->
|
||||
<button class="btn btn-sm btn-outline-secondary w-100 mb-2" @onclick="ToggleThemeAsync">
|
||||
@if (_theme == "dark")
|
||||
{
|
||||
<i class="bi bi-sun me-1"></i><span>Light Mode</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="bi bi-moon me-1"></i><span>Dark Mode</span>
|
||||
}
|
||||
</button>
|
||||
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="text-muted small mb-2">
|
||||
@@ -122,3 +136,22 @@
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@code {
|
||||
private string _theme = "light";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
_theme = await Js.InvokeAsync<string>("sorAdmin.getTheme");
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ToggleThemeAsync()
|
||||
{
|
||||
_theme = _theme == "light" ? "dark" : "light";
|
||||
await Js.InvokeVoidAsync("sorAdmin.setTheme", _theme);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
@page "/accounts/new"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject UserManager<Account> UserManager
|
||||
@inject RoleManager<IdentityRole<Guid>> RoleManager
|
||||
@inject NavigationManager Nav
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
<PageTitle>Create Account – SOR Admin</PageTitle>
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/accounts" class="text-muted text-decoration-none small">
|
||||
<i class="bi bi-arrow-left me-1"></i>Accounts
|
||||
</a>
|
||||
<h1 class="mt-1 mb-0">Create Account</h1>
|
||||
</div>
|
||||
|
||||
@if (_message != null)
|
||||
{
|
||||
<div class="alert @(_isError ? "alert-danger" : "alert-success")">@_message</div>
|
||||
}
|
||||
|
||||
<div class="card shadow-sm" style="max-width:520px">
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Email <span class="text-danger">*</span></label>
|
||||
<input @bind="_email" type="email" class="form-control" placeholder="user@example.com" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Display Name</label>
|
||||
<input @bind="_displayName" class="form-control" placeholder="Optional" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Password <span class="text-danger">*</span></label>
|
||||
<input @bind="_password" type="password" class="form-control"
|
||||
placeholder="12+ chars, uppercase, digit, symbol" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Confirm Password <span class="text-danger">*</span></label>
|
||||
<input @bind="_confirmPassword" type="password" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Roles</label>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="roleAdmin"
|
||||
@bind="_assignAdmin" />
|
||||
<label class="form-check-label" for="roleAdmin">Admin</label>
|
||||
</div>
|
||||
<AuthorizeView Roles="SuperAdmin">
|
||||
<Authorized>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="roleSuperAdmin"
|
||||
@bind="_assignSuperAdmin" />
|
||||
<label class="form-check-label" for="roleSuperAdmin">SuperAdmin</label>
|
||||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
<button class="btn btn-primary" @onclick="CreateAsync" disabled="@_saving">
|
||||
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||
<i class="bi bi-person-check me-1"></i>Create Account
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@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}");
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
@inject SorIdentityDbContext Db
|
||||
@inject UserManager<Account> UserManager
|
||||
@inject NavigationManager Nav
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
|
||||
<PageTitle>Account – SOR Admin</PageTitle>
|
||||
|
||||
@@ -54,17 +55,53 @@ else
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Roles</div>
|
||||
<div class="card-body">
|
||||
@if (_roles.Count == 0)
|
||||
{
|
||||
<p class="text-muted small">No roles assigned.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var role in _roles)
|
||||
<div class="mb-3">
|
||||
@if (_roles.Count == 0)
|
||||
{
|
||||
<span class="badge bg-primary me-1 mb-1">@role</span>
|
||||
<p class="text-muted small mb-2">No roles assigned.</p>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="mb-2">
|
||||
@foreach (var role in _roles)
|
||||
{
|
||||
<span class="badge bg-primary me-1 mb-1">@role</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
@if (_roles.Contains("Admin"))
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick='() => ChangeRoleAsync("Admin", false)'>
|
||||
<i class="bi bi-dash-circle me-1"></i>Remove Admin
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-primary" @onclick='() => ChangeRoleAsync("Admin", true)'>
|
||||
<i class="bi bi-plus-circle me-1"></i>Add Admin
|
||||
</button>
|
||||
}
|
||||
|
||||
<AuthorizeView Roles="SuperAdmin">
|
||||
<Authorized>
|
||||
@if (_roles.Contains("SuperAdmin"))
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick='() => ChangeRoleAsync("SuperAdmin", false)'>
|
||||
<i class="bi bi-dash-circle me-1"></i>Remove SuperAdmin
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-warning" @onclick='() => ChangeRoleAsync("SuperAdmin", true)'>
|
||||
<i class="bi bi-plus-circle me-1"></i>Add SuperAdmin
|
||||
</button>
|
||||
}
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -128,6 +165,30 @@ else
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Password Reset -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Reset Password</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-2">
|
||||
<label class="form-label small">New Password</label>
|
||||
<input @bind="_newPassword" type="password" class="form-control form-control-sm"
|
||||
placeholder="12+ chars, uppercase, digit, symbol" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small">Confirm Password</label>
|
||||
<input @bind="_confirmPassword" type="password" class="form-control form-control-sm" />
|
||||
</div>
|
||||
<button class="btn btn-sm btn-warning" @onclick="ResetPasswordAsync">
|
||||
<i class="bi bi-key me-1"></i>Force Reset Password
|
||||
</button>
|
||||
<div class="form-text mt-1">
|
||||
Bypasses current password check. The user must log in with this new password.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -136,14 +197,17 @@ else
|
||||
|
||||
private Account? _account;
|
||||
private List<string> _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;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="mb-0">Accounts</h1>
|
||||
<a href="/accounts/new" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-person-plus me-1"></i>Create Account
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-3">
|
||||
|
||||
@@ -0,0 +1,734 @@
|
||||
@* AbilityBuilder.razor — structured UI for AbilityDefinition[] / Action[] JSON *@
|
||||
|
||||
<div class="ability-builder">
|
||||
@if (_abilities.Count == 0)
|
||||
{
|
||||
<p class="text-muted fst-italic">No abilities defined. Click "Add Ability" to start.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
@for (int ai = 0; ai < _abilities.Count; ai++)
|
||||
{
|
||||
var idx = ai;
|
||||
var ab = _abilities[idx];
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<span class="fw-semibold">
|
||||
<span class="badge @AbilityTypeBadge(ab.TypeStr) me-2">@ab.TypeStr</span>
|
||||
@(string.IsNullOrEmpty(ab.Name) ? "(unnamed)" : ab.Name)
|
||||
</span>
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
@onclick="() => { _abilities.RemoveAt(idx); Compile(); }">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<!-- Core fields -->
|
||||
<div class="row g-2 mb-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small">Type</label>
|
||||
<select class="form-select form-select-sm" @bind="ab.TypeStr" @bind:after="Compile">
|
||||
@foreach (var t in AbilityTypes)
|
||||
{ <option value="@t">@t</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label small">Name <span class="text-muted">(optional)</span></label>
|
||||
<input class="form-control form-control-sm" @bind="ab.Name" @bind:after="Compile"
|
||||
placeholder="Display name" />
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<label class="form-label small">
|
||||
Description <small class="text-muted">(plain English — what it does)</small>
|
||||
</label>
|
||||
<input class="form-control form-control-sm" @bind="ab.Description" @bind:after="Compile"
|
||||
placeholder="e.g. Deal 3 damage to target enemy unit." />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Type-specific fields -->
|
||||
@if (ab.TypeStr == "Active")
|
||||
{
|
||||
<div class="row g-2 mb-3">
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small">Range Min</label>
|
||||
<input type="number" class="form-control form-control-sm"
|
||||
@bind="ab.RangeMin" @bind:after="Compile" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small">Range Max</label>
|
||||
<input type="number" class="form-control form-control-sm"
|
||||
@bind="ab.RangeMax" @bind:after="Compile" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small">Uses / Turn</label>
|
||||
<input type="number" min="1" class="form-control form-control-sm"
|
||||
@bind="ab.UsesPerTurn" @bind:after="Compile" />
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label small">Cost JSON <small class="text-muted">(CostEntry[] array)</small></label>
|
||||
<input class="form-control form-control-sm font-monospace" @bind="ab.CostJson" @bind:after="Compile"
|
||||
placeholder='e.g. [{"Type":"SpiritPoints","Amount":2}]' />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else if (ab.TypeStr == "Aura")
|
||||
{
|
||||
<div class="row g-2 mb-3">
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small">Aura Range Min</label>
|
||||
<input type="number" class="form-control form-control-sm"
|
||||
@bind="ab.AuraRangeMin" @bind:after="Compile" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small">Aura Range Max</label>
|
||||
<input type="number" class="form-control form-control-sm"
|
||||
@bind="ab.AuraRangeMax" @bind:after="Compile" />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else if (ab.TypeStr == "Triggered")
|
||||
{
|
||||
<div class="mb-3">
|
||||
<label class="form-label small">Trigger Event</label>
|
||||
<div class="row g-2">
|
||||
<div class="col-md-3">
|
||||
<select class="form-select form-select-sm"
|
||||
value="@ab.TriggerType"
|
||||
@onchange="e => SelectTrigger(ab, (string)e.Value!)">
|
||||
<option value="">— select trigger —</option>
|
||||
@foreach (var t in TriggerTypesList)
|
||||
{ <option value="@t">@t</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<textarea class="form-control form-control-sm font-monospace" rows="2"
|
||||
@bind="ab.TriggerJson" @bind:after="Compile"
|
||||
placeholder='{"$type":"OnTurnStart","Player":"Owner"}'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Activation conditions (all types) -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label small">
|
||||
Activation Conditions JSON <small class="text-muted">(Condition[] array, optional)</small>
|
||||
</label>
|
||||
<textarea class="form-control form-control-sm font-monospace" rows="2"
|
||||
@bind="ab.ConditionsJson" @bind:after="Compile"
|
||||
placeholder='e.g. [{"$type":"IsOwnTurn"}]'></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<h6 class="text-muted small mb-2">
|
||||
Actions
|
||||
<small class="ms-1 fw-normal">(each action = one targeting context + one or more effects)</small>
|
||||
</h6>
|
||||
|
||||
@for (int aci = 0; aci < ab.Actions.Count; aci++)
|
||||
{
|
||||
var actionIdx = aci;
|
||||
var action = ab.Actions[actionIdx];
|
||||
|
||||
<div class="card border-secondary mb-2">
|
||||
<div class="card-header d-flex justify-content-between align-items-center py-1 border-bottom border-secondary">
|
||||
<span class="small fw-medium">Action @(actionIdx + 1)</span>
|
||||
<button class="btn btn-sm btn-outline-danger py-0"
|
||||
@onclick="() => { ab.Actions.RemoveAt(actionIdx); Compile(); }">
|
||||
<i class="bi bi-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="card-body py-2">
|
||||
<!-- Target selector -->
|
||||
<div class="row g-2 mb-2 align-items-end">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small mb-0">Scope</label>
|
||||
<select class="form-select form-select-sm" @bind="action.Scope" @bind:after="Compile">
|
||||
@foreach (var s in TargetScopes) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small mb-0">Target Type</label>
|
||||
<select class="form-select form-select-sm" @bind="action.TargetType" @bind:after="Compile">
|
||||
@foreach (var t in TargetTypes) { <option value="@t">@t</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small mb-0">Ownership</label>
|
||||
<select class="form-select form-select-sm" @bind="action.Ownership" @bind:after="Compile">
|
||||
@foreach (var o in TargetOwnerships) { <option value="@o">@o</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small mb-0">Count N</label>
|
||||
<input type="number" min="1" class="form-control form-control-sm"
|
||||
@bind="action.Count" @bind:after="Compile" />
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
id="all_@(ai)_@(actionIdx)"
|
||||
@bind="action.All" @bind:after="Compile" />
|
||||
<label class="form-check-label small" for="all_@(ai)_@(actionIdx)">All</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Effects -->
|
||||
<label class="form-label small fw-medium mb-1">Effects</label>
|
||||
|
||||
@for (int ei = 0; ei < action.Effects.Count; ei++)
|
||||
{
|
||||
var effectIdx = ei;
|
||||
var effect = action.Effects[effectIdx];
|
||||
|
||||
<div class="border rounded p-2 mb-2">
|
||||
<div class="row g-1 align-items-start">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small mb-0">Effect Type</label>
|
||||
<select class="form-select form-select-sm"
|
||||
value="@effect.TypeKey"
|
||||
@onchange="e => SelectEffectType(effect, (string)e.Value!)">
|
||||
@foreach (var grp in EffectGroups)
|
||||
{
|
||||
<optgroup label="@grp.Label">
|
||||
@foreach (var et in grp.Types)
|
||||
{ <option value="@et">@et</option> }
|
||||
</optgroup>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<label class="form-label small mb-0">
|
||||
Fields JSON <small class="text-muted">(omit $type)</small>
|
||||
</label>
|
||||
<textarea class="form-control form-control-sm font-monospace"
|
||||
rows="3"
|
||||
@bind="effect.FieldsJson"
|
||||
@bind:after="Compile"></textarea>
|
||||
</div>
|
||||
<div class="col-md-1 text-end">
|
||||
<label class="form-label small mb-0 invisible">x</label>
|
||||
<button class="btn btn-sm btn-outline-danger d-block"
|
||||
@onclick="() => { action.Effects.RemoveAt(effectIdx); Compile(); }">
|
||||
<i class="bi bi-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<button class="btn btn-sm btn-outline-success"
|
||||
@onclick="() => { action.Effects.Add(new EffectDraft()); Compile(); }">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Effect
|
||||
</button>
|
||||
|
||||
<!-- Action-level conditions -->
|
||||
<div class="mt-2">
|
||||
<label class="form-label small mb-0">
|
||||
Action Conditions JSON <small class="text-muted">(Condition[] array, optional)</small>
|
||||
</label>
|
||||
<textarea class="form-control form-control-sm font-monospace" rows="2"
|
||||
@bind="action.ConditionsJson" @bind:after="Compile"
|
||||
placeholder='e.g. [{"$type":"IsOwnTurn"}]'></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<button class="btn btn-sm btn-outline-secondary mt-1"
|
||||
@onclick="() => { ab.Actions.Add(new ActionDraft()); Compile(); }">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Action
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<button class="btn btn-outline-primary btn-sm mb-4" @onclick="AddAbility">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Ability
|
||||
</button>
|
||||
|
||||
<!-- JSON output / raw edit -->
|
||||
<div class="border rounded p-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span class="small fw-semibold text-muted">
|
||||
<i class="bi bi-code-slash me-1"></i>Compiled JSON
|
||||
</span>
|
||||
<button class="btn btn-sm btn-outline-secondary" @onclick="() => _showRaw = !_showRaw">
|
||||
@(_showRaw ? "Close Raw Editor" : "Edit Raw JSON")
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (_showRaw)
|
||||
{
|
||||
<textarea class="form-control font-monospace mb-2" rows="15" @bind="_compiledJson"></textarea>
|
||||
<div class="d-flex gap-2 align-items-center">
|
||||
<button class="btn btn-sm btn-primary" @onclick="ApplyRawJson">Apply</button>
|
||||
<span class="text-muted small">Parses raw JSON and rebuilds builder state.</span>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<pre class="small font-monospace mb-0 p-2 bg-light bg-opacity-10 rounded"
|
||||
style="max-height:200px;overflow-y:auto">@_compiledJson</pre>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter] public string AbilitiesJson { get; set; } = "[]";
|
||||
[Parameter] public EventCallback<string> AbilitiesJsonChanged { get; set; }
|
||||
|
||||
private readonly List<AbilityDraft> _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<string, string> 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<string, string> 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<JsonObject>())
|
||||
{
|
||||
var ab = new AbilityDraft
|
||||
{
|
||||
TypeStr = node["Type"]?.GetValue<string>() ?? "Active",
|
||||
Name = node["Name"]?.GetValue<string>() ?? "",
|
||||
Description = node["Description"]?.GetValue<string>() ?? "",
|
||||
UsesPerTurn = node["UsesPerTurn"]?.GetValue<int>() ?? 1,
|
||||
RangeMin = node["Range"]?["Min"]?.GetValue<int>(),
|
||||
RangeMax = node["Range"]?["Max"]?.GetValue<int>(),
|
||||
AuraRangeMin = node["AuraRange"]?["Min"]?.GetValue<int>(),
|
||||
AuraRangeMax = node["AuraRange"]?["Max"]?.GetValue<int>(),
|
||||
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<string>() ?? "";
|
||||
}
|
||||
|
||||
if (node["Actions"] is JsonArray actions)
|
||||
{
|
||||
foreach (var actionNode in actions.OfType<JsonObject>())
|
||||
{
|
||||
var target = actionNode["Target"] as JsonObject;
|
||||
var act = new ActionDraft
|
||||
{
|
||||
Scope = target?["Scope"]?.GetValue<string>() ?? "Battlefield",
|
||||
TargetType = target?["Type"]?.GetValue<string>() ?? "Unit",
|
||||
Ownership = target?["Ownership"]?.GetValue<string>() ?? "Enemy",
|
||||
Count = target?["Count"]?["N"]?.GetValue<int>() ?? 1,
|
||||
All = target?["Count"]?["All"]?.GetValue<bool>() ?? false,
|
||||
ConditionsJson = actionNode["Conditions"] is JsonNode ac ? ac.ToJsonString() : "",
|
||||
};
|
||||
|
||||
if (actionNode["Effects"] is JsonArray effects)
|
||||
{
|
||||
foreach (var eff in effects.OfType<JsonObject>())
|
||||
{
|
||||
var typeKey = eff["$type"]?.GetValue<string>() ?? "";
|
||||
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<ActionDraft> 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<EffectDraft> Effects { get; set; } = new();
|
||||
}
|
||||
|
||||
private sealed class EffectDraft
|
||||
{
|
||||
public string TypeKey { get; set; } = "DealDamage";
|
||||
public string FieldsJson { get; set; } = """{"Amount":{"Fixed":1},"BypassDefense":false}""";
|
||||
}
|
||||
}
|
||||
@@ -231,19 +231,20 @@ else
|
||||
<!-- ── Abilities / Effects ────────────────────────────────────────────── -->
|
||||
else if (_activeTab == "Abilities")
|
||||
{
|
||||
<div class="mb-2 text-muted small">
|
||||
@if (_card.CardType is CardType.Repentance or CardType.Instinct or CardType.Terramorpha)
|
||||
{
|
||||
<span>Effects JSON (Action[] array) — see <code>abilities.md</code> for schema.</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Abilities JSON (AbilityDefinition[] array) — see <code>abilities.md</code> for schema.</span>
|
||||
}
|
||||
<div class="mb-3 d-flex align-items-center gap-3">
|
||||
<span class="text-muted small">
|
||||
@if (_card.CardType is CardType.Repentance or CardType.Instinct or CardType.Terramorpha)
|
||||
{
|
||||
<span>Effects (Action[] array) for @_card.CardType cards.</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Abilities (AbilityDefinition[] array) for @_card.CardType cards.</span>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
<textarea @bind="_abilitiesJson" class="form-control font-monospace"
|
||||
rows="20" spellcheck="false"
|
||||
placeholder="[ { "type": "Active", ... } ]"></textarea>
|
||||
<AbilityBuilder AbilitiesJson="@_abilitiesJson"
|
||||
AbilitiesJsonChanged="@(json => _abilitiesJson = json)" />
|
||||
}
|
||||
|
||||
<!-- ── Assets ─────────────────────────────────────────────────────────── -->
|
||||
|
||||
@@ -40,7 +40,7 @@ else
|
||||
@if (_channel.ChannelType != SOR.Database.Enums.ChatChannelType.Match)
|
||||
{
|
||||
<div class="card bg-dark text-white border-secondary mb-4">
|
||||
<div class="card-header fw-semibold text-danger">
|
||||
<div class="card-header fw-semibold text-danger border-bottom border-secondary">
|
||||
<i class="bi bi-megaphone me-1"></i>Post System Message
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@@ -65,9 +65,9 @@ else
|
||||
|
||||
<!-- Message history -->
|
||||
<div class="card bg-dark text-white border-secondary">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<div class="card-header d-flex justify-content-between align-items-center border-bottom border-secondary">
|
||||
<span class="fw-semibold">Messages (newest first)</span>
|
||||
<span class="text-muted small">@_messages.Count shown</span>
|
||||
<span class="text-white-50 small">@_messages.Count shown</span>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-dark table-hover mb-0 small">
|
||||
|
||||
@@ -21,7 +21,7 @@ else
|
||||
<div class="col-md-3">
|
||||
<div class="card bg-dark text-white border-secondary h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small">Total Channels</div>
|
||||
<div class="text-white-50 small">Total Channels</div>
|
||||
<div class="fs-3 fw-bold">@_totalChannels</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,7 +29,7 @@ else
|
||||
<div class="col-md-3">
|
||||
<div class="card bg-dark text-white border-secondary h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small">Total Messages</div>
|
||||
<div class="text-white-50 small">Total Messages</div>
|
||||
<div class="fs-3 fw-bold">@_totalMessages</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -37,7 +37,7 @@ else
|
||||
<div class="col-md-3">
|
||||
<div class="card bg-dark text-white border-secondary h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small">Friendships</div>
|
||||
<div class="text-white-50 small">Friendships</div>
|
||||
<div class="fs-3 fw-bold">@_friendships</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -45,7 +45,7 @@ else
|
||||
<div class="col-md-3">
|
||||
<div class="card bg-dark text-white border-secondary h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small">Blocked Pairs</div>
|
||||
<div class="text-white-50 small">Blocked Pairs</div>
|
||||
<div class="fs-3 fw-bold">@_blockedPairs</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -54,7 +54,7 @@ else
|
||||
|
||||
<!-- Channel list with type filter -->
|
||||
<div class="card bg-dark text-white border-secondary">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<div class="card-header d-flex justify-content-between align-items-center border-bottom border-secondary">
|
||||
<span class="fw-semibold">Channels</span>
|
||||
<select class="form-select form-select-sm bg-dark text-white border-secondary w-auto"
|
||||
@bind="_typeFilter">
|
||||
@@ -90,7 +90,9 @@ else
|
||||
<td>@ch.MessageCount</td>
|
||||
<td class="text-muted small">@ch.CreatedAt.ToString("yyyy-MM-dd HH:mm")</td>
|
||||
<td>
|
||||
<a href="/chat/channel/@ch.Id" class="btn btn-sm btn-outline-secondary">View</a>
|
||||
<a href="/chat/channel/@ch.Id" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-chat-text me-1"></i>View & Post
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
@@ -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 */
|
||||
|
||||
@@ -20,6 +20,7 @@ public static class AbilitySystem
|
||||
private static readonly JsonSerializerOptions _jsonOpts = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new System.Text.Json.Serialization.JsonStringEnumConverter() },
|
||||
};
|
||||
|
||||
// ── Parsing ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -44,4 +44,10 @@ public sealed class AbilityDefinition
|
||||
/// Not required for game logic.
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Plain-English description of what this ability does.
|
||||
/// Used in the admin ability builder. Not used by game logic.
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user