Dungeon Builder WIP...p2
This commit is contained in:
@@ -24,15 +24,16 @@ public class ObjectEditModel : AdminPageModel
|
||||
public List<DamageResistanceType> DamageTypes { get; set; } = new();
|
||||
public List<string> 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<IActionResult> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}";
|
||||
}
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/admin/dungeonbuilder/palettes" class="text-blue-400 hover:text-blue-300 text-sm">← Back to Palettes</a>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-bold text-white mb-6">@ViewData["Title"]</h1>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="mb-4 p-3 rounded @(Model.IsError ? "bg-red-900/50 text-red-300" : "bg-green-900/50 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Palette.Id" />
|
||||
<input type="hidden" asp-for="Palette.FloorTemplateIdsJson" id="floorIds" />
|
||||
<input type="hidden" asp-for="Palette.WallTemplateIdsJson" id="wallIds" />
|
||||
<input type="hidden" asp-for="Palette.DoorTemplateIdsJson" id="doorIds" />
|
||||
<input type="hidden" asp-for="Palette.DecorationIdsJson" id="decorIds" />
|
||||
<input type="hidden" asp-for="Palette.ContainerIdsJson" id="containerIds" />
|
||||
<input type="hidden" asp-for="Palette.TrapIdsJson" id="trapIds" />
|
||||
<input type="hidden" asp-for="Palette.RoomTemplateIdsJson" id="roomIds" />
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
<!-- Left: Basic Settings -->
|
||||
<div class="space-y-4">
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Basic Settings</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Name *</label>
|
||||
<input type="text" asp-for="Palette.Name" class="input w-full text-sm" required placeholder="Stone Dungeon" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Description</label>
|
||||
<textarea asp-for="Palette.Description" rows="2" class="input w-full text-sm" placeholder="Classic stone dungeon theme..."></textarea>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Biome</label>
|
||||
<input type="text" asp-for="Palette.Biome" class="input w-full text-sm" placeholder="dungeon" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Tags</label>
|
||||
<input type="text" asp-for="Palette.Tags" class="input w-full text-sm" placeholder="stone,dark" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Palette.IsEnabled" class="rounded" />
|
||||
<label class="text-sm text-gray-300">Enabled</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Room Generation</h3>
|
||||
<div class="space-y-3">
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Min Rooms</label>
|
||||
<input type="number" asp-for="Palette.MinRooms" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Max Rooms</label>
|
||||
<input type="number" asp-for="Palette.MaxRooms" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Min Room W</label>
|
||||
<input type="number" asp-for="Palette.MinRoomWidth" class="input w-full text-sm" min="3" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Max Room W</label>
|
||||
<input type="number" asp-for="Palette.MaxRoomWidth" class="input w-full text-sm" min="3" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Min Room H</label>
|
||||
<input type="number" asp-for="Palette.MinRoomHeight" class="input w-full text-sm" min="3" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Max Room H</label>
|
||||
<input type="number" asp-for="Palette.MaxRoomHeight" class="input w-full text-sm" min="3" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Min Corridor W</label>
|
||||
<input type="number" asp-for="Palette.MinCorridorWidth" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Max Corridor W</label>
|
||||
<input type="number" asp-for="Palette.MaxCorridorWidth" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Density Settings</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Decoration Density (0-100)</label>
|
||||
<input type="range" asp-for="Palette.DecorationDensity" min="0" max="100" class="w-full" />
|
||||
<div class="text-xs text-gray-500 text-right">@Model.Palette.DecorationDensity%</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Container Density (0-100)</label>
|
||||
<input type="range" asp-for="Palette.ContainerDensity" min="0" max="100" class="w-full" />
|
||||
<div class="text-xs text-gray-500 text-right">@Model.Palette.ContainerDensity%</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Trap Density (0-100)</label>
|
||||
<input type="range" asp-for="Palette.TrapDensity" min="0" max="100" class="w-full" />
|
||||
<div class="text-xs text-gray-500 text-right">@Model.Palette.TrapDensity%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Center: Tile Templates -->
|
||||
<div class="space-y-4">
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">🧱 Floor Templates</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Select tile templates to use for floors</p>
|
||||
<div class="space-y-2 max-h-[200px] overflow-auto" id="floorList">
|
||||
@foreach (var tile in Model.FloorTiles)
|
||||
{
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-800 rounded hover:bg-gray-700 cursor-pointer">
|
||||
<input type="checkbox" class="rounded floor-check" value="@tile.Id"
|
||||
@(Model.SelectedFloorIds.Contains(tile.Id) ? "checked" : "") />
|
||||
<span class="text-sm text-gray-300">@tile.Name</span>
|
||||
<span class="text-xs text-gray-500 ml-auto">W:@tile.Weight</span>
|
||||
</label>
|
||||
}
|
||||
@if (!Model.FloorTiles.Any())
|
||||
{
|
||||
<div class="text-xs text-gray-500 p-2">No floor templates. Create some first!</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">🧱 Wall Templates</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Select tile templates to use for walls</p>
|
||||
<div class="space-y-2 max-h-[200px] overflow-auto" id="wallList">
|
||||
@foreach (var tile in Model.WallTiles)
|
||||
{
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-800 rounded hover:bg-gray-700 cursor-pointer">
|
||||
<input type="checkbox" class="rounded wall-check" value="@tile.Id"
|
||||
@(Model.SelectedWallIds.Contains(tile.Id) ? "checked" : "") />
|
||||
<span class="text-sm text-gray-300">@tile.Name</span>
|
||||
<span class="text-xs text-gray-500 ml-auto">W:@tile.Weight</span>
|
||||
</label>
|
||||
}
|
||||
@if (!Model.WallTiles.Any())
|
||||
{
|
||||
<div class="text-xs text-gray-500 p-2">No wall templates. Create some first!</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">🚪 Door Templates</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Select tile templates to use for doors</p>
|
||||
<div class="space-y-2 max-h-[150px] overflow-auto" id="doorList">
|
||||
@foreach (var tile in Model.DoorTiles)
|
||||
{
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-800 rounded hover:bg-gray-700 cursor-pointer">
|
||||
<input type="checkbox" class="rounded door-check" value="@tile.Id"
|
||||
@(Model.SelectedDoorIds.Contains(tile.Id) ? "checked" : "") />
|
||||
<span class="text-sm text-gray-300">@tile.Name</span>
|
||||
</label>
|
||||
}
|
||||
@if (!Model.DoorTiles.Any())
|
||||
{
|
||||
<div class="text-xs text-gray-500 p-2">No door templates.</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">🗺️ Room Templates</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Pre-built rooms to include</p>
|
||||
<div class="space-y-2 max-h-[150px] overflow-auto" id="roomList">
|
||||
@foreach (var room in Model.Rooms)
|
||||
{
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-800 rounded hover:bg-gray-700 cursor-pointer">
|
||||
<input type="checkbox" class="rounded room-check" value="@room.Id"
|
||||
@(Model.SelectedRoomIds.Contains(room.Id) ? "checked" : "") />
|
||||
<span class="text-sm text-gray-300">@room.Name</span>
|
||||
<span class="text-xs text-gray-500 ml-auto">@room.Type</span>
|
||||
</label>
|
||||
}
|
||||
@if (!Model.Rooms.Any())
|
||||
{
|
||||
<div class="text-xs text-gray-500 p-2">No room templates.</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: Object Templates -->
|
||||
<div class="space-y-4">
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">🪨 Decorations</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Objects placed as decoration</p>
|
||||
<div class="space-y-2 max-h-[200px] overflow-auto" id="decorList">
|
||||
@foreach (var obj in Model.Decorations)
|
||||
{
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-800 rounded hover:bg-gray-700 cursor-pointer">
|
||||
<input type="checkbox" class="rounded decor-check" value="@obj.Id"
|
||||
@(Model.SelectedDecorationIds.Contains(obj.Id) ? "checked" : "") />
|
||||
<span class="text-sm text-gray-300">@obj.Name</span>
|
||||
</label>
|
||||
}
|
||||
@if (!Model.Decorations.Any())
|
||||
{
|
||||
<div class="text-xs text-gray-500 p-2">No decoration objects.</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">📦 Containers</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Chests, barrels, crates</p>
|
||||
<div class="space-y-2 max-h-[200px] overflow-auto" id="containerList">
|
||||
@foreach (var obj in Model.Containers)
|
||||
{
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-800 rounded hover:bg-gray-700 cursor-pointer">
|
||||
<input type="checkbox" class="rounded container-check" value="@obj.Id"
|
||||
@(Model.SelectedContainerIds.Contains(obj.Id) ? "checked" : "") />
|
||||
<span class="text-sm text-gray-300">@obj.Name</span>
|
||||
</label>
|
||||
}
|
||||
@if (!Model.Containers.Any())
|
||||
{
|
||||
<div class="text-xs text-gray-500 p-2">No container objects.</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">⚠️ Traps</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Hazards and traps</p>
|
||||
<div class="space-y-2 max-h-[200px] overflow-auto" id="trapList">
|
||||
@foreach (var obj in Model.Traps)
|
||||
{
|
||||
<label class="flex items-center gap-2 p-2 bg-gray-800 rounded hover:bg-gray-700 cursor-pointer">
|
||||
<input type="checkbox" class="rounded trap-check" value="@obj.Id"
|
||||
@(Model.SelectedTrapIds.Contains(obj.Id) ? "checked" : "") />
|
||||
<span class="text-sm text-gray-300">@obj.Name</span>
|
||||
</label>
|
||||
}
|
||||
@if (!Model.Traps.Any())
|
||||
{
|
||||
<div class="text-xs text-gray-500 p-2">No trap objects.</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-4 mt-6">
|
||||
<a href="/admin/dungeonbuilder/palettes" class="btn btn-ghost">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
@(Model.Palette.Id == 0 ? "Create Palette" : "Save Changes")
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
function collectIds(selector) {
|
||||
return Array.from(document.querySelectorAll(selector + ':checked')).map(cb => parseInt(cb.value));
|
||||
}
|
||||
|
||||
function saveSelections() {
|
||||
document.getElementById('floorIds').value = JSON.stringify(collectIds('.floor-check'));
|
||||
document.getElementById('wallIds').value = JSON.stringify(collectIds('.wall-check'));
|
||||
document.getElementById('doorIds').value = JSON.stringify(collectIds('.door-check'));
|
||||
document.getElementById('decorIds').value = JSON.stringify(collectIds('.decor-check'));
|
||||
document.getElementById('containerIds').value = JSON.stringify(collectIds('.container-check'));
|
||||
document.getElementById('trapIds').value = JSON.stringify(collectIds('.trap-check'));
|
||||
document.getElementById('roomIds').value = JSON.stringify(collectIds('.room-check'));
|
||||
}
|
||||
|
||||
document.querySelector('form').onsubmit = () => saveSelections();
|
||||
</script>
|
||||
@@ -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<TileTemplate> FloorTiles { get; set; } = new();
|
||||
public List<TileTemplate> WallTiles { get; set; } = new();
|
||||
public List<TileTemplate> DoorTiles { get; set; } = new();
|
||||
public List<ObjectTemplate> Decorations { get; set; } = new();
|
||||
public List<ObjectTemplate> Containers { get; set; } = new();
|
||||
public List<ObjectTemplate> Traps { get; set; } = new();
|
||||
public List<BuilderRoomTemplate> Rooms { get; set; } = new();
|
||||
|
||||
// Selected IDs
|
||||
public List<int> SelectedFloorIds { get; set; } = new();
|
||||
public List<int> SelectedWallIds { get; set; } = new();
|
||||
public List<int> SelectedDoorIds { get; set; } = new();
|
||||
public List<int> SelectedDecorationIds { get; set; } = new();
|
||||
public List<int> SelectedContainerIds { get; set; } = new();
|
||||
public List<int> SelectedTrapIds { get; set; } = new();
|
||||
public List<int> 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<IActionResult> 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<int> ParseIds(string? json)
|
||||
{
|
||||
if (string.IsNullOrEmpty(json)) return new List<int>();
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<List<int>>(json) ?? new List<int>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new List<int>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
@page "/admin/dungeonbuilder/palettes"
|
||||
@model DungeonBuilder.PalettesModel
|
||||
@{
|
||||
ViewData["Title"] = "Dungeon Palettes";
|
||||
}
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/admin/dungeonbuilder" class="text-blue-400 hover:text-blue-300 text-sm">← Back to Dungeon Builder</a>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-white">Dungeon Palettes</h1>
|
||||
<p class="text-gray-400 text-sm mt-1">Themed collections of templates for dungeon generation</p>
|
||||
</div>
|
||||
<a href="/admin/dungeonbuilder/palettes/edit" class="btn btn-primary">+ New Palette</a>
|
||||
</div>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="mb-4 p-3 rounded @(Model.IsError ? "bg-red-900/50 text-red-300" : "bg-green-900/50 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
@foreach (var palette in Model.Palettes)
|
||||
{
|
||||
<div class="card p-5 hover:border-yellow-500/50 transition-colors">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="flex-1">
|
||||
<h3 class="font-semibold text-white text-lg">@palette.Name</h3>
|
||||
@if (!string.IsNullOrEmpty(palette.Biome))
|
||||
{
|
||||
<span class="text-xs text-yellow-400">@palette.Biome</span>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(palette.Description))
|
||||
{
|
||||
<p class="text-sm text-gray-400 mt-2">@palette.Description</p>
|
||||
}
|
||||
</div>
|
||||
<div class="w-12 h-12 bg-yellow-500/20 rounded-lg flex items-center justify-center text-2xl">
|
||||
🎨
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-2 mt-4 text-xs text-gray-400">
|
||||
<div class="bg-gray-800 rounded p-2 text-center">
|
||||
<div class="text-lg font-semibold text-white">@palette.MinRooms-@palette.MaxRooms</div>
|
||||
<div>Rooms</div>
|
||||
</div>
|
||||
<div class="bg-gray-800 rounded p-2 text-center">
|
||||
<div class="text-lg font-semibold text-white">@palette.DecorationDensity%</div>
|
||||
<div>Decor</div>
|
||||
</div>
|
||||
<div class="bg-gray-800 rounded p-2 text-center">
|
||||
<div class="text-lg font-semibold text-white">@palette.TrapDensity%</div>
|
||||
<div>Traps</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mt-4 pt-4 border-t border-gray-700">
|
||||
<span class="text-xs text-gray-500">ID: @palette.Id</span>
|
||||
<div class="flex gap-3">
|
||||
<a href="/admin/dungeonbuilder/palettes/edit?id=@palette.Id" class="text-blue-400 hover:text-blue-300 text-sm">Edit</a>
|
||||
<form method="post" asp-page-handler="Delete" class="inline" onsubmit="return confirm('Delete this palette?');">
|
||||
<input type="hidden" name="id" value="@palette.Id" />
|
||||
<button type="submit" class="text-red-400 hover:text-red-300 text-sm">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!Model.Palettes.Any())
|
||||
{
|
||||
<div class="col-span-full card p-8 text-center text-gray-500">
|
||||
No palettes found. <a href="/admin/dungeonbuilder/palettes/edit" class="text-blue-400 hover:underline">Create one</a>!
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -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<DungeonPalette> 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<IActionResult> 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();
|
||||
}
|
||||
}
|
||||
@@ -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<TileTemplateCategory>();
|
||||
var socketTypes = Enum.GetValues<SocketType>();
|
||||
}
|
||||
|
||||
<style>
|
||||
.tile-grid {
|
||||
display: grid;
|
||||
gap: 1px;
|
||||
background: #1a1a2e;
|
||||
border: 2px solid #374151;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.tile-cell {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: #0f0f1a;
|
||||
cursor: crosshair;
|
||||
position: relative;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
.tile-cell:hover {
|
||||
outline: 2px solid #60a5fa;
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.palette-tile {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
cursor: pointer;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 2px;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
.palette-tile:hover { border-color: #60a5fa; }
|
||||
.palette-tile.active { border-color: #fbbf24; }
|
||||
.socket-indicator {
|
||||
position: absolute;
|
||||
background: rgba(0,0,0,0.7);
|
||||
font-size: 8px;
|
||||
padding: 1px 3px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.socket-n { top: 0; left: 50%; transform: translateX(-50%); }
|
||||
.socket-e { right: 0; top: 50%; transform: translateY(-50%); }
|
||||
.socket-s { bottom: 0; left: 50%; transform: translateX(-50%); }
|
||||
.socket-w { left: 0; top: 50%; transform: translateY(-50%); }
|
||||
.socket-open { color: #4ade80; }
|
||||
.socket-closed { color: #f87171; }
|
||||
.socket-custom { color: #facc15; }
|
||||
</style>
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/admin/dungeonbuilder/tiles" class="text-blue-400 hover:text-blue-300 text-sm">← Back to Tiles</a>
|
||||
</div>
|
||||
|
||||
<h1 class="text-2xl font-bold text-white mb-6">@ViewData["Title"]</h1>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Message))
|
||||
{
|
||||
<div class="mb-4 p-3 rounded @(Model.IsError ? "bg-red-900/50 text-red-300" : "bg-green-900/50 text-green-300")">
|
||||
@Model.Message
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post" id="tileForm">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Tile.Id" />
|
||||
<input type="hidden" asp-for="Tile.TilesJson" id="tilesJson" />
|
||||
<input type="hidden" asp-for="Tile.PrimaryTileDefinitionId" id="primaryTileId" />
|
||||
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
<!-- Left: Settings -->
|
||||
<div class="space-y-4">
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Basic Settings</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Name *</label>
|
||||
<input type="text" asp-for="Tile.Name" class="input w-full text-sm" required placeholder="Stone Floor Clean" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Category</label>
|
||||
<select asp-for="Tile.Category" class="input w-full text-sm" onchange="onCategoryChange()">
|
||||
@foreach (var c in categories)
|
||||
{
|
||||
<option value="@c">@c</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Biome</label>
|
||||
<input type="text" asp-for="Tile.Biome" class="input w-full text-sm" placeholder="dungeon" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Tags</label>
|
||||
<input type="text" asp-for="Tile.Tags" class="input w-full text-sm" placeholder="stone,clean" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Size</h3>
|
||||
<div class="grid grid-cols-2 gap-2 mb-3">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Width</label>
|
||||
<input type="number" asp-for="Tile.Width" class="input w-full text-sm" min="1" max="10" id="tileWidth" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Height</label>
|
||||
<input type="number" asp-for="Tile.Height" class="input w-full text-sm" min="1" max="10" id="tileHeight" />
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="resizeTemplate()" class="btn btn-secondary w-full text-sm">Resize</button>
|
||||
<p class="text-xs text-gray-500 mt-2">Use 1×1 for simple tiles, larger for patterns like pillars or wall corners.</p>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Properties</h3>
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Tile.IsWalkable" class="rounded" id="isWalkable" />
|
||||
<label class="text-sm text-gray-300">Walkable</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Tile.BlocksMovement" class="rounded" />
|
||||
<label class="text-sm text-gray-300">Blocks Movement</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Tile.BlocksProjectiles" class="rounded" />
|
||||
<label class="text-sm text-gray-300">Blocks Projectiles</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Tile.BlocksLineOfSight" class="rounded" />
|
||||
<label class="text-sm text-gray-300">Blocks Line of Sight</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Generation</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Weight</label>
|
||||
<input type="number" asp-for="Tile.Weight" class="input w-full text-sm" min="1" />
|
||||
<p class="text-xs text-gray-500 mt-1">Higher = more common</p>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Min Tier</label>
|
||||
<input type="number" asp-for="Tile.MinTier" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Max Tier</label>
|
||||
<input type="number" asp-for="Tile.MaxTier" class="input w-full text-sm" min="0" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Tile.IsEnabled" class="rounded" />
|
||||
<label class="text-sm text-gray-300">Enabled</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Center: Template Grid -->
|
||||
<div class="space-y-4">
|
||||
<div class="card p-4">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<h3 class="font-semibold text-white">Template Pattern</h3>
|
||||
<button type="button" onclick="clearTemplate()" class="text-xs text-gray-400 hover:text-white">Clear</button>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-900 rounded p-4 flex justify-center">
|
||||
<div id="templateGrid" class="tile-grid inline-grid"></div>
|
||||
</div>
|
||||
|
||||
<p class="text-xs text-gray-500 mt-2">Click cells to paint with selected tile. First tile placed becomes the primary.</p>
|
||||
</div>
|
||||
|
||||
<!-- Socket Configuration -->
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Edge Sockets</h3>
|
||||
<p class="text-xs text-gray-500 mb-3">Sockets control how this template connects to neighbors.</p>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">North</label>
|
||||
<select asp-for="Tile.SocketN" class="input w-full text-sm">
|
||||
@foreach (var s in socketTypes) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">East</label>
|
||||
<select asp-for="Tile.SocketE" class="input w-full text-sm">
|
||||
@foreach (var s in socketTypes) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">South</label>
|
||||
<select asp-for="Tile.SocketS" class="input w-full text-sm">
|
||||
@foreach (var s in socketTypes) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">West</label>
|
||||
<select asp-for="Tile.SocketW" class="input w-full text-sm">
|
||||
@foreach (var s in socketTypes) { <option value="@s">@s</option> }
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
<label class="text-xs text-gray-400">Custom Socket Names (comma-separated: N,E,S,W)</label>
|
||||
<input type="text" asp-for="Tile.SocketCustom" class="input w-full text-sm" placeholder="wall-edge,wall-edge,open,open" />
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 mt-3">
|
||||
<button type="button" onclick="setAllSockets('Open')" class="btn btn-ghost text-xs flex-1">All Open</button>
|
||||
<button type="button" onclick="setAllSockets('Closed')" class="btn btn-ghost text-xs flex-1">All Closed</button>
|
||||
<button type="button" onclick="autoSockets()" class="btn btn-ghost text-xs flex-1">Auto</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: Tile Palette -->
|
||||
<div class="space-y-4">
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Tile Palette</h3>
|
||||
|
||||
<div class="mb-3">
|
||||
<select id="sheetSelect" class="input w-full text-sm" onchange="loadSheet()">
|
||||
<option value="">Select sprite sheet...</option>
|
||||
@foreach (var sheet in Model.TileSheets)
|
||||
{
|
||||
<option value="@sheet.Id"
|
||||
data-cdn="@sheet.CdnPath"
|
||||
data-cols="@sheet.Columns"
|
||||
data-tw="@sheet.TileWidth"
|
||||
data-th="@sheet.TileHeight"
|
||||
data-sw="@sheet.SheetWidth"
|
||||
data-sh="@sheet.SheetHeight">@sheet.Name</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="palette" class="flex flex-wrap gap-1 max-h-[400px] overflow-auto bg-gray-900 rounded p-2">
|
||||
<div class="text-gray-500 text-xs p-2">Select a sprite sheet</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-2">Selected Tile</h3>
|
||||
<div id="selectedInfo" class="text-sm text-gray-400">None</div>
|
||||
<div id="selectedPreview" class="mt-2 bg-gray-900 rounded p-2 h-12 flex items-center justify-center">
|
||||
<span class="text-gray-600">-</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick Templates -->
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Quick Fill</h3>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<button type="button" onclick="fillAll()" class="btn btn-secondary text-xs">Fill All</button>
|
||||
<button type="button" onclick="fillBorder()" class="btn btn-secondary text-xs">Fill Border</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-4 mt-6">
|
||||
<a href="/admin/dungeonbuilder/tiles" class="btn btn-ghost">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
@(Model.Tile.Id == 0 ? "Create Template" : "Save Changes")
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
const cdnBase = '@Model.CdnBaseUrl';
|
||||
let tw = @Model.Tile.Width, th = @Model.Tile.Height;
|
||||
let sheet = null;
|
||||
let selected = null;
|
||||
let templateData = {}; // { "x,y": { sheetId, frameIndex, tileDefId } }
|
||||
let primarySet = false;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadExisting();
|
||||
buildTemplateGrid();
|
||||
});
|
||||
|
||||
function loadExisting() {
|
||||
const json = document.getElementById('tilesJson').value;
|
||||
if (json) {
|
||||
try {
|
||||
JSON.parse(json).forEach(t => {
|
||||
templateData[`${t.x},${t.y}`] = { sheetId: t.sheetId, frameIndex: t.frameIndex, tileDefId: t.tileDefId };
|
||||
});
|
||||
primarySet = Object.keys(templateData).length > 0;
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
function buildTemplateGrid() {
|
||||
const grid = document.getElementById('templateGrid');
|
||||
grid.style.gridTemplateColumns = `repeat(${tw}, 32px)`;
|
||||
grid.innerHTML = '';
|
||||
|
||||
for (let y = 0; y < th; y++) {
|
||||
for (let x = 0; x < tw; x++) {
|
||||
const cell = document.createElement('div');
|
||||
cell.className = 'tile-cell';
|
||||
cell.dataset.x = x;
|
||||
cell.dataset.y = y;
|
||||
cell.onclick = () => paintCell(x, y);
|
||||
grid.appendChild(cell);
|
||||
renderCell(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderCell(x, y) {
|
||||
const cell = document.querySelector(`.tile-cell[data-x="${x}"][data-y="${y}"]`);
|
||||
if (!cell) return;
|
||||
|
||||
const data = templateData[`${x},${y}`];
|
||||
if (data && sheet && data.sheetId == sheet.id) {
|
||||
const col = data.frameIndex % sheet.cols;
|
||||
const row = Math.floor(data.frameIndex / sheet.cols);
|
||||
cell.style.background = `url('${cdnBase}/downloads/${sheet.cdn}') ${-col * sheet.tw}px ${-row * sheet.th}px no-repeat`;
|
||||
cell.style.backgroundSize = `${sheet.sw}px ${sheet.sh}px`;
|
||||
} else if (data) {
|
||||
cell.style.background = '#2d3748';
|
||||
} else {
|
||||
cell.style.background = '#0f0f1a';
|
||||
}
|
||||
}
|
||||
|
||||
function paintCell(x, y) {
|
||||
if (!selected) return;
|
||||
|
||||
const key = `${x},${y}`;
|
||||
templateData[key] = { sheetId: selected.sheetId, frameIndex: selected.frameIndex };
|
||||
|
||||
// First tile becomes primary
|
||||
if (!primarySet) {
|
||||
document.getElementById('primaryTileId').value = selected.tileDefId || '';
|
||||
primarySet = true;
|
||||
}
|
||||
|
||||
renderCell(x, y);
|
||||
saveData();
|
||||
}
|
||||
|
||||
function loadSheet() {
|
||||
const opt = document.getElementById('sheetSelect').selectedOptions[0];
|
||||
if (!opt?.value) {
|
||||
sheet = null;
|
||||
document.getElementById('palette').innerHTML = '<div class="text-gray-500 text-xs p-2">Select a sprite sheet</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
sheet = {
|
||||
id: +opt.value,
|
||||
cdn: opt.dataset.cdn,
|
||||
cols: +opt.dataset.cols,
|
||||
tw: +opt.dataset.tw,
|
||||
th: +opt.dataset.th,
|
||||
sw: +opt.dataset.sw,
|
||||
sh: +opt.dataset.sh
|
||||
};
|
||||
|
||||
const total = sheet.cols * Math.ceil(sheet.sh / sheet.th);
|
||||
let html = '';
|
||||
for (let i = 0; i < total; i++) {
|
||||
const col = i % sheet.cols;
|
||||
const row = Math.floor(i / sheet.cols);
|
||||
html += `<div class="palette-tile" data-frame="${i}" onclick="selectTile(${i})"
|
||||
style="background: url('${cdnBase}/downloads/${sheet.cdn}') ${-col * sheet.tw}px ${-row * sheet.th}px no-repeat;
|
||||
background-size: ${sheet.sw}px ${sheet.sh}px;"></div>`;
|
||||
}
|
||||
document.getElementById('palette').innerHTML = html;
|
||||
|
||||
// Re-render template with new sheet
|
||||
for (let y = 0; y < th; y++) {
|
||||
for (let x = 0; x < tw; x++) {
|
||||
renderCell(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function selectTile(frameIndex) {
|
||||
document.querySelectorAll('.palette-tile').forEach(t => t.classList.remove('active'));
|
||||
document.querySelector(`.palette-tile[data-frame="${frameIndex}"]`)?.classList.add('active');
|
||||
|
||||
selected = { sheetId: sheet.id, frameIndex };
|
||||
|
||||
document.getElementById('selectedInfo').textContent = `Frame ${frameIndex}`;
|
||||
|
||||
const col = frameIndex % sheet.cols;
|
||||
const row = Math.floor(frameIndex / sheet.cols);
|
||||
document.getElementById('selectedPreview').innerHTML = `
|
||||
<div style="width: ${sheet.tw}px; height: ${sheet.th}px;
|
||||
background: url('${cdnBase}/downloads/${sheet.cdn}') ${-col * sheet.tw}px ${-row * sheet.th}px no-repeat;
|
||||
background-size: ${sheet.sw}px ${sheet.sh}px;
|
||||
image-rendering: pixelated;"></div>
|
||||
`;
|
||||
}
|
||||
|
||||
function resizeTemplate() {
|
||||
tw = +document.getElementById('tileWidth').value || 1;
|
||||
th = +document.getElementById('tileHeight').value || 1;
|
||||
tw = Math.max(1, Math.min(10, tw));
|
||||
th = Math.max(1, Math.min(10, th));
|
||||
buildTemplateGrid();
|
||||
}
|
||||
|
||||
function clearTemplate() {
|
||||
if (!confirm('Clear all tiles?')) return;
|
||||
templateData = {};
|
||||
primarySet = false;
|
||||
document.getElementById('primaryTileId').value = '';
|
||||
buildTemplateGrid();
|
||||
saveData();
|
||||
}
|
||||
|
||||
function fillAll() {
|
||||
if (!selected) { alert('Select a tile first'); return; }
|
||||
for (let y = 0; y < th; y++) {
|
||||
for (let x = 0; x < tw; x++) {
|
||||
templateData[`${x},${y}`] = { ...selected };
|
||||
}
|
||||
}
|
||||
if (!primarySet) {
|
||||
document.getElementById('primaryTileId').value = '';
|
||||
primarySet = true;
|
||||
}
|
||||
buildTemplateGrid();
|
||||
saveData();
|
||||
}
|
||||
|
||||
function fillBorder() {
|
||||
if (!selected) { alert('Select a tile first'); return; }
|
||||
for (let x = 0; x < tw; x++) {
|
||||
templateData[`${x},0`] = { ...selected };
|
||||
templateData[`${x},${th-1}`] = { ...selected };
|
||||
}
|
||||
for (let y = 0; y < th; y++) {
|
||||
templateData[`0,${y}`] = { ...selected };
|
||||
templateData[`${tw-1},${y}`] = { ...selected };
|
||||
}
|
||||
buildTemplateGrid();
|
||||
saveData();
|
||||
}
|
||||
|
||||
function setAllSockets(type) {
|
||||
document.querySelector('[name="Tile.SocketN"]').value = type;
|
||||
document.querySelector('[name="Tile.SocketE"]').value = type;
|
||||
document.querySelector('[name="Tile.SocketS"]').value = type;
|
||||
document.querySelector('[name="Tile.SocketW"]').value = type;
|
||||
}
|
||||
|
||||
function autoSockets() {
|
||||
const cat = document.querySelector('[name="Tile.Category"]').value;
|
||||
if (cat === 'Floor' || cat === 'Decoration') {
|
||||
setAllSockets('Open');
|
||||
document.getElementById('isWalkable').checked = true;
|
||||
} else if (cat === 'Wall') {
|
||||
setAllSockets('Closed');
|
||||
document.getElementById('isWalkable').checked = false;
|
||||
} else if (cat === 'Door') {
|
||||
// Vertical door default
|
||||
document.querySelector('[name="Tile.SocketN"]').value = 'Open';
|
||||
document.querySelector('[name="Tile.SocketS"]').value = 'Open';
|
||||
document.querySelector('[name="Tile.SocketE"]').value = 'Closed';
|
||||
document.querySelector('[name="Tile.SocketW"]').value = 'Closed';
|
||||
}
|
||||
}
|
||||
|
||||
function onCategoryChange() {
|
||||
autoSockets();
|
||||
}
|
||||
|
||||
function saveData() {
|
||||
const tiles = Object.entries(templateData).map(([k, v]) => {
|
||||
const [x, y] = k.split(',').map(Number);
|
||||
return { x, y, sheetId: v.sheetId, frameIndex: v.frameIndex, tileDefId: v.tileDefId };
|
||||
});
|
||||
document.getElementById('tilesJson').value = JSON.stringify(tiles);
|
||||
}
|
||||
|
||||
document.getElementById('tileForm').onsubmit = () => saveData();
|
||||
</script>
|
||||
@@ -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<TileMapSheet> 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<IActionResult> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user