diff --git a/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml.cs b/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml.cs index c09e1b1..ec73d6f 100644 --- a/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml.cs +++ b/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml.cs @@ -24,15 +24,16 @@ public class ObjectEditModel : AdminPageModel public List DamageTypes { get; set; } = new(); public List CdnImages { get; set; } = new(); - public string CdnBaseUrl => _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? ""; + public string CdnBaseUrl;// => _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? ""; public string? Message { get; set; } public bool IsError { get; set; } public async Task OnGetAsync(int? id) { + CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com"); await LoadReferenceData(); - + if (id.HasValue) { var obj = await _db.ObjectTemplates @@ -59,6 +60,7 @@ public class ObjectEditModel : AdminPageModel public async Task OnPostAsync() { + CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com"); await LoadReferenceData(); if (!ModelState.IsValid) @@ -167,4 +169,17 @@ public class ObjectEditModel : AdminPageModel if (!baseUrl.EndsWith("/downloads")) baseUrl += "/downloads"; return $"{baseUrl}/{path.TrimStart('/')}"; } + private static string NormalizeCdnBaseUrl(string? baseUrl) + { + baseUrl = string.IsNullOrWhiteSpace(baseUrl) + ? "https://assets.aeternalisgames.com" + : baseUrl; + + baseUrl = baseUrl.TrimEnd('/'); + + if (!baseUrl.EndsWith("/downloads", StringComparison.OrdinalIgnoreCase)) + baseUrl += "/downloads"; + + return baseUrl; + } } diff --git a/Services/Admin/Pages/DungeonBuilder/PaletteEdit.cshtml b/Services/Admin/Pages/DungeonBuilder/PaletteEdit.cshtml new file mode 100644 index 0000000..d2e3b58 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/PaletteEdit.cshtml @@ -0,0 +1,297 @@ +@page "/admin/dungeonbuilder/palettes/edit" +@model DungeonBuilder.PaletteEditModel +@{ + ViewData["Title"] = Model.Palette.Id == 0 ? "New Dungeon Palette" : $"Edit: {Model.Palette.Name}"; +} + + + +

@ViewData["Title"]

+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +
+ @Model.Message +
+} + +
+ @Html.AntiForgeryToken() + + + + + + + + + +
+ +
+
+

Basic Settings

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

Room Generation

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

Density Settings

+
+
+ + +
@Model.Palette.DecorationDensity%
+
+
+ + +
@Model.Palette.ContainerDensity%
+
+
+ + +
@Model.Palette.TrapDensity%
+
+
+
+
+ + +
+
+

🧱 Floor Templates

+

Select tile templates to use for floors

+
+ @foreach (var tile in Model.FloorTiles) + { + + } + @if (!Model.FloorTiles.Any()) + { +
No floor templates. Create some first!
+ } +
+
+ +
+

🧱 Wall Templates

+

Select tile templates to use for walls

+
+ @foreach (var tile in Model.WallTiles) + { + + } + @if (!Model.WallTiles.Any()) + { +
No wall templates. Create some first!
+ } +
+
+ +
+

πŸšͺ Door Templates

+

Select tile templates to use for doors

+
+ @foreach (var tile in Model.DoorTiles) + { + + } + @if (!Model.DoorTiles.Any()) + { +
No door templates.
+ } +
+
+ +
+

πŸ—ΊοΈ Room Templates

+

Pre-built rooms to include

+
+ @foreach (var room in Model.Rooms) + { + + } + @if (!Model.Rooms.Any()) + { +
No room templates.
+ } +
+
+
+ + +
+
+

πŸͺ¨ Decorations

+

Objects placed as decoration

+
+ @foreach (var obj in Model.Decorations) + { + + } + @if (!Model.Decorations.Any()) + { +
No decoration objects.
+ } +
+
+ +
+

πŸ“¦ Containers

+

Chests, barrels, crates

+
+ @foreach (var obj in Model.Containers) + { + + } + @if (!Model.Containers.Any()) + { +
No container objects.
+ } +
+
+ +
+

