Admin tools for mob sprites
This commit is contained in:
@@ -490,6 +490,131 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Animations Section -->
|
||||
@if (!Model.IsNew)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-white">Animations (@Model.MobAnimations.Count)</h2>
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/spritesheets" class="btn btn-sm btn-secondary" target="_blank">Manage Sheets</a>
|
||||
<button type="button" onclick="showAddAnimationModal()" class="btn btn-sm btn-primary">+ Add Animation</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
@if (Model.MobAnimations.Count > 0)
|
||||
{
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b border-gray-700">
|
||||
<th class="py-2 text-left text-gray-400">Key</th>
|
||||
<th class="py-2 text-left text-gray-400">Sheet</th>
|
||||
<th class="py-2 text-left text-gray-400">Frames</th>
|
||||
<th class="py-2 text-left text-gray-400">FPS</th>
|
||||
<th class="py-2 text-left text-gray-400">Options</th>
|
||||
<th class="py-2 text-left text-gray-400">Override Key</th>
|
||||
<th class="py-2 text-left text-gray-400">Status</th>
|
||||
<th class="py-2 text-right text-gray-400">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-700/50">
|
||||
@foreach (var assignment in Model.MobAnimations)
|
||||
{
|
||||
var anim = assignment.AnimationDefinition;
|
||||
var sheet = anim?.SpriteSheet;
|
||||
<tr class="hover:bg-gray-800/50">
|
||||
<td class="py-3 text-white font-mono">@anim?.Key</td>
|
||||
<td class="py-3 text-gray-300 text-xs">@sheet?.Name</td>
|
||||
<td class="py-3 text-gray-300 font-mono text-xs">@anim?.FrameSequence</td>
|
||||
<td class="py-3 text-gray-300">@anim?.Fps</td>
|
||||
<td class="py-3 text-gray-400 text-xs">
|
||||
@if (anim?.Loop == true) { <span class="mr-1">Loop</span> }
|
||||
@if (anim?.FlipX == true) { <span class="mr-1">FlipX</span> }
|
||||
@if (anim?.FlipY == true) { <span>FlipY</span> }
|
||||
</td>
|
||||
<td class="py-3 text-gray-300 font-mono text-xs">@(assignment.OverrideKey ?? "-")</td>
|
||||
<td class="py-3">
|
||||
@if (assignment.IsEnabled)
|
||||
{
|
||||
<span class="text-green-400 text-xs">Active</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-500 text-xs">Disabled</span>
|
||||
}
|
||||
</td>
|
||||
<td class="py-3 text-right">
|
||||
<div class="flex justify-end gap-1">
|
||||
<form method="post" asp-page-handler="ToggleAnimation" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="assignmentId" value="@assignment.Id" />
|
||||
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
|
||||
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-gray-400" title="Toggle">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
|
||||
</button>
|
||||
</form>
|
||||
<form method="post" asp-page-handler="RemoveAnimation" class="inline" onsubmit="return confirm('Remove this animation?')">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="assignmentId" value="@assignment.Id" />
|
||||
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
|
||||
<button type="submit" class="p-1.5 hover:bg-gray-700 rounded text-red-400" title="Remove">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-gray-400 text-center py-4">No animations assigned. <a href="/admin/spritesheets" class="text-indigo-400 hover:underline">Create sprite sheets</a> first, then add animations here.</p>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Animation Modal -->
|
||||
<div id="addAnimationModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center">
|
||||
<div class="bg-gray-900 rounded-xl shadow-xl p-6 w-full max-w-md mx-4 border border-gray-700">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Add Animation</h3>
|
||||
<form method="post" asp-page-handler="AddAnimation">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="mobId" value="@Model.Mob.Id" />
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="label">Animation</label>
|
||||
<select name="animationId" class="input" required>
|
||||
<option value="">Select an animation...</option>
|
||||
@foreach (var anim in Model.AllAnimations)
|
||||
{
|
||||
<option value="@anim.Id">[@(anim.SpriteSheet?.Name ?? "?")] @anim.Key - @anim.FrameSequence (@anim.Fps fps)</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Override Key (optional)</label>
|
||||
<input type="text" name="overrideKey" class="input" placeholder="e.g., walk_down" />
|
||||
<p class="text-xs text-gray-500 mt-1">Use if you want to map this animation to a different key for this mob</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Priority</label>
|
||||
<input type="number" name="priority" value="0" class="input" />
|
||||
<p class="text-xs text-gray-500 mt-1">Higher priority used when multiple match</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-4">
|
||||
<button type="button" onclick="closeAddAnimationModal()" class="btn btn-secondary">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Assign</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Loot Tables Section -->
|
||||
@if (!Model.IsNew)
|
||||
{
|
||||
@@ -613,10 +738,19 @@
|
||||
document.getElementById('addAbilityModal').classList.add('hidden');
|
||||
document.getElementById('addAbilityModal').classList.remove('flex');
|
||||
}
|
||||
function showAddAnimationModal() {
|
||||
document.getElementById('addAnimationModal').classList.remove('hidden');
|
||||
document.getElementById('addAnimationModal').classList.add('flex');
|
||||
}
|
||||
function closeAddAnimationModal() {
|
||||
document.getElementById('addAnimationModal').classList.add('hidden');
|
||||
document.getElementById('addAnimationModal').classList.remove('flex');
|
||||
}
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape') {
|
||||
closeAddLootModal();
|
||||
closeAddAbilityModal();
|
||||
closeAddAnimationModal();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Text.Json;
|
||||
|
||||
namespace Server.Services.Admin.Pages.Mobs;
|
||||
|
||||
// Helper class for sprite configuration
|
||||
// Helper class for sprite configuration (legacy - keeping for backwards compatibility)
|
||||
public class MobSpriteConfig
|
||||
{
|
||||
public Dictionary<string, string> Sprites { get; set; } = new();
|
||||
@@ -29,10 +29,12 @@ public class MobSpriteConfig
|
||||
public class EditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public EditModel(GameDbContext db)
|
||||
public EditModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
@@ -46,6 +48,11 @@ public class EditModel : AdminPageModel
|
||||
public List<MobAbilityAssignment> MobAbilities { get; set; } = new();
|
||||
public List<MobAbilityDefinition> AllAbilities { get; set; } = new();
|
||||
|
||||
// Animation management
|
||||
public List<MobAnimationAssignment> MobAnimations { get; set; } = new();
|
||||
public List<MobAnimationDefinition> AllAnimations { get; set; } = new();
|
||||
public string CdnBaseUrl { get; set; } = "";
|
||||
|
||||
public bool IsNew => Mob.Id == 0;
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
@@ -88,6 +95,8 @@ public class EditModel : AdminPageModel
|
||||
|
||||
public async Task OnGetAsync(int? id)
|
||||
{
|
||||
CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
|
||||
|
||||
AllLootTables = await _db.DungeonLootTables
|
||||
.Where(t => t.IsEnabled)
|
||||
.OrderBy(t => t.Name)
|
||||
@@ -102,6 +111,13 @@ public class EditModel : AdminPageModel
|
||||
.Where(a => a.IsEnabled)
|
||||
.OrderBy(a => a.Name)
|
||||
.ToListAsync();
|
||||
|
||||
AllAnimations = await _db.MobAnimationDefinitions
|
||||
.Include(a => a.SpriteSheet)
|
||||
.Where(a => a.IsEnabled)
|
||||
.OrderBy(a => a.SpriteSheet!.Name)
|
||||
.ThenBy(a => a.Key)
|
||||
.ToListAsync();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
@@ -121,6 +137,13 @@ public class EditModel : AdminPageModel
|
||||
.Where(a => a.MobDefinitionId == id.Value)
|
||||
.OrderBy(a => a.AbilityDefinition!.Name)
|
||||
.ToListAsync();
|
||||
|
||||
MobAnimations = await _db.MobAnimationAssignments
|
||||
.Include(a => a.AnimationDefinition)
|
||||
.ThenInclude(d => d!.SpriteSheet)
|
||||
.Where(a => a.MobDefinitionId == id.Value)
|
||||
.OrderBy(a => a.AnimationDefinition!.Key)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -403,4 +426,55 @@ public class EditModel : AdminPageModel
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAddAnimationAsync(int mobId, int animationId, string? overrideKey, int priority)
|
||||
{
|
||||
// Check if already assigned
|
||||
var existing = await _db.MobAnimationAssignments
|
||||
.FirstOrDefaultAsync(a => a.MobDefinitionId == mobId && a.AnimationDefinitionId == animationId);
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
TempData["Error"] = "This animation is already assigned to this mob.";
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
var assignment = new MobAnimationAssignment
|
||||
{
|
||||
MobDefinitionId = mobId,
|
||||
AnimationDefinitionId = animationId,
|
||||
OverrideKey = string.IsNullOrWhiteSpace(overrideKey) ? null : overrideKey,
|
||||
Priority = priority,
|
||||
IsEnabled = true
|
||||
};
|
||||
|
||||
_db.MobAnimationAssignments.Add(assignment);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostRemoveAnimationAsync(int assignmentId, int mobId)
|
||||
{
|
||||
var assignment = await _db.MobAnimationAssignments.FindAsync(assignmentId);
|
||||
if (assignment != null)
|
||||
{
|
||||
_db.MobAnimationAssignments.Remove(assignment);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostToggleAnimationAsync(int assignmentId, int mobId)
|
||||
{
|
||||
var assignment = await _db.MobAnimationAssignments.FindAsync(assignmentId);
|
||||
if (assignment != null)
|
||||
{
|
||||
assignment.IsEnabled = !assignment.IsEnabled;
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage("/Mobs/Edit", new { id = mobId });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,13 @@
|
||||
Abilities
|
||||
</a>
|
||||
|
||||
<a href="/admin/spritesheets" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/SpriteSheets") == true ? "active" : "")" onclick="closeMobileMenu()">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
</svg>
|
||||
Sprite Sheets
|
||||
</a>
|
||||
|
||||
<a href="/admin/assets" class="sidebar-link @(ViewContext.RouteData.Values["page"]?.ToString()?.StartsWith("/Assets") == true ? "active" : "")" onclick="closeMobileMenu()">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
@page "/admin/spritesheets/edit"
|
||||
@model SpriteSheets.EditModel
|
||||
@{
|
||||
ViewData["Title"] = Model.Sheet.Id > 0 ? $"Edit: {Model.Sheet.Name}" : "New Sprite Sheet";
|
||||
var isNew = Model.Sheet.Id == 0;
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<a href="/admin/spritesheets" class="text-gray-400 hover:text-white text-sm">← Back to Sprite Sheets</a>
|
||||
<h1 class="text-3xl font-bold text-white mt-2">@ViewData["Title"]</h1>
|
||||
</div>
|
||||
@if (!isNew)
|
||||
{
|
||||
<form method="post" asp-page-handler="Duplicate">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@Model.Sheet.Id" />
|
||||
<button type="submit" class="btn btn-secondary">Duplicate</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-300" : "bg-green-900/50 border border-green-700 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
@if (TempData["Error"] != null)
|
||||
{
|
||||
<div class="p-4 rounded-lg bg-red-900/50 border border-red-700 text-red-300">
|
||||
@TempData["Error"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post" class="space-y-6">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Sheet.Id" />
|
||||
<input type="hidden" asp-for="Sheet.CreatedAt" />
|
||||
|
||||
<!-- Basic Info -->
|
||||
<div class="card p-6">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Sprite Sheet Info</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<div class="lg:col-span-2">
|
||||
<label class="label">Name</label>
|
||||
<input type="text" asp-for="Sheet.Name" class="input" required placeholder="e.g., Skeleton Walk" />
|
||||
</div>
|
||||
<div class="lg:col-span-2">
|
||||
<label class="label">CDN Path</label>
|
||||
<div class="flex gap-2">
|
||||
<input type="text" asp-for="Sheet.CdnPath" class="input flex-1" required placeholder="textures/mobs/skeleton.png" />
|
||||
<button type="button" onclick="showCdnBrowser()" class="btn btn-secondary">Browse</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Sheet Width (px)</label>
|
||||
<input type="number" asp-for="Sheet.SheetWidth" class="input" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Sheet Height (px)</label>
|
||||
<input type="number" asp-for="Sheet.SheetHeight" class="input" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Frame Width (px)</label>
|
||||
<input type="number" asp-for="Sheet.FrameWidth" class="input" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Frame Height (px)</label>
|
||||
<input type="number" asp-for="Sheet.FrameHeight" class="input" min="1" />
|
||||
</div>
|
||||
<div class="flex items-center gap-2 pt-6">
|
||||
<input type="checkbox" asp-for="Sheet.IsEnabled" class="w-4 h-4" />
|
||||
<label asp-for="Sheet.IsEnabled" class="text-gray-300">Enabled</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Sheet.CdnPath))
|
||||
{
|
||||
<div class="mt-4 p-4 bg-gray-800 rounded-lg">
|
||||
<p class="text-sm text-gray-400 mb-2">Preview (Sheet: @Model.Sheet.SheetWidth x @Model.Sheet.SheetHeight, Frame: @Model.Sheet.FrameWidth x @Model.Sheet.FrameHeight = @Model.Sheet.TotalFrames frames)</p>
|
||||
<img src="@Model.CdnBaseUrl/@Model.Sheet.CdnPath" alt="Sprite sheet preview" class="max-h-64 object-contain" style="image-rendering: pixelated;" />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="flex gap-4">
|
||||
<button type="submit" class="btn btn-primary">Save Sprite Sheet</button>
|
||||
<a href="/admin/spritesheets" class="btn btn-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Animations Section (only for existing sheets) -->
|
||||
@if (!isNew)
|
||||
{
|
||||
<div class="card">
|
||||
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-white">Animations (@Model.Animations.Count)</h2>
|
||||
<button type="button" onclick="showAddAnimModal()" class="btn btn-sm btn-primary">+ Add Animation</button>
|
||||
</div>
|
||||
<div class="p-4">
|
||||
@if (Model.Animations.Count > 0)
|
||||
{
|
||||
<div class="space-y-3">
|
||||
@foreach (var anim in Model.Animations)
|
||||
{
|
||||
<div class="bg-gray-800 rounded-lg p-4">
|
||||
<form method="post" asp-page-handler="UpdateAnimation" class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-8 gap-3 items-end">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="animId" value="@anim.Id" />
|
||||
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
|
||||
|
||||
<div>
|
||||
<label class="label text-xs">Key</label>
|
||||
<input type="text" name="key" value="@anim.Key" class="input input-sm" required />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label text-xs">Name</label>
|
||||
<input type="text" name="name" value="@anim.Name" class="input input-sm" />
|
||||
</div>
|
||||
<div class="lg:col-span-2">
|
||||
<label class="label text-xs">Frames (comma-separated)</label>
|
||||
<input type="text" name="frameSequence" value="@anim.FrameSequence" class="input input-sm font-mono" required />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label text-xs">FPS</label>
|
||||
<input type="number" name="fps" value="@anim.Fps" class="input input-sm" step="0.1" min="0.1" />
|
||||
</div>
|
||||
<div class="flex items-center gap-4 pt-5">
|
||||
<label class="flex items-center gap-1 text-xs text-gray-300">
|
||||
<input type="checkbox" name="loop" value="true" checked="@anim.Loop" class="w-3 h-3" />
|
||||
Loop
|
||||
</label>
|
||||
<label class="flex items-center gap-1 text-xs text-gray-300">
|
||||
<input type="checkbox" name="flipX" value="true" checked="@anim.FlipX" class="w-3 h-3" />
|
||||
FlipX
|
||||
</label>
|
||||
<label class="flex items-center gap-1 text-xs text-gray-300">
|
||||
<input type="checkbox" name="flipY" value="true" checked="@anim.FlipY" class="w-3 h-3" />
|
||||
FlipY
|
||||
</label>
|
||||
<label class="flex items-center gap-1 text-xs text-gray-300">
|
||||
<input type="checkbox" name="isEnabled" value="true" checked="@anim.IsEnabled" class="w-3 h-3" />
|
||||
On
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex gap-1">
|
||||
<button type="submit" class="btn btn-sm btn-secondary flex-1">Save</button>
|
||||
<button type="button" onclick="deleteAnim(@anim.Id)" class="btn btn-sm btn-danger">X</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-gray-400 text-center py-4">No animations defined. Add animations to use this sprite sheet.</p>
|
||||
}
|
||||
|
||||
<!-- Frame Reference -->
|
||||
<div class="mt-4 p-4 bg-gray-900 rounded-lg">
|
||||
<p class="text-sm text-gray-400 mb-2">Frame Reference (frames are numbered 0 to @(Model.Sheet.TotalFrames - 1), left-to-right, top-to-bottom)</p>
|
||||
<div class="grid gap-1" style="grid-template-columns: repeat(@Model.Sheet.Columns, minmax(0, 1fr)); max-width: fit-content;">
|
||||
@for (int i = 0; i < Model.Sheet.TotalFrames; i++)
|
||||
{
|
||||
<div class="w-8 h-8 bg-gray-700 rounded text-xs flex items-center justify-center text-gray-300">@i</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add Animation Modal -->
|
||||
<div id="addAnimModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center">
|
||||
<div class="bg-gray-900 rounded-xl shadow-xl p-6 w-full max-w-lg mx-4 border border-gray-700">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Add Animation</h3>
|
||||
<form method="post" asp-page-handler="AddAnimation">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="label">Key (e.g., walk_down)</label>
|
||||
<input type="text" name="key" class="input" required placeholder="idle_down" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Name (optional)</label>
|
||||
<input type="text" name="name" class="input" placeholder="Idle Down" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Frame Sequence (comma-separated)</label>
|
||||
<input type="text" name="frameSequence" class="input font-mono" required placeholder="0,1,2,3" />
|
||||
<p class="text-xs text-gray-500 mt-1">e.g., "0,1,2,3" or "4,5,6,7,6,5" for ping-pong</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="label">FPS</label>
|
||||
<input type="number" name="fps" value="8" class="input" step="0.1" min="0.1" />
|
||||
</div>
|
||||
<div class="flex items-center gap-4 pt-6">
|
||||
<label class="flex items-center gap-2 text-gray-300">
|
||||
<input type="checkbox" name="loop" value="true" checked class="w-4 h-4" />
|
||||
Loop
|
||||
</label>
|
||||
<label class="flex items-center gap-2 text-gray-300">
|
||||
<input type="checkbox" name="flipX" value="true" class="w-4 h-4" />
|
||||
Flip X
|
||||
</label>
|
||||
<label class="flex items-center gap-2 text-gray-300">
|
||||
<input type="checkbox" name="flipY" value="true" class="w-4 h-4" />
|
||||
Flip Y
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-4">
|
||||
<button type="button" onclick="closeAddAnimModal()" class="btn btn-secondary">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Add Animation</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Animation Form (hidden) -->
|
||||
<form id="deleteAnimForm" method="post" asp-page-handler="DeleteAnimation" class="hidden">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="animId" id="deleteAnimId" value="" />
|
||||
<input type="hidden" name="sheetId" value="@Model.Sheet.Id" />
|
||||
</form>
|
||||
}
|
||||
|
||||
<!-- CDN Browser Modal -->
|
||||
<div id="cdnBrowserModal" class="fixed inset-0 bg-black/50 z-50 hidden items-center justify-center">
|
||||
<div class="bg-gray-900 rounded-xl shadow-xl p-6 w-full max-w-2xl mx-4 border border-gray-700 max-h-[80vh] overflow-hidden flex flex-col">
|
||||
<h3 class="text-lg font-semibold text-white mb-4">Select Image from CDN</h3>
|
||||
<div class="flex-1 overflow-y-auto grid grid-cols-2 md:grid-cols-3 gap-3">
|
||||
@foreach (var asset in Model.CdnImages)
|
||||
{
|
||||
<button type="button" onclick="selectCdnImage('@asset.DownloadPath')" class="p-2 bg-gray-800 rounded-lg hover:bg-gray-700 text-left">
|
||||
<img src="@Model.CdnBaseUrl/@asset.DownloadPath" alt="@asset.FilePath" class="w-full h-20 object-contain mb-1" style="image-rendering: pixelated;" />
|
||||
<p class="text-xs text-gray-400 truncate">@asset.FilePath</p>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<div class="flex justify-end pt-4">
|
||||
<button type="button" onclick="closeCdnBrowser()" class="btn btn-secondary">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
function showAddAnimModal() {
|
||||
document.getElementById('addAnimModal').classList.remove('hidden');
|
||||
document.getElementById('addAnimModal').classList.add('flex');
|
||||
}
|
||||
function closeAddAnimModal() {
|
||||
document.getElementById('addAnimModal').classList.add('hidden');
|
||||
document.getElementById('addAnimModal').classList.remove('flex');
|
||||
}
|
||||
function deleteAnim(id) {
|
||||
if (confirm('Delete this animation?')) {
|
||||
document.getElementById('deleteAnimId').value = id;
|
||||
document.getElementById('deleteAnimForm').submit();
|
||||
}
|
||||
}
|
||||
function showCdnBrowser() {
|
||||
document.getElementById('cdnBrowserModal').classList.remove('hidden');
|
||||
document.getElementById('cdnBrowserModal').classList.add('flex');
|
||||
}
|
||||
function closeCdnBrowser() {
|
||||
document.getElementById('cdnBrowserModal').classList.add('hidden');
|
||||
document.getElementById('cdnBrowserModal').classList.remove('flex');
|
||||
}
|
||||
function selectCdnImage(path) {
|
||||
document.getElementById('Sheet_CdnPath').value = path;
|
||||
closeCdnBrowser();
|
||||
}
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape') {
|
||||
closeAddAnimModal();
|
||||
closeCdnBrowser();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
|
||||
namespace Server.Services.Admin.Pages.SpriteSheets;
|
||||
|
||||
public class EditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public EditModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public MobSpriteSheet Sheet { get; set; } = new();
|
||||
|
||||
public List<MobAnimationDefinition> Animations { get; set; } = new();
|
||||
public List<ClientAsset> CdnImages { get; set; } = new();
|
||||
public string CdnBaseUrl { get; set; } = "";
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync(int? id)
|
||||
{
|
||||
CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
|
||||
CdnImages = await _db.ClientAssets
|
||||
.Where(a => a.AssetType == ClientAssetType.Texture && a.IsEnabled)
|
||||
.OrderBy(a => a.FilePath)
|
||||
.ToListAsync();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var sheet = await _db.MobSpriteSheets
|
||||
.Include(s => s.Animations)
|
||||
.FirstOrDefaultAsync(s => s.Id == id.Value);
|
||||
|
||||
if (sheet != null)
|
||||
{
|
||||
Sheet = sheet;
|
||||
Animations = sheet.Animations?.OrderBy(a => a.Key).ToList() ?? new();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Sheet = new MobSpriteSheet
|
||||
{
|
||||
IsEnabled = true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
CdnBaseUrl = _config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com";
|
||||
|
||||
try
|
||||
{
|
||||
if (Sheet.Id == 0)
|
||||
{
|
||||
Sheet.CreatedAt = DateTime.UtcNow;
|
||||
Sheet.UpdatedAt = DateTime.UtcNow;
|
||||
_db.MobSpriteSheets.Add(Sheet);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Sprite sheet '{Sheet.Name}' created.";
|
||||
return RedirectToPage(new { id = Sheet.Id });
|
||||
}
|
||||
else
|
||||
{
|
||||
var existing = await _db.MobSpriteSheets.FindAsync(Sheet.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
Message = "Sprite sheet not found.";
|
||||
IsError = true;
|
||||
return Page();
|
||||
}
|
||||
|
||||
existing.Name = Sheet.Name;
|
||||
existing.CdnPath = Sheet.CdnPath;
|
||||
existing.SheetWidth = Sheet.SheetWidth;
|
||||
existing.SheetHeight = Sheet.SheetHeight;
|
||||
existing.FrameWidth = Sheet.FrameWidth;
|
||||
existing.FrameHeight = Sheet.FrameHeight;
|
||||
existing.IsEnabled = Sheet.IsEnabled;
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
Sheet = existing;
|
||||
Message = "Sprite sheet updated.";
|
||||
|
||||
Animations = await _db.MobAnimationDefinitions
|
||||
.Where(a => a.SpriteSheetId == Sheet.Id)
|
||||
.OrderBy(a => a.Key)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message = $"Error: {ex.Message}";
|
||||
IsError = true;
|
||||
}
|
||||
|
||||
CdnImages = await _db.ClientAssets
|
||||
.Where(a => a.AssetType == ClientAssetType.Texture && a.IsEnabled)
|
||||
.OrderBy(a => a.FilePath)
|
||||
.ToListAsync();
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAddAnimationAsync(int sheetId, string key, string? name, string frameSequence, float fps, bool loop, bool flipX, bool flipY)
|
||||
{
|
||||
var animation = new MobAnimationDefinition
|
||||
{
|
||||
SpriteSheetId = sheetId,
|
||||
Key = key,
|
||||
Name = name,
|
||||
FrameSequence = frameSequence,
|
||||
Fps = fps,
|
||||
Loop = loop,
|
||||
FlipX = flipX,
|
||||
FlipY = flipY,
|
||||
IsEnabled = true
|
||||
};
|
||||
|
||||
_db.MobAnimationDefinitions.Add(animation);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage(new { id = sheetId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostUpdateAnimationAsync(int animId, int sheetId, string key, string? name, string frameSequence, float fps, bool loop, bool flipX, bool flipY, bool isEnabled)
|
||||
{
|
||||
var animation = await _db.MobAnimationDefinitions.FindAsync(animId);
|
||||
if (animation != null)
|
||||
{
|
||||
animation.Key = key;
|
||||
animation.Name = name;
|
||||
animation.FrameSequence = frameSequence;
|
||||
animation.Fps = fps;
|
||||
animation.Loop = loop;
|
||||
animation.FlipX = flipX;
|
||||
animation.FlipY = flipY;
|
||||
animation.IsEnabled = isEnabled;
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage(new { id = sheetId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAnimationAsync(int animId, int sheetId)
|
||||
{
|
||||
var animation = await _db.MobAnimationDefinitions.FindAsync(animId);
|
||||
if (animation != null)
|
||||
{
|
||||
// Check if assigned to any mobs
|
||||
var assignmentCount = await _db.MobAnimationAssignments
|
||||
.Where(a => a.AnimationDefinitionId == animId)
|
||||
.CountAsync();
|
||||
|
||||
if (assignmentCount > 0)
|
||||
{
|
||||
TempData["Error"] = $"Cannot delete: animation is assigned to {assignmentCount} mob(s).";
|
||||
return RedirectToPage(new { id = sheetId });
|
||||
}
|
||||
|
||||
_db.MobAnimationDefinitions.Remove(animation);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage(new { id = sheetId });
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDuplicateAsync(int id)
|
||||
{
|
||||
var original = await _db.MobSpriteSheets
|
||||
.Include(s => s.Animations)
|
||||
.FirstOrDefaultAsync(s => s.Id == id);
|
||||
|
||||
if (original == null) return RedirectToPage();
|
||||
|
||||
var copy = new MobSpriteSheet
|
||||
{
|
||||
Name = original.Name + " (Copy)",
|
||||
CdnPath = original.CdnPath,
|
||||
SheetWidth = original.SheetWidth,
|
||||
SheetHeight = original.SheetHeight,
|
||||
FrameWidth = original.FrameWidth,
|
||||
FrameHeight = original.FrameHeight,
|
||||
IsEnabled = true,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = DateTime.UtcNow
|
||||
};
|
||||
|
||||
_db.MobSpriteSheets.Add(copy);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
// Copy animations
|
||||
if (original.Animations != null)
|
||||
{
|
||||
foreach (var anim in original.Animations)
|
||||
{
|
||||
_db.MobAnimationDefinitions.Add(new MobAnimationDefinition
|
||||
{
|
||||
SpriteSheetId = copy.Id,
|
||||
Key = anim.Key,
|
||||
Name = anim.Name,
|
||||
FrameSequence = anim.FrameSequence,
|
||||
Fps = anim.Fps,
|
||||
Loop = anim.Loop,
|
||||
FlipX = anim.FlipX,
|
||||
FlipY = anim.FlipY,
|
||||
IsEnabled = anim.IsEnabled
|
||||
});
|
||||
}
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RedirectToPage(new { id = copy.Id });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
@page "/admin/spritesheets"
|
||||
@model SpriteSheets.IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Sprite Sheets";
|
||||
}
|
||||
|
||||
<div class="space-y-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">Sprite Sheets</h1>
|
||||
<p class="text-gray-400 mt-1">Manage sprite sheets and animations for mobs</p>
|
||||
</div>
|
||||
<a href="/admin/spritesheets/edit" class="btn btn-primary">+ New Sprite Sheet</a>
|
||||
</div>
|
||||
|
||||
@if (TempData["Message"] != null)
|
||||
{
|
||||
<div class="p-4 rounded-lg bg-green-900/50 border border-green-700 text-green-300">
|
||||
@TempData["Message"]
|
||||
</div>
|
||||
}
|
||||
@if (TempData["Error"] != null)
|
||||
{
|
||||
<div class="p-4 rounded-lg bg-red-900/50 border border-red-700 text-red-300">
|
||||
@TempData["Error"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
@foreach (var sheet in Model.SpriteSheets)
|
||||
{
|
||||
<div class="card p-4">
|
||||
<div class="flex items-start justify-between mb-3">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-white">@sheet.Name</h3>
|
||||
<p class="text-sm text-gray-400 font-mono">@sheet.CdnPath</p>
|
||||
</div>
|
||||
@if (sheet.IsEnabled)
|
||||
{
|
||||
<span class="badge bg-green-600">Enabled</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-gray-600">Disabled</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-2 text-sm mb-3">
|
||||
<div class="text-gray-400">Sheet Size:</div>
|
||||
<div class="text-white">@sheet.SheetWidth x @sheet.SheetHeight</div>
|
||||
<div class="text-gray-400">Frame Size:</div>
|
||||
<div class="text-white">@sheet.FrameWidth x @sheet.FrameHeight</div>
|
||||
<div class="text-gray-400">Grid:</div>
|
||||
<div class="text-white">@sheet.Columns x @sheet.Rows (@sheet.TotalFrames frames)</div>
|
||||
<div class="text-gray-400">Animations:</div>
|
||||
<div class="text-white">@(sheet.Animations?.Count ?? 0)</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/spritesheets/edit?id=@sheet.Id" class="btn btn-sm btn-secondary flex-1">Edit</a>
|
||||
<form method="post" asp-page-handler="Delete" class="inline" onsubmit="return confirm('Delete this sprite sheet and all its animations?')">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" name="id" value="@sheet.Id" />
|
||||
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (Model.SpriteSheets.Count == 0)
|
||||
{
|
||||
<div class="card p-8 text-center text-gray-400">
|
||||
No sprite sheets found. <a href="/admin/spritesheets/edit" class="text-indigo-400 hover:underline">Create one</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
|
||||
namespace Server.Services.Admin.Pages.SpriteSheets;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public IndexModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public List<MobSpriteSheet> SpriteSheets { get; set; } = new();
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
SpriteSheets = await _db.MobSpriteSheets
|
||||
.Include(s => s.Animations)
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var sheet = await _db.MobSpriteSheets.FindAsync(id);
|
||||
if (sheet != null)
|
||||
{
|
||||
// Check for animation assignments
|
||||
var animationIds = await _db.MobAnimationDefinitions
|
||||
.Where(a => a.SpriteSheetId == id)
|
||||
.Select(a => a.Id)
|
||||
.ToListAsync();
|
||||
|
||||
var assignmentCount = await _db.MobAnimationAssignments
|
||||
.Where(a => animationIds.Contains(a.AnimationDefinitionId))
|
||||
.CountAsync();
|
||||
|
||||
if (assignmentCount > 0)
|
||||
{
|
||||
TempData["Error"] = $"Cannot delete: animations from this sheet are assigned to {assignmentCount} mob(s).";
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
_db.MobSpriteSheets.Remove(sheet);
|
||||
await _db.SaveChangesAsync();
|
||||
TempData["Message"] = $"Sprite sheet '{sheet.Name}' deleted.";
|
||||
}
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user