From ff7357c55791b08a11757c3d482f10da0ad9f5d9 Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 10 Jan 2026 13:43:59 -0500 Subject: [PATCH] Admin updates, dungeon viewer --- Game/Dungeon/DungeonHandlerAdmin.cs | 82 +++ Game/Dungeon/DungeonPhase.cs | 7 + Game/Dungeon/DungeonSimulation.cs | 9 +- Game/Dungeon/DungeonSimulationAdmin.cs | 23 + Services/Admin/Pages/Dungeons/Index.cshtml | 237 +++++++ Services/Admin/Pages/Dungeons/Index.cshtml.cs | 133 ++++ Services/Admin/Pages/Dungeons/View.cshtml | 373 ++++++++++ Services/Admin/Pages/Dungeons/View.cshtml.cs | 163 +++++ Services/Admin/Pages/Mobs/Edit.cshtml | 2 +- Services/Admin/Pages/Mobs/Edit.cshtml.cs | 6 +- .../Admin/Pages/RoomTemplates/Edit.cshtml | 647 ------------------ .../Admin/Pages/RoomTemplates/Edit.cshtml.cs | 138 ---- .../Admin/Pages/RoomTemplates/Index.cshtml | 134 ---- .../Admin/Pages/RoomTemplates/Index.cshtml.cs | 64 -- Services/Admin/Pages/TileMaps/Edit.cshtml | 418 +---------- 15 files changed, 1033 insertions(+), 1403 deletions(-) create mode 100644 Game/Dungeon/DungeonHandlerAdmin.cs create mode 100644 Game/Dungeon/DungeonPhase.cs create mode 100644 Game/Dungeon/DungeonSimulationAdmin.cs create mode 100644 Services/Admin/Pages/Dungeons/Index.cshtml create mode 100644 Services/Admin/Pages/Dungeons/Index.cshtml.cs create mode 100644 Services/Admin/Pages/Dungeons/View.cshtml create mode 100644 Services/Admin/Pages/Dungeons/View.cshtml.cs delete mode 100644 Services/Admin/Pages/RoomTemplates/Edit.cshtml delete mode 100644 Services/Admin/Pages/RoomTemplates/Edit.cshtml.cs delete mode 100644 Services/Admin/Pages/RoomTemplates/Index.cshtml delete mode 100644 Services/Admin/Pages/RoomTemplates/Index.cshtml.cs diff --git a/Game/Dungeon/DungeonHandlerAdmin.cs b/Game/Dungeon/DungeonHandlerAdmin.cs new file mode 100644 index 0000000..ab1de91 --- /dev/null +++ b/Game/Dungeon/DungeonHandlerAdmin.cs @@ -0,0 +1,82 @@ +using System.Collections.Concurrent; + +namespace Server.Game.Dungeon; + +/// +/// Admin/management extensions for DungeonHandler +/// +public partial class DungeonHandler +{ + /// + /// Get all active dungeon instances (for admin viewing) + /// + public IReadOnlyCollection GetActiveDungeons() + { + return _dungeons.Values.ToList().AsReadOnly(); + } + + /// + /// Get a specific dungeon by ID (for admin viewing) + /// + public DungeonInstance? GetDungeon(Guid id) + { + _dungeons.TryGetValue(id, out var dungeon); + return dungeon; + } + + /// + /// Force close a dungeon (admin action) + /// Removes all players and destroys the instance + /// + public bool ForceCloseDungeon(Guid dungeonId) + { + if (!_dungeons.TryGetValue(dungeonId, out var dungeon)) + return false; + + // Remove all players from the dungeon + foreach (var player in dungeon.Simulation.Players.Values.ToList()) + { + try + { + // Send them back to town + // Note: This is a simplified version - in production you'd want to + // properly handle player state transitions + //dungeon.Simulation.RemovePlayer(player.CharacterId); + Console.WriteLine("Force Close Dungeon -- Needs Implemented"); + } + catch { /* Ignore errors during cleanup */ } + } + + // Remove the dungeon + return _dungeons.TryRemove(dungeonId, out _); + } + + /// + /// Get summary statistics for admin dashboard + /// + public DungeonStats GetStats() + { + var dungeons = _dungeons.Values.ToList(); + + return new DungeonStats + { + ActiveCount = dungeons.Count, + TotalPlayers = dungeons.Sum(d => d.Simulation.Players.Count), + TotalMobsAlive = dungeons.Sum(d => d.Simulation.Mobs.Values.Count(m => m.IsAlive)), + CompletedCount = dungeons.Count(d => d.Simulation.Phase == DungeonPhase.Cleared), + BossesKilled = dungeons.Count(d => d.BossKilled) + }; + } +} + +/// +/// Statistics for admin dashboard +/// +public class DungeonStats +{ + public int ActiveCount { get; set; } + public int TotalPlayers { get; set; } + public int TotalMobsAlive { get; set; } + public int CompletedCount { get; set; } + public int BossesKilled { get; set; } +} diff --git a/Game/Dungeon/DungeonPhase.cs b/Game/Dungeon/DungeonPhase.cs new file mode 100644 index 0000000..27b4d34 --- /dev/null +++ b/Game/Dungeon/DungeonPhase.cs @@ -0,0 +1,7 @@ +public enum DungeonPhase +{ + Active, + Cleared, + Abandoned +} + diff --git a/Game/Dungeon/DungeonSimulation.cs b/Game/Dungeon/DungeonSimulation.cs index 4281eb3..24e6b4a 100644 --- a/Game/Dungeon/DungeonSimulation.cs +++ b/Game/Dungeon/DungeonSimulation.cs @@ -7,7 +7,7 @@ namespace Server.Game.Dungeon; /// /// Runtime simulation for an active dungeon instance /// -public class DungeonSimulation +public partial class DungeonSimulation { public DungeonLayout Layout { get; } public int Tier { get; } @@ -1052,9 +1052,4 @@ public class DungeonSimulation } } -public enum DungeonPhase -{ - Active, - Cleared, - Abandoned -} + diff --git a/Game/Dungeon/DungeonSimulationAdmin.cs b/Game/Dungeon/DungeonSimulationAdmin.cs new file mode 100644 index 0000000..deac2b4 --- /dev/null +++ b/Game/Dungeon/DungeonSimulationAdmin.cs @@ -0,0 +1,23 @@ +namespace Server.Game.Dungeon; + +/// +/// Admin extensions for DungeonSimulation +/// +public partial class DungeonSimulation +{ + /// + /// Force the dungeon to complete (admin action) + /// + public void ForceComplete() + { + Phase = DungeonPhase.Cleared; + } + + /// + /// Force the dungeon phase (admin action) + /// + public void SetPhase(DungeonPhase phase) + { + Phase = phase; + } +} diff --git a/Services/Admin/Pages/Dungeons/Index.cshtml b/Services/Admin/Pages/Dungeons/Index.cshtml new file mode 100644 index 0000000..ee1478f --- /dev/null +++ b/Services/Admin/Pages/Dungeons/Index.cshtml @@ -0,0 +1,237 @@ +@page "/admin/dungeons" +@model Admin.Pages.Dungeons.IndexModel +@{ + ViewData["Title"] = "Dungeon Management"; +} + + + +
+ +
+
+