⚠️ Traps

+

Hazards and traps

+
+ @foreach (var obj in Model.Traps) + { + + } + @if (!Model.Traps.Any()) + { +
No trap objects.
+ } +
+
+
+
+ +
+ Cancel + +
+
+ + diff --git a/Services/Admin/Pages/DungeonBuilder/PaletteEdit.cshtml.cs b/Services/Admin/Pages/DungeonBuilder/PaletteEdit.cshtml.cs new file mode 100644 index 0000000..3686d8a --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/PaletteEdit.cshtml.cs @@ -0,0 +1,198 @@ +using DataServer.Data; +using DataServer.Data.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System.Text.Json; + +namespace Server.Services.Admin.Pages.DungeonBuilder; + +public class PaletteEditModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public PaletteEditModel(GameDbContext db) + { + _db = db; + } + + [BindProperty] + public DungeonPalette Palette { get; set; } = new(); + + // Available items + public List FloorTiles { get; set; } = new(); + public List WallTiles { get; set; } = new(); + public List DoorTiles { get; set; } = new(); + public List Decorations { get; set; } = new(); + public List Containers { get; set; } = new(); + public List Traps { get; set; } = new(); + public List Rooms { get; set; } = new(); + + // Selected IDs + public List SelectedFloorIds { get; set; } = new(); + public List SelectedWallIds { get; set; } = new(); + public List SelectedDoorIds { get; set; } = new(); + public List SelectedDecorationIds { get; set; } = new(); + public List SelectedContainerIds { get; set; } = new(); + public List SelectedTrapIds { get; set; } = new(); + public List SelectedRoomIds { get; set; } = new(); + + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync(int? id) + { + await LoadReferenceData(); + + if (id.HasValue) + { + var palette = await _db.DungeonPalettes.FindAsync(id.Value); + if (palette != null) + { + Palette = palette; + + // Parse selected IDs + SelectedFloorIds = ParseIds(palette.FloorTemplateIdsJson); + SelectedWallIds = ParseIds(palette.WallTemplateIdsJson); + SelectedDoorIds = ParseIds(palette.DoorTemplateIdsJson); + SelectedDecorationIds = ParseIds(palette.DecorationIdsJson); + SelectedContainerIds = ParseIds(palette.ContainerIdsJson); + SelectedTrapIds = ParseIds(palette.TrapIdsJson); + SelectedRoomIds = ParseIds(palette.RoomTemplateIdsJson); + } + } + else + { + // Defaults + Palette.IsEnabled = true; + Palette.MinRooms = 5; + Palette.MaxRooms = 15; + Palette.MinRoomWidth = 6; + Palette.MaxRoomWidth = 20; + Palette.MinRoomHeight = 6; + Palette.MaxRoomHeight = 20; + Palette.MinCorridorWidth = 3; + Palette.MaxCorridorWidth = 5; + Palette.DecorationDensity = 30; + Palette.ContainerDensity = 20; + Palette.TrapDensity = 10; + } + } + + public async Task OnPostAsync() + { + await LoadReferenceData(); + + if (string.IsNullOrWhiteSpace(Palette.Name)) + { + IsError = true; + Message = "Name is required."; + return Page(); + } + + Palette.UpdatedAt = DateTime.UtcNow; + + if (Palette.Id == 0) + { + Palette.CreatedAt = DateTime.UtcNow; + _db.DungeonPalettes.Add(Palette); + Message = "Palette created!"; + } + else + { + var existing = await _db.DungeonPalettes.FindAsync(Palette.Id); + if (existing == null) + { + IsError = true; + Message = "Palette not found."; + return Page(); + } + + existing.Name = Palette.Name; + existing.Description = Palette.Description; + existing.Biome = Palette.Biome; + existing.Tags = Palette.Tags; + existing.FloorTemplateIdsJson = Palette.FloorTemplateIdsJson; + existing.WallTemplateIdsJson = Palette.WallTemplateIdsJson; + existing.DoorTemplateIdsJson = Palette.DoorTemplateIdsJson; + existing.DecorationIdsJson = Palette.DecorationIdsJson; + existing.ContainerIdsJson = Palette.ContainerIdsJson; + existing.TrapIdsJson = Palette.TrapIdsJson; + existing.RoomTemplateIdsJson = Palette.RoomTemplateIdsJson; + existing.MinRooms = Palette.MinRooms; + existing.MaxRooms = Palette.MaxRooms; + existing.MinRoomWidth = Palette.MinRoomWidth; + existing.MaxRoomWidth = Palette.MaxRoomWidth; + existing.MinRoomHeight = Palette.MinRoomHeight; + existing.MaxRoomHeight = Palette.MaxRoomHeight; + existing.MinCorridorWidth = Palette.MinCorridorWidth; + existing.MaxCorridorWidth = Palette.MaxCorridorWidth; + existing.DecorationDensity = Palette.DecorationDensity; + existing.ContainerDensity = Palette.ContainerDensity; + existing.TrapDensity = Palette.TrapDensity; + existing.IsEnabled = Palette.IsEnabled; + existing.UpdatedAt = DateTime.UtcNow; + + Message = "Changes saved!"; + } + + await _db.SaveChangesAsync(); + + // Re-parse selected IDs for display + SelectedFloorIds = ParseIds(Palette.FloorTemplateIdsJson); + SelectedWallIds = ParseIds(Palette.WallTemplateIdsJson); + SelectedDoorIds = ParseIds(Palette.DoorTemplateIdsJson); + SelectedDecorationIds = ParseIds(Palette.DecorationIdsJson); + SelectedContainerIds = ParseIds(Palette.ContainerIdsJson); + SelectedTrapIds = ParseIds(Palette.TrapIdsJson); + SelectedRoomIds = ParseIds(Palette.RoomTemplateIdsJson); + + return RedirectToPage(new { id = Palette.Id }); + } + + private async Task LoadReferenceData() + { + // Tile templates by category + var allTiles = await _db.TileTemplates + .Where(t => t.IsEnabled) + .OrderBy(t => t.Name) + .ToListAsync(); + + FloorTiles = allTiles.Where(t => t.Category == TileTemplateCategory.Floor).ToList(); + WallTiles = allTiles.Where(t => t.Category == TileTemplateCategory.Wall).ToList(); + DoorTiles = allTiles.Where(t => t.Category == TileTemplateCategory.Door).ToList(); + + // Object templates by type + var allObjects = await _db.ObjectTemplates + .Where(o => o.IsEnabled) + .OrderBy(o => o.Name) + .ToListAsync(); + + Decorations = allObjects.Where(o => + o.Type == ObjectTemplateType.Decoration || + o.Type == ObjectTemplateType.Furniture || + o.Type == ObjectTemplateType.Light).ToList(); + Containers = allObjects.Where(o => o.Type == ObjectTemplateType.Container).ToList(); + Traps = allObjects.Where(o => + o.Type == ObjectTemplateType.Trap || + o.Type == ObjectTemplateType.Hazard).ToList(); + + // Room templates + Rooms = await _db.BuilderRoomTemplates + .Where(r => r.IsEnabled) + .OrderBy(r => r.Name) + .ToListAsync(); + } + + private List ParseIds(string? json) + { + if (string.IsNullOrEmpty(json)) return new List(); + try + { + return JsonSerializer.Deserialize>(json) ?? new List(); + } + catch + { + return new List(); + } + } +} diff --git a/Services/Admin/Pages/DungeonBuilder/Palettes.cshtml b/Services/Admin/Pages/DungeonBuilder/Palettes.cshtml new file mode 100644 index 0000000..902041c --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/Palettes.cshtml @@ -0,0 +1,81 @@ +@page "/admin/dungeonbuilder/palettes" +@model DungeonBuilder.PalettesModel +@{ + ViewData["Title"] = "Dungeon Palettes"; +} + + + +
+
+

