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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user