diff --git a/Services/Admin/Pages/RoomTemplates/Edit.cshtml b/Services/Admin/Pages/RoomTemplates/Edit.cshtml new file mode 100644 index 0000000..1085123 --- /dev/null +++ b/Services/Admin/Pages/RoomTemplates/Edit.cshtml @@ -0,0 +1,426 @@ +@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

+
+ +
+ + +
+ + +
+
+
+ + +
+

Tile Palette

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

No tilemap sheets found. Create one first.

+ } + else + { + +
+ +
+ + +
+ + + + +
+ + +
+ +
+ + + + + +
+ + + + +
+ } +
+ + +
+
+

Room Editor

+ @Model.Room.Width × @Model.Room.Height +
+ +
+
+ +
+
+ +
+ Click to place • Right-click to erase • Drag to paint +
+
+
+ +@section Scripts { + + +} diff --git a/Services/Admin/Pages/RoomTemplates/Edit.cshtml.cs b/Services/Admin/Pages/RoomTemplates/Edit.cshtml.cs new file mode 100644 index 0000000..ef5fbf4 --- /dev/null +++ b/Services/Admin/Pages/RoomTemplates/Edit.cshtml.cs @@ -0,0 +1,138 @@ +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 new file mode 100644 index 0000000..389d3cd --- /dev/null +++ b/Services/Admin/Pages/RoomTemplates/Index.cshtml @@ -0,0 +1,134 @@ +@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 new file mode 100644 index 0000000..48ba0e9 --- /dev/null +++ b/Services/Admin/Pages/RoomTemplates/Index.cshtml.cs @@ -0,0 +1,64 @@ +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/Shared/_Layout.cshtml b/Services/Admin/Pages/Shared/_Layout.cshtml index 9e9cb49..cfb95ec 100644 --- a/Services/Admin/Pages/Shared/_Layout.cshtml +++ b/Services/Admin/Pages/Shared/_Layout.cshtml @@ -159,6 +159,13 @@ TileMaps + + + + + Room Templates + + diff --git a/Services/Admin/Pages/TileMaps/Edit.cshtml b/Services/Admin/Pages/TileMaps/Edit.cshtml index 3d1949d..32356a2 100644 --- a/Services/Admin/Pages/TileMaps/Edit.cshtml +++ b/Services/Admin/Pages/TileMaps/Edit.cshtml @@ -353,7 +353,7 @@ @section Scripts {