Dungeon Palettes

+

Themed collections of templates for dungeon generation

+
+ + New Palette +
+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +
+ @Model.Message +
+} + +
+ @foreach (var palette in Model.Palettes) + { +
+
+
+

@palette.Name

+ @if (!string.IsNullOrEmpty(palette.Biome)) + { + @palette.Biome + } + @if (!string.IsNullOrEmpty(palette.Description)) + { +

@palette.Description

+ } +
+
+ 🎨 +
+
+ +
+
+
@palette.MinRooms-@palette.MaxRooms
+
Rooms
+
+
+
@palette.DecorationDensity%
+
Decor
+
+
+
@palette.TrapDensity%
+
Traps
+
+
+ +
+ ID: @palette.Id +
+ Edit +
+ + +
+
+
+
+ } + + @if (!Model.Palettes.Any()) + { +
+ No palettes found. Create one! +
+ } +
diff --git a/Services/Admin/Pages/DungeonBuilder/Palettes.cshtml.cs b/Services/Admin/Pages/DungeonBuilder/Palettes.cshtml.cs new file mode 100644 index 0000000..fe7534b --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/Palettes.cshtml.cs @@ -0,0 +1,41 @@ +using DataServer.Data; +using DataServer.Data.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Server.Services.Admin.Pages.DungeonBuilder; + +public class PalettesModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public PalettesModel(GameDbContext db) + { + _db = db; + } + + public List Palettes { get; set; } = new(); + + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync() + { + Palettes = await _db.DungeonPalettes + .OrderBy(p => p.Name) + .ToListAsync(); + } + + public async Task OnPostDeleteAsync(int id) + { + var palette = await _db.DungeonPalettes.FindAsync(id); + if (palette != null) + { + _db.DungeonPalettes.Remove(palette); + await _db.SaveChangesAsync(); + Message = $"Deleted palette: {palette.Name}"; + } + + return RedirectToPage(); + } +} diff --git a/Services/Admin/Pages/DungeonBuilder/TileEdit.cshtml b/Services/Admin/Pages/DungeonBuilder/TileEdit.cshtml new file mode 100644 index 0000000..dd11ae1 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/TileEdit.cshtml @@ -0,0 +1,498 @@ +@page "/admin/dungeonbuilder/tiles/edit" +@model DungeonBuilder.TileEditModel +@using DataServer.Data.Entities +@{ + ViewData["Title"] = Model.Tile.Id == 0 ? "New Tile Template" : $"Edit: {Model.Tile.Name}"; + var categories = Enum.GetValues(); + var socketTypes = Enum.GetValues(); +} + + + + + +