Dungeon Management

+

View and manage active dungeon instances

+
+
+ +
+
+ + @if (TempData["Message"] != null) + { +
+ @TempData["Message"] +
+ } + @if (TempData["Error"] != null) + { +
+ @TempData["Error"] +
+ } + + +
+
+
@Model.ActiveCount
+
Active Dungeons
+
+
+
@Model.TotalPlayers
+
Players In Dungeons
+
+
+
@Model.CompletedToday
+
Completed Today
+
+
+
@Model.AverageDuration
+
Avg Duration (min)
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+ + Clear +
+
+ + +
+

+
+ Active Dungeons (@Model.Dungeons.Count) +

+ + @if (Model.Dungeons.Count > 0) + { +
+ @foreach (var dungeon in Model.Dungeons) + { +
+
+
+
+ Tier @dungeon.Tier + Lvl @dungeon.LevelBracketMin-@dungeon.LevelBracketMax + @if (dungeon.BossKilled) + { + Boss Killed + } +
+
@dungeon.Id.ToString()[..8]...
+
+
+ @dungeon.Phase +
@dungeon.Duration
+
+
+ +
+
+
@dungeon.PlayerCount
+
Players
+
+
+
@dungeon.MobsAlive / @dungeon.TotalMobs
+
Mobs
+
+
+
@dungeon.RoomCount
+
Rooms
+
+
+ +
+ Created by: @dungeon.CreatorName + • + Seed: @dungeon.Seed +
+ +
+ + + + + + View + +
+ @Html.AntiForgeryToken() + + +
+
+
+ } +
+ } + else + { +
+
🏰
+

No active dungeons at the moment.

+

Dungeons are created when players enter them.

+
+ } +
+
+ +@section Scripts { + +} + +@functions { + string GetPhaseClass(string phase) + { + return phase.ToLower() switch + { + "active" => "phase-active", + "completed" => "phase-completed", + "failed" => "phase-failed", + _ => "text-gray-400" + }; + } +} diff --git a/Services/Admin/Pages/Dungeons/Index.cshtml.cs b/Services/Admin/Pages/Dungeons/Index.cshtml.cs new file mode 100644 index 0000000..686630a --- /dev/null +++ b/Services/Admin/Pages/Dungeons/Index.cshtml.cs @@ -0,0 +1,133 @@ +using Microsoft.AspNetCore.Mvc; +using Server.Game.Dungeon; + +namespace Server.Services.Admin.Pages.Dungeons; + +public class IndexModel : AdminPageModel +{ + private readonly DungeonHandler _dungeonHandler; + + public IndexModel(DungeonHandler dungeonHandler) + { + _dungeonHandler = dungeonHandler; + } + + public List Dungeons { get; set; } = new(); + + // Stats + public int ActiveCount { get; set; } + public int TotalPlayers { get; set; } + public int CompletedToday { get; set; } + public string AverageDuration { get; set; } = "0"; + + // Filters + public string? StatusFilter { get; set; } + public int? TierFilter { get; set; } + public int? BracketFilter { get; set; } + + public void OnGet(string? status, int? tier, int? bracket) + { + StatusFilter = status; + TierFilter = tier; + BracketFilter = bracket; + + // Get all active dungeons from the handler + var allDungeons = _dungeonHandler.GetActiveDungeons(); + + // Apply filters + var filtered = allDungeons.AsEnumerable(); + + if (!string.IsNullOrEmpty(status)) + { + if (status == "active") + filtered = filtered.Where(d => d.Simulation.Phase == DungeonPhase.Active); + else if (status == "completed") + filtered = filtered.Where(d => d.Simulation.Phase == DungeonPhase.Cleared); + } + + if (tier.HasValue) + { + filtered = filtered.Where(d => d.Tier == tier.Value); + } + + if (bracket.HasValue) + { + int minLevel = (bracket.Value - 1) * 10 + 1; + int maxLevel = bracket.Value * 10; + filtered = filtered.Where(d => d.LevelBracketMin >= minLevel && d.LevelBracketMax <= maxLevel); + } + + // Transform to summary + Dungeons = filtered.Select(d => new DungeonSummary + { + Id = d.Id, + Tier = d.Tier, + Seed = d.Seed, + LevelBracketMin = d.LevelBracketMin, + LevelBracketMax = d.LevelBracketMax, + CreatorName = d.CreatorName, + CreatedAt = d.CreatedAt, + Phase = d.Simulation.Phase.ToString(), + PlayerCount = d.Simulation.Players.Count, + MobsAlive = d.Simulation.Mobs.Values.Count(m => m.IsAlive), + TotalMobs = d.Simulation.Mobs.Count, + RoomCount = d.LayoutV2?.Rooms?.Count ?? d.Simulation.Layout.Rooms.Count, + BossKilled = d.BossKilled, + Duration = FormatDuration(DateTime.UtcNow - d.CreatedAt) + }).OrderByDescending(d => d.CreatedAt).ToList(); + + // Calculate stats + ActiveCount = allDungeons.Count; + TotalPlayers = allDungeons.Sum(d => d.Simulation.Players.Count); + + // Average duration of completed dungeons (simplified) + var completedDungeons = allDungeons.Where(d => d.Simulation.Phase == DungeonPhase.Cleared).ToList(); + if (completedDungeons.Any()) + { + var avgMinutes = completedDungeons.Average(d => (DateTime.UtcNow - d.CreatedAt).TotalMinutes); + AverageDuration = avgMinutes.ToString("F1"); + } + } + + public IActionResult OnPostDelete(Guid id) + { + var result = _dungeonHandler.ForceCloseDungeon(id); + if (result) + { + TempData["Message"] = "Dungeon deleted successfully."; + } + else + { + TempData["Error"] = "Failed to delete dungeon. It may have already been closed."; + } + + return RedirectToPage(); + } + + private static string FormatDuration(TimeSpan duration) + { + if (duration.TotalHours >= 1) + return $"{(int)duration.TotalHours}h {duration.Minutes}m"; + if (duration.TotalMinutes >= 1) + return $"{(int)duration.TotalMinutes}m"; + return $"{(int)duration.TotalSeconds}s"; + } +} + +public class DungeonSummary +{ + public Guid Id { get; set; } + public int Tier { get; set; } + public int Seed { get; set; } + public int LevelBracketMin { get; set; } + public int LevelBracketMax { get; set; } + public string CreatorName { get; set; } = ""; + public DateTime CreatedAt { get; set; } + public string Phase { get; set; } = ""; + public int PlayerCount { get; set; } + public int MobsAlive { get; set; } + public int TotalMobs { get; set; } + public int RoomCount { get; set; } + public bool BossKilled { get; set; } + public string Duration { get; set; } = ""; +} diff --git a/Services/Admin/Pages/Dungeons/View.cshtml b/Services/Admin/Pages/Dungeons/View.cshtml new file mode 100644 index 0000000..e59fdfa --- /dev/null +++ b/Services/Admin/Pages/Dungeons/View.cshtml @@ -0,0 +1,373 @@ +@page "/admin/dungeons/view" +@model Admin.Pages.Dungeons.ViewModel +@{ + ViewData["Title"] = $"Dungeon View - Tier {Model.Dungeon?.Tier}"; +} + + + + + +@if (Model.Dungeon == null) +{ +
+
❌
+

Dungeon Not Found

+

This dungeon may have been closed or doesn't exist.

+ Back to Dungeons +
+} +else +{ +
+ +
+
+
+

Live Dungeon Map

+
+
+ Live + +
+
+ +
+ +
+
+ +
+
+
+ Players +
+
+
+ Mobs +
+
+
+ Boss +
+
+
+ Floor +
+
+
+ Wall +
+
+
+
+ + +
+ +
+

Dungeon Info

+
+
+ ID + @Model.Dungeon.Id.ToString()[..12]... +
+
+ Tier + @Model.Dungeon.Tier +
+
+ Level Bracket + @Model.Dungeon.LevelBracketMin - @Model.Dungeon.LevelBracketMax +
+
+ Seed + @Model.Dungeon.Seed +
+
+ Phase + + @Model.Dungeon.Simulation.Phase + +
+
+ Creator + @Model.Dungeon.CreatorName +
+
+ Created + @Model.Dungeon.CreatedAt.ToString("HH:mm:ss") +
+
+ Duration + @Model.Duration +
+
+
+ + +
+

Stats

+
+
+
@Model.Dungeon.Simulation.Players.Count
+
Players
+
+
+
@Model.Dungeon.Simulation.Mobs.Values.Count(m => m.IsAlive)
+
Mobs Alive
+
+
+
@Model.RoomCount
+
Rooms
+
+
+
+ @(Model.Dungeon.BossKilled ? "✓" : "✗") +
+
Boss Killed
+
+
+
+ + +
+

Players (@Model.Dungeon.Simulation.Players.Count)

+
+ @foreach (var player in Model.Dungeon.Simulation.Players.Values) + { + var healthPct = player.MaxHealth > 0 ? (player.Health * 100 / player.MaxHealth) : 0; +
+
+
+
@player.CharacterName
+
+
+
+
+
@player.Health/@player.MaxHealth
+
+ } + @if (Model.Dungeon.Simulation.Players.Count == 0) + { +
No players
+ } +
+
+ + +
+

Actions

+
+
+ @Html.AntiForgeryToken() + + +
+
+ @Html.AntiForgeryToken() + + +
+
+ @Html.AntiForgeryToken() + + +
+
+
+
+
+} + +@section Scripts { + +} diff --git a/Services/Admin/Pages/Dungeons/View.cshtml.cs b/Services/Admin/Pages/Dungeons/View.cshtml.cs new file mode 100644 index 0000000..879de4e --- /dev/null +++ b/Services/Admin/Pages/Dungeons/View.cshtml.cs @@ -0,0 +1,163 @@ +using Microsoft.AspNetCore.Mvc; +using Server.Game.Dungeon; +using System.Text.Json; + +namespace Server.Services.Admin.Pages.Dungeons; + +public class ViewModel : AdminPageModel +{ + private readonly DungeonHandler _dungeonHandler; + + public ViewModel(DungeonHandler dungeonHandler) + { + _dungeonHandler = dungeonHandler; + } + + public DungeonInstance? Dungeon { get; set; } + public string Duration { get; set; } = ""; + public int RoomCount { get; set; } + public int MapWidth { get; set; } + public int MapHeight { get; set; } + public string WalkableJson { get; set; } = "[]"; + public string PlayersJson { get; set; } = "[]"; + public string MobsJson { get; set; } = "[]"; + + public void OnGet(Guid id) + { + Dungeon = _dungeonHandler.GetDungeon(id); + + if (Dungeon == null) return; + + Duration = FormatDuration(DateTime.UtcNow - Dungeon.CreatedAt); + RoomCount = Dungeon.LayoutV2?.Rooms?.Count ?? Dungeon.Simulation.Layout.Rooms.Count; + + // Get map dimensions + var layout = Dungeon.LayoutV2 ?? (DungeonLayoutV2?)null; + if (layout != null) + { + MapWidth = layout.Width; + MapHeight = layout.Height; + + // Flatten walkable array + var walkable = new List(); + for (int y = 0; y < layout.Height; y++) + { + for (int x = 0; x < layout.Width; x++) + { + walkable.Add(layout.Walkable[x, y]); + } + } + WalkableJson = JsonSerializer.Serialize(walkable); + } + else + { + // Fallback for V1 layouts + MapWidth = 100; + MapHeight = 100; + WalkableJson = "[]"; + } + + // Serialize entity positions + PlayersJson = JsonSerializer.Serialize( + Dungeon.Simulation.Players.Values.Select(p => new + { + name = p.CharacterName, + x = p.X, + y = p.Y, + health = p.Health, + maxHealth = p.MaxHealth + }) + ); + + MobsJson = JsonSerializer.Serialize( + Dungeon.Simulation.Mobs.Values.Select(m => new + { + name = m.Name, + x = m.X, + y = m.Y, + alive = m.IsAlive, + isBoss = m.Type == DataServer.Data.Enums.MobType.Boss + }) + ); + } + + public IActionResult OnGetStatus(Guid id) + { + var dungeon = _dungeonHandler.GetDungeon(id); + if (dungeon == null) + return new JsonResult(new { error = "Not found" }) { StatusCode = 404 }; + + return new JsonResult(new + { + playerCount = dungeon.Simulation.Players.Count, + mobsAlive = dungeon.Simulation.Mobs.Values.Count(m => m.IsAlive), + duration = FormatDuration(DateTime.UtcNow - dungeon.CreatedAt), + players = dungeon.Simulation.Players.Values.Select(p => new + { + name = p.CharacterName, + x = p.X, + y = p.Y + }), + mobs = dungeon.Simulation.Mobs.Values.Where(m => m.IsAlive).Select(m => new + { + name = m.Name, + x = m.X, + y = m.Y, + alive = m.IsAlive, + isBoss = m.Type == DataServer.Data.Enums.MobType.Boss + }) + }); + } + + public IActionResult OnPostKillAllMobs(Guid id) + { + var dungeon = _dungeonHandler.GetDungeon(id); + if (dungeon != null) + { + foreach (var mob in dungeon.Simulation.Mobs.Values) + { + mob.Health = 0; + mob.IsAlive = false; + } + TempData["Message"] = "All mobs killed."; + } + + return RedirectToPage(new { id }); + } + + public IActionResult OnPostCompleteDungeon(Guid id) + { + var dungeon = _dungeonHandler.GetDungeon(id); + if (dungeon != null) + { + dungeon.Simulation.ForceComplete(); + TempData["Message"] = "Dungeon marked as completed."; + } + + return RedirectToPage(new { id }); + } + + public IActionResult OnPostDelete(Guid id) + { + var result = _dungeonHandler.ForceCloseDungeon(id); + if (result) + { + TempData["Message"] = "Dungeon deleted."; + } + else + { + TempData["Error"] = "Failed to delete dungeon."; + } + + return RedirectToPage("/Dungeons/Index"); + } + + private static string FormatDuration(TimeSpan duration) + { + if (duration.TotalHours >= 1) + return $"{(int)duration.TotalHours}h {duration.Minutes}m"; + if (duration.TotalMinutes >= 1) + return $"{(int)duration.TotalMinutes}m {duration.Seconds}s"; + return $"{(int)duration.TotalSeconds}s"; + } +} diff --git a/Services/Admin/Pages/Mobs/Edit.cshtml b/Services/Admin/Pages/Mobs/Edit.cshtml index 932f931..05fd505 100644 --- a/Services/Admin/Pages/Mobs/Edit.cshtml +++ b/Services/Admin/Pages/Mobs/Edit.cshtml @@ -493,7 +493,7 @@ @if (!Model.IsNew) { -
+

Animations (@Model.MobAnimations.Count)

diff --git a/Services/Admin/Pages/Mobs/Edit.cshtml.cs b/Services/Admin/Pages/Mobs/Edit.cshtml.cs index 29ee08e..85fd4d7 100644 --- a/Services/Admin/Pages/Mobs/Edit.cshtml.cs +++ b/Services/Admin/Pages/Mobs/Edit.cshtml.cs @@ -451,7 +451,7 @@ public class EditModel : AdminPageModel _db.MobAnimationAssignments.Add(assignment); await _db.SaveChangesAsync(); - return RedirectToPage("/Mobs/Edit", new { id = mobId }); + return Redirect($"/admin/mobs/edit?id={mobId}#animations-section"); } public async Task OnPostRemoveAnimationAsync(int assignmentId, int mobId) @@ -463,7 +463,7 @@ public class EditModel : AdminPageModel await _db.SaveChangesAsync(); } - return RedirectToPage("/Mobs/Edit", new { id = mobId }); + return Redirect($"/admin/mobs/edit?id={mobId}#animations-section"); } public async Task OnPostToggleAnimationAsync(int assignmentId, int mobId) @@ -475,6 +475,6 @@ public class EditModel : AdminPageModel await _db.SaveChangesAsync(); } - return RedirectToPage("/Mobs/Edit", new { id = mobId }); + return Redirect($"/admin/mobs/edit?id={mobId}#animations-section"); } } diff --git a/Services/Admin/Pages/RoomTemplates/Edit.cshtml b/Services/Admin/Pages/RoomTemplates/Edit.cshtml deleted file mode 100644 index 98e4a15..0000000 --- a/Services/Admin/Pages/RoomTemplates/Edit.cshtml +++ /dev/null @@ -1,647 +0,0 @@ -@page "/admin/roomtemplates/edit" -@model RoomTemplates.EditModel -@using DataServer.Data.Entities -@{ - ViewData["Title"] = Model.Room.Id == 0 ? "New Room Template" : $"Edit: {Model.Room.Name}"; - var roomTypes = Enum.GetValues(); - var tileTypes = Enum.GetValues(); -} - - - -@if (!string.IsNullOrEmpty(Model.Message)) -{ -
- @Model.Message -
-} - -
- -
-

