Admin tools for mob sprites

This commit is contained in:
dingo
2025-12-27 20:12:40 -05:00
parent 99472f226a
commit c16dc1259d
12 changed files with 3536 additions and 2 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,162 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SystemRevivalServer.Migrations
{
/// <inheritdoc />
public partial class AdminToolsforSprites : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "mob_ability_animation_mappings",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
AbilityAssignmentId = table.Column<int>(type: "int", nullable: false),
AnimationKey = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
DirectionSuffix = table.Column<string>(type: "varchar(16)", maxLength: 16, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_mob_ability_animation_mappings", x => x.Id);
table.ForeignKey(
name: "FK_mob_ability_animation_mappings_dungeon_mob_ability_assignmen~",
column: x => x.AbilityAssignmentId,
principalTable: "dungeon_mob_ability_assignments",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "mob_sprite_sheets",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
CdnPath = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
SheetWidth = table.Column<int>(type: "int", nullable: false),
SheetHeight = table.Column<int>(type: "int", nullable: false),
FrameWidth = table.Column<int>(type: "int", nullable: false),
FrameHeight = table.Column<int>(type: "int", nullable: false),
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_mob_sprite_sheets", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "mob_animation_definitions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
SpriteSheetId = table.Column<int>(type: "int", nullable: false),
Key = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Name = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
FrameSequence = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Fps = table.Column<float>(type: "float", nullable: false),
Loop = table.Column<bool>(type: "tinyint(1)", nullable: false),
FlipX = table.Column<bool>(type: "tinyint(1)", nullable: false),
FlipY = table.Column<bool>(type: "tinyint(1)", nullable: false),
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_mob_animation_definitions", x => x.Id);
table.ForeignKey(
name: "FK_mob_animation_definitions_mob_sprite_sheets_SpriteSheetId",
column: x => x.SpriteSheetId,
principalTable: "mob_sprite_sheets",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "mob_animation_assignments",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
MobDefinitionId = table.Column<int>(type: "int", nullable: false),
AnimationDefinitionId = table.Column<int>(type: "int", nullable: false),
OverrideKey = table.Column<string>(type: "varchar(64)", maxLength: 64, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Priority = table.Column<int>(type: "int", nullable: false),
IsEnabled = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_mob_animation_assignments", x => x.Id);
table.ForeignKey(
name: "FK_mob_animation_assignments_dungeon_mob_definitions_MobDefinit~",
column: x => x.MobDefinitionId,
principalTable: "dungeon_mob_definitions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_mob_animation_assignments_mob_animation_definitions_Animatio~",
column: x => x.AnimationDefinitionId,
principalTable: "mob_animation_definitions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_mob_ability_animation_mappings_AbilityAssignmentId",
table: "mob_ability_animation_mappings",
column: "AbilityAssignmentId");
migrationBuilder.CreateIndex(
name: "IX_mob_animation_assignments_AnimationDefinitionId",
table: "mob_animation_assignments",
column: "AnimationDefinitionId");
migrationBuilder.CreateIndex(
name: "IX_mob_animation_assignments_MobDefinitionId",
table: "mob_animation_assignments",
column: "MobDefinitionId");
migrationBuilder.CreateIndex(
name: "IX_mob_animation_definitions_SpriteSheetId",
table: "mob_animation_definitions",
column: "SpriteSheetId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "mob_ability_animation_mappings");
migrationBuilder.DropTable(
name: "mob_animation_assignments");
migrationBuilder.DropTable(
name: "mob_animation_definitions");
migrationBuilder.DropTable(
name: "mob_sprite_sheets");
}
}
}
+197
View File
@@ -1309,6 +1309,33 @@ namespace SystemRevivalServer.Migrations
b.ToTable("dungeon_stash_items");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAbilityAnimationMapping", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AbilityAssignmentId")
.HasColumnType("int");
b.Property<string>("AnimationKey")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<string>("DirectionSuffix")
.HasMaxLength(16)
.HasColumnType("varchar(16)");
b.HasKey("Id");
b.HasIndex("AbilityAssignmentId");
b.ToTable("mob_ability_animation_mappings");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAbilityAssignment", b =>
{
b.Property<int>("Id")
@@ -1488,6 +1515,130 @@ namespace SystemRevivalServer.Migrations
b.ToTable("dungeon_mob_abilities");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAnimationAssignment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AnimationDefinitionId")
.HasColumnType("int");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("MobDefinitionId")
.HasColumnType("int");
b.Property<string>("OverrideKey")
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<int>("Priority")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AnimationDefinitionId");
b.HasIndex("MobDefinitionId");
b.ToTable("mob_animation_assignments");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAnimationDefinition", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("FlipX")
.HasColumnType("tinyint(1)");
b.Property<bool>("FlipY")
.HasColumnType("tinyint(1)");
b.Property<float>("Fps")
.HasColumnType("float");
b.Property<string>("FrameSequence")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("Key")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<bool>("Loop")
.HasColumnType("tinyint(1)");
b.Property<string>("Name")
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<int>("SpriteSheetId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("SpriteSheetId");
b.ToTable("mob_animation_definitions");
});
modelBuilder.Entity("DataServer.Data.Entities.MobSpriteSheet", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property<int>("Id"));
b.Property<string>("CdnPath")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)");
b.Property<int>("FrameHeight")
.HasColumnType("int");
b.Property<int>("FrameWidth")
.HasColumnType("int");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<int>("SheetHeight")
.HasColumnType("int");
b.Property<int>("SheetWidth")
.HasColumnType("int");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.ToTable("mob_sprite_sheets");
});
modelBuilder.Entity("DataServer.Data.Session", b =>
{
b.Property<ulong>("Id")
@@ -1863,6 +2014,17 @@ namespace SystemRevivalServer.Migrations
b.Navigation("Definition");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAbilityAnimationMapping", b =>
{
b.HasOne("DataServer.Data.Entities.MobAbilityAssignment", "AbilityAssignment")
.WithMany()
.HasForeignKey("AbilityAssignmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("AbilityAssignment");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAbilityAssignment", b =>
{
b.HasOne("DataServer.Data.Entities.MobAbilityDefinition", "AbilityDefinition")
@@ -1882,6 +2044,36 @@ namespace SystemRevivalServer.Migrations
b.Navigation("MobDefinition");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAnimationAssignment", b =>
{
b.HasOne("DataServer.Data.Entities.MobAnimationDefinition", "AnimationDefinition")
.WithMany()
.HasForeignKey("AnimationDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DataServer.Data.Entities.DungeonMobDefinition", "MobDefinition")
.WithMany()
.HasForeignKey("MobDefinitionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("AnimationDefinition");
b.Navigation("MobDefinition");
});
modelBuilder.Entity("DataServer.Data.Entities.MobAnimationDefinition", b =>
{
b.HasOne("DataServer.Data.Entities.MobSpriteSheet", "SpriteSheet")
.WithMany("Animations")
.HasForeignKey("SpriteSheetId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("SpriteSheet");
});
modelBuilder.Entity("DataServer.Data.Session", b =>
{
b.HasOne("DataServer.Data.Account", "Account")
@@ -1932,6 +2124,11 @@ namespace SystemRevivalServer.Migrations
{
b.Navigation("AbilityAssignments");
});
modelBuilder.Entity("DataServer.Data.Entities.MobSpriteSheet", b =>
{
b.Navigation("Animations");
});
#pragma warning restore 612, 618
}
}
+134
View File
@@ -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();
}
});
+76 -2
View File
@@ -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">&larr; 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();
}
}
+6
View File
@@ -27,6 +27,12 @@ public sealed class GameDbContext : DbContext
public DbSet<MobAbilityDefinition> MobAbilityDefinitions => Set<MobAbilityDefinition>();
public DbSet<MobAbilityAssignment> MobAbilityAssignments => Set<MobAbilityAssignment>();
// Mob sprite/animation system
public DbSet<MobSpriteSheet> MobSpriteSheets => Set<MobSpriteSheet>();
public DbSet<MobAnimationDefinition> MobAnimationDefinitions => Set<MobAnimationDefinition>();
public DbSet<MobAnimationAssignment> MobAnimationAssignments => Set<MobAnimationAssignment>();
public DbSet<MobAbilityAnimationMapping> MobAbilityAnimationMappings => Set<MobAbilityAnimationMapping>();
public DbSet<DungeonBeltItem> DungeonBeltItems => Set<DungeonBeltItem>();
public DbSet<DeathChest> DeathChests => Set<DeathChest>();
public DbSet<DeathChestItem> DeathChestItems => Set<DeathChestItem>();
+167
View File
@@ -0,0 +1,167 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataServer.Data.Entities;
/// <summary>
/// Defines a sprite sheet uploaded to the CDN
/// </summary>
[Table("mob_sprite_sheets")]
public class MobSpriteSheet
{
[Key]
public int Id { get; set; }
/// <summary>Friendly name for admin UI</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>CDN path (e.g., "textures/mobs/skeleton.png")</summary>
[Required, MaxLength(256)]
public string CdnPath { get; set; } = "";
/// <summary>Total width of the sprite sheet in pixels</summary>
public int SheetWidth { get; set; } = 512;
/// <summary>Total height of the sprite sheet in pixels</summary>
public int SheetHeight { get; set; } = 512;
/// <summary>Width of each frame in pixels</summary>
public int FrameWidth { get; set; } = 64;
/// <summary>Height of each frame in pixels</summary>
public int FrameHeight { get; set; } = 64;
/// <summary>Number of columns in the sheet (calculated from width/frameWidth)</summary>
[NotMapped]
public int Columns => SheetWidth / FrameWidth;
/// <summary>Number of rows in the sheet</summary>
[NotMapped]
public int Rows => SheetHeight / FrameHeight;
/// <summary>Total number of frames</summary>
[NotMapped]
public int TotalFrames => Columns * Rows;
public bool IsEnabled { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
// Navigation
public ICollection<MobAnimationDefinition>? Animations { get; set; }
}
/// <summary>
/// Defines a named animation using frames from a sprite sheet
/// </summary>
[Table("mob_animation_definitions")]
public class MobAnimationDefinition
{
[Key]
public int Id { get; set; }
/// <summary>Which sprite sheet this animation uses</summary>
public int SpriteSheetId { get; set; }
[ForeignKey(nameof(SpriteSheetId))]
public MobSpriteSheet? SpriteSheet { get; set; }
/// <summary>Animation key (e.g., "walk_left", "attack_down", "idle", "cast")</summary>
[Required, MaxLength(64)]
public string Key { get; set; } = "";
/// <summary>Friendly name for admin</summary>
[MaxLength(64)]
public string? Name { get; set; }
/// <summary>
/// Comma-separated list of frame indices (0-based)
/// e.g., "0,1,2,3" or "8,9,10,11,10,9" for ping-pong
/// Frames are numbered left-to-right, top-to-bottom
/// </summary>
[Required, MaxLength(256)]
public string FrameSequence { get; set; } = "0";
/// <summary>Frames per second</summary>
public float Fps { get; set; } = 8f;
/// <summary>Whether the animation loops</summary>
public bool Loop { get; set; } = true;
/// <summary>Optional: flip horizontally (for reusing left as right)</summary>
public bool FlipX { get; set; } = false;
/// <summary>Optional: flip vertically</summary>
public bool FlipY { get; set; } = false;
public bool IsEnabled { get; set; } = true;
/// <summary>Parse frame sequence into array of ints</summary>
[NotMapped]
public int[] Frames => string.IsNullOrEmpty(FrameSequence)
? new[] { 0 }
: FrameSequence.Split(',').Select(s => int.TryParse(s.Trim(), out var n) ? n : 0).ToArray();
}
/// <summary>
/// Links a mob to its animations - which animations from which sheets it uses
/// </summary>
[Table("mob_animation_assignments")]
public class MobAnimationAssignment
{
[Key]
public int Id { get; set; }
/// <summary>Which mob this animation is for</summary>
public int MobDefinitionId { get; set; }
[ForeignKey(nameof(MobDefinitionId))]
public DungeonMobDefinition? MobDefinition { get; set; }
/// <summary>Which animation definition to use</summary>
public int AnimationDefinitionId { get; set; }
[ForeignKey(nameof(AnimationDefinitionId))]
public MobAnimationDefinition? AnimationDefinition { get; set; }
/// <summary>
/// Override key for this mob (e.g., map "walk" to specific directional animation)
/// If null, uses the animation's original key
/// </summary>
[MaxLength(64)]
public string? OverrideKey { get; set; }
/// <summary>Priority when multiple animations match (higher = preferred)</summary>
public int Priority { get; set; } = 0;
public bool IsEnabled { get; set; } = true;
}
/// <summary>
/// Maps ability to animation for a specific mob
/// </summary>
[Table("mob_ability_animation_mappings")]
public class MobAbilityAnimationMapping
{
[Key]
public int Id { get; set; }
/// <summary>The mob-ability assignment this mapping is for</summary>
public int AbilityAssignmentId { get; set; }
[ForeignKey(nameof(AbilityAssignmentId))]
public MobAbilityAssignment? AbilityAssignment { get; set; }
/// <summary>
/// Animation key to play when this ability is used
/// This should match one of the mob's assigned animations
/// </summary>
[Required, MaxLength(64)]
public string AnimationKey { get; set; } = "attack";
/// <summary>Optional: specific direction variant (down, up, left, right)</summary>
[MaxLength(16)]
public string? DirectionSuffix { get; set; }
}