@ViewData["Title"]

+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +
+ @Model.Message +
+} + +
+ @Html.AntiForgeryToken() + + + + +
+ +
+
+

Basic Settings

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

Size

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

Use 1Γ—1 for simple tiles, larger for patterns like pillars or wall corners.

+
+ +
+

Properties

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

Generation

+
+
+ + +

Higher = more common

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

Template Pattern

+ +
+ +
+
+
+ +

Click cells to paint with selected tile. First tile placed becomes the primary.

+
+ + +
+

Edge Sockets

+

Sockets control how this template connects to neighbors.

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

Tile Palette

+ +
+ +
+ +
+
Select a sprite sheet
+
+
+ +
+

Selected Tile

+
None
+
+ - +
+
+ + +
+

Quick Fill

+
+ + +
+
+
+
+ +
+ Cancel + +
+
+ + diff --git a/Services/Admin/Pages/DungeonBuilder/TileEdit.cshtml.cs b/Services/Admin/Pages/DungeonBuilder/TileEdit.cshtml.cs new file mode 100644 index 0000000..3b73217 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/TileEdit.cshtml.cs @@ -0,0 +1,149 @@ +using DataServer.Data; +using DataServer.Data.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Server.Services.Admin.Pages.DungeonBuilder; + +public class TileEditModel : AdminPageModel +{ + private readonly GameDbContext _db; + private readonly IConfiguration _config; + + public TileEditModel(GameDbContext db, IConfiguration config) + { + _db = db; + _config = config; + } + + [BindProperty] + public TileTemplate Tile { get; set; } = new(); + + public List TileSheets { get; set; } = new(); + + public string CdnBaseUrl;// => _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? ""; + + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync(int? id) + { + CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"] ?? "https://assets.aeternalisgames.com"); + await LoadReferenceData(); + + if (id.HasValue) + { + var tile = await _db.TileTemplates + .Include(t => t.PrimaryTileDefinition) + .ThenInclude(td => td!.TileMapSheet) + .FirstOrDefaultAsync(t => t.Id == id.Value); + + if (tile != null) + { + Tile = tile; + } + } + else + { + // Defaults + Tile.IsEnabled = true; + Tile.Width = 1; + Tile.Height = 1; + Tile.Weight = 100; + Tile.MinTier = 1; + Tile.IsWalkable = true; + Tile.SocketN = SocketType.Open; + Tile.SocketE = SocketType.Open; + Tile.SocketS = SocketType.Open; + Tile.SocketW = SocketType.Open; + } + } + + public async Task OnPostAsync() + { + await LoadReferenceData(); + + if (string.IsNullOrWhiteSpace(Tile.Name)) + { + IsError = true; + Message = "Name is required."; + return Page(); + } + + Tile.UpdatedAt = DateTime.UtcNow; + + // Handle nullable primary tile + if (string.IsNullOrEmpty(Request.Form["Tile.PrimaryTileDefinitionId"])) + { + Tile.PrimaryTileDefinitionId = null; + } + + if (Tile.Id == 0) + { + Tile.CreatedAt = DateTime.UtcNow; + _db.TileTemplates.Add(Tile); + Message = "Tile template created!"; + } + else + { + var existing = await _db.TileTemplates.FindAsync(Tile.Id); + if (existing == null) + { + IsError = true; + Message = "Tile template not found."; + return Page(); + } + + existing.Name = Tile.Name; + existing.Description = Tile.Description; + existing.Category = Tile.Category; + existing.Tags = Tile.Tags; + existing.Biome = Tile.Biome; + existing.Width = Tile.Width; + existing.Height = Tile.Height; + existing.TilesJson = Tile.TilesJson; + existing.PrimaryTileDefinitionId = Tile.PrimaryTileDefinitionId; + existing.IsWalkable = Tile.IsWalkable; + existing.BlocksProjectiles = Tile.BlocksProjectiles; + existing.BlocksLineOfSight = Tile.BlocksLineOfSight; + existing.BlocksMovement = Tile.BlocksMovement; + existing.SocketN = Tile.SocketN; + existing.SocketE = Tile.SocketE; + existing.SocketS = Tile.SocketS; + existing.SocketW = Tile.SocketW; + existing.SocketCustom = Tile.SocketCustom; + existing.Weight = Tile.Weight; + existing.MinTier = Tile.MinTier; + existing.MaxTier = Tile.MaxTier; + existing.IsEnabled = Tile.IsEnabled; + existing.UpdatedAt = DateTime.UtcNow; + + Message = "Changes saved!"; + } + + await _db.SaveChangesAsync(); + + return RedirectToPage(new { id = Tile.Id }); + } + + private async Task LoadReferenceData() + { + TileSheets = await _db.TileMapSheets + .Where(s => s.IsEnabled) + .OrderBy(s => s.Name) + .ToListAsync(); + } + private static string NormalizeCdnBaseUrl(string? baseUrl) + { + baseUrl = string.IsNullOrWhiteSpace(baseUrl) + ? "https://assets.aeternalisgames.com" + : baseUrl; + + baseUrl = baseUrl.TrimEnd('/'); + + if (!baseUrl.EndsWith("/downloads", StringComparison.OrdinalIgnoreCase)) + baseUrl += "/downloads"; + + return baseUrl; + } +}