Room Settings

- -
- @Html.AntiForgeryToken() - - - - - -
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
-
- - -
-
- - -
-
- -
-
- - -
-
- - -
-
- -
- - -

Higher = more common in generation

-
- -
- - -
- -
- -
-
-
-
- - -
-

Tools & Palette

- - -
-
- - - -
-
- - -
- @if (Model.TileMapSheets.Count == 0) - { -

No tilemap sheets found. Create one first.

- } - else - { - -
- -
- - -
- - - - -
- - -
- -
- - - - - -
- - - - -
- } -
- - - - - - -
- - -
-
-

Room Editor

- @Model.Room.Width × @Model.Room.Height -
- -
-
- -
-
- -
-

Tiles: Click to place • Right-click to erase • Drag to paint

-

Spawns: Click to place/remove • Connections: Click room edges

-
- - -
-

Legend:

-
- Player - Mob - Boss - Chest - Connection -
-
-
-
- -@section Scripts { - - -} diff --git a/Services/Admin/Pages/RoomTemplates/Edit.cshtml.cs b/Services/Admin/Pages/RoomTemplates/Edit.cshtml.cs deleted file mode 100644 index ef5fbf4..0000000 --- a/Services/Admin/Pages/RoomTemplates/Edit.cshtml.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using DataServer.Data; -using DataServer.Data.Entities; -using System.Text.Json; - -namespace Server.Services.Admin.Pages.RoomTemplates; - -public class EditModel : AdminPageModel -{ - private readonly GameDbContext _db; - private readonly IConfiguration _config; - - public EditModel(GameDbContext db, IConfiguration config) - { - _db = db; - _config = config; - } - - [BindProperty] - public RoomTemplate Room { get; set; } = new(); - - public List TileMapSheets { get; set; } = new(); - public List AllTiles { 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"]?.TrimEnd('/') ?? "https://assets.aeternalisgames.com"; - if (!CdnBaseUrl.EndsWith("/downloads")) CdnBaseUrl += "/downloads"; - - TileMapSheets = await _db.TileMapSheets - .Where(s => s.IsEnabled) - .Include(s => s.Tiles!.Where(t => t.IsEnabled)) - .OrderBy(s => s.Name) - .ToListAsync(); - - AllTiles = TileMapSheets.SelectMany(s => s.Tiles ?? new List()).ToList(); - - if (id.HasValue) - { - var room = await _db.RoomTemplates.FindAsync(id.Value); - if (room != null) - { - Room = room; - } - } - else - { - Room = new RoomTemplate - { - Width = 10, - Height = 10, - MinTier = 1, - Weight = 100, - IsEnabled = true - }; - } - } - - public async Task OnPostAsync() - { - CdnBaseUrl = _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? "https://assets.aeternalisgames.com"; - if (!CdnBaseUrl.EndsWith("/downloads")) CdnBaseUrl += "/downloads"; - - try - { - if (Room.Id == 0) - { - Room.CreatedAt = DateTime.UtcNow; - Room.UpdatedAt = DateTime.UtcNow; - _db.RoomTemplates.Add(Room); - await _db.SaveChangesAsync(); - Message = $"Room template '{Room.Name}' created."; - return RedirectToPage(new { id = Room.Id }); - } - else - { - var existing = await _db.RoomTemplates.FindAsync(Room.Id); - if (existing == null) - { - Message = "Room template not found."; - IsError = true; - return Page(); - } - - existing.Name = Room.Name; - existing.Description = Room.Description; - existing.Tags = Room.Tags; - existing.Type = Room.Type; - existing.Width = Room.Width; - existing.Height = Room.Height; - existing.MinTier = Room.MinTier; - existing.MaxTier = Room.MaxTier; - existing.Weight = Room.Weight; - existing.TileDataJson = Room.TileDataJson; - existing.SpawnPointsJson = Room.SpawnPointsJson; - existing.ConnectionPointsJson = Room.ConnectionPointsJson; - existing.IsEnabled = Room.IsEnabled; - existing.UpdatedAt = DateTime.UtcNow; - - await _db.SaveChangesAsync(); - Room = existing; - Message = "Room template updated."; - } - } - catch (Exception ex) - { - Message = $"Error: {ex.Message}"; - IsError = true; - } - - TileMapSheets = await _db.TileMapSheets - .Where(s => s.IsEnabled) - .Include(s => s.Tiles!.Where(t => t.IsEnabled)) - .OrderBy(s => s.Name) - .ToListAsync(); - AllTiles = TileMapSheets.SelectMany(s => s.Tiles ?? new List()).ToList(); - - return Page(); - } - - public async Task OnPostSaveTilesAsync(int roomId, string tileData) - { - var room = await _db.RoomTemplates.FindAsync(roomId); - if (room != null) - { - room.TileDataJson = tileData; - room.UpdatedAt = DateTime.UtcNow; - await _db.SaveChangesAsync(); - return new JsonResult(new { success = true }); - } - return new JsonResult(new { success = false, error = "Room not found" }); - } -} diff --git a/Services/Admin/Pages/RoomTemplates/Index.cshtml b/Services/Admin/Pages/RoomTemplates/Index.cshtml deleted file mode 100644 index 389d3cd..0000000 --- a/Services/Admin/Pages/RoomTemplates/Index.cshtml +++ /dev/null @@ -1,134 +0,0 @@ -@page "/admin/roomtemplates" -@model RoomTemplates.IndexModel -@using DataServer.Data.Entities -@{ - ViewData["Title"] = "Room Templates"; -} - -
-
-

Room Templates

-

Create and manage room layouts for dungeon generation

-
- + New Room -
- - -
- Filter: - @foreach (var type in Enum.GetValues().Take(10)) - { - var count = Model.Rooms.Count(r => r.Type == type); - if (count > 0) - { - @type (@count) - } - } -
- -
- @foreach (var room in Model.Rooms) - { -
-
-
-

@room.Name

-

@room.Width×@room.Height tiles

-
-
- @room.Type - - @(room.IsEnabled ? "On" : "Off") - -
-
- - @if (!string.IsNullOrEmpty(room.Description)) - { -

@room.Description

- } - -
-
- Tier: - @room.MinTier - @(room.MaxTier == 0 ? "∞" : room.MaxTier.ToString()) -
-
- Weight: - @room.Weight -
-
- - @if (!string.IsNullOrEmpty(room.Tags)) - { -
- @foreach (var tag in room.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries).Take(4)) - { - @tag.Trim() - } -
- } - - -
- @if (!string.IsNullOrEmpty(room.TileDataJson)) - { - @(CountTiles(room.TileDataJson)) tiles placed - } - else - { - No tiles placed - } -
- -
- Edit -
- - -
-
- - -
-
-
- } -
- -@if (Model.Rooms.Count == 0) -{ -
-

No room templates yet. Create rooms to use in dungeon generation.

- Create Your First Room -
-} - -@functions { - string GetRoomTypeColor(RoomType type) - { - return type switch - { - RoomType.Entrance => "bg-green-900 text-green-300", - RoomType.Exit => "bg-blue-900 text-blue-300", - RoomType.Boss => "bg-red-900 text-red-300", - RoomType.Treasure => "bg-yellow-900 text-yellow-300", - RoomType.Secret => "bg-purple-900 text-purple-300", - RoomType.Shop => "bg-cyan-900 text-cyan-300", - RoomType.Hallway => "bg-gray-700 text-gray-300", - _ => "bg-gray-600 text-gray-300" - }; - } - - int CountTiles(string? json) - { - if (string.IsNullOrEmpty(json)) return 0; - try - { - var tiles = System.Text.Json.JsonSerializer.Deserialize>(json); - return tiles?.Count ?? 0; - } - catch { return 0; } - } -} diff --git a/Services/Admin/Pages/RoomTemplates/Index.cshtml.cs b/Services/Admin/Pages/RoomTemplates/Index.cshtml.cs deleted file mode 100644 index 48ba0e9..0000000 --- a/Services/Admin/Pages/RoomTemplates/Index.cshtml.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using DataServer.Data; -using DataServer.Data.Entities; - -namespace Server.Services.Admin.Pages.RoomTemplates; - -public class IndexModel : AdminPageModel -{ - private readonly GameDbContext _db; - - public IndexModel(GameDbContext db) - { - _db = db; - } - - public List Rooms { get; set; } = new(); - - public async Task OnGetAsync() - { - Rooms = await _db.RoomTemplates - .OrderBy(r => r.Type) - .ThenBy(r => r.Name) - .ToListAsync(); - } - - public async Task OnPostDeleteAsync(int id) - { - var room = await _db.RoomTemplates.FindAsync(id); - if (room != null) - { - _db.RoomTemplates.Remove(room); - await _db.SaveChangesAsync(); - } - return RedirectToPage(); - } - - public async Task OnPostDuplicateAsync(int id) - { - var room = await _db.RoomTemplates.FindAsync(id); - if (room != null) - { - var copy = new RoomTemplate - { - Name = room.Name + " (Copy)", - Description = room.Description, - Tags = room.Tags, - Type = room.Type, - Width = room.Width, - Height = room.Height, - MinTier = room.MinTier, - MaxTier = room.MaxTier, - Weight = room.Weight, - TileDataJson = room.TileDataJson, - SpawnPointsJson = room.SpawnPointsJson, - ConnectionPointsJson = room.ConnectionPointsJson, - IsEnabled = false - }; - _db.RoomTemplates.Add(copy); - await _db.SaveChangesAsync(); - } - return RedirectToPage(); - } -} diff --git a/Services/Admin/Pages/TileMaps/Edit.cshtml b/Services/Admin/Pages/TileMaps/Edit.cshtml index bf052b2..edd5775 100644 --- a/Services/Admin/Pages/TileMaps/Edit.cshtml +++ b/Services/Admin/Pages/TileMaps/Edit.cshtml @@ -3,8 +3,6 @@ @using DataServer.Data.Entities @{ ViewData["Title"] = Model.Sheet.Id == 0 ? "New TileMap Sheet" : $"Edit: {Model.Sheet.Name}"; - var tileTypes = Enum.GetValues(); - var socketTypes = Enum.GetValues(); // Build image URL - handle both with and without /downloads/ path var imageUrl = Model.Sheet.CdnPath; if (!string.IsNullOrEmpty(imageUrl)) @@ -126,282 +124,23 @@
+ @if (Model.Sheet.Id > 0) { -
-
-

Tile Definitions

-
-
- - - -
- - -
- - -
+
+
💡
+
+

Create Tile Templates

+

+ To use tiles from this sheet, create Tile Templates + which define walkability, sockets, and other properties. +

- -

Click on a tile to define its properties. Defined: @Model.TileDefinitions.Count / @Model.Sheet.TotalTiles

- - -
-
- @if (!string.IsNullOrEmpty(Model.Sheet.CdnPath)) - { - @Model.Sheet.Name - - -
- @for (int row = 0; row < Model.Sheet.Rows; row++) - { - @for (int col = 0; col < Model.Sheet.Columns; col++) - { - var frameIndex = row * Model.Sheet.Columns + col; - var tileDef = Model.TileDefinitions.FirstOrDefault(t => t.FrameIndex == frameIndex); - var hasDefinition = tileDef != null; - var tileColor = hasDefinition ? GetTileTypeColor(tileDef!.Type) : "transparent"; - -
-
- } - } -
- } -
-
- - -
- Legend: - Floor - Wall - Door - Water - Lava - Spawn -
- - - @if (Model.TileDefinitions.Count > 0) - { -
-

Defined Tiles (@Model.TileDefinitions.Count)

-
- - - - - - - - - - - - - - @foreach (var tile in Model.TileDefinitions.Take(50)) - { - var col = tile.FrameIndex % Model.Sheet.Columns; - var row = tile.FrameIndex / Model.Sheet.Columns; - - - - - - - - - - - } - -
#PreviewNameTypeSocketsPropsActions
@tile.FrameIndex -
-
-
-
@(tile.Name ?? "-") - @tile.Type - - N - E - S - W - - @if (tile.IsWalkable) { W } - @if (tile.BlocksProjectiles) { P } - @if (tile.BlocksLineOfSight) { L } - - -
- - - -
-
- @if (Model.TileDefinitions.Count > 50) - { -

Showing first 50 of @Model.TileDefinitions.Count tiles

- } -
-
- }
} - - -