Admin tools for mob sprites
This commit is contained in:
@@ -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