DungeonBuilder UI Attempt.3
This commit is contained in:
@@ -269,7 +269,7 @@
|
||||
<option value="">-- None --</option>
|
||||
@foreach (var dt in Model.DamageTypes)
|
||||
{
|
||||
<option value="@dt.Key">@dt.DisplayName</option>
|
||||
<option value="@dt.Key">@dt.Name</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -156,7 +156,7 @@ public class ObjectEditModel : AdminPageModel
|
||||
.ToListAsync();
|
||||
|
||||
DamageTypes = await _db.DamageResistanceTypes
|
||||
.OrderBy(d => d.DisplayName)
|
||||
.OrderBy(d => d.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,465 @@
|
||||
@page "/admin/dungeonbuilder/rooms/edit"
|
||||
@model DungeonBuilder.RoomEditModel
|
||||
@using DataServer.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = Model.Room.Id == 0 ? "New Room Template" : $"Edit: {Model.Room.Name}";
|
||||
var roomTypes = Enum.GetValues<RoomType>();
|
||||
}
|
||||
|
||||
<style>
|
||||
.editor-grid {
|
||||
display: grid;
|
||||
gap: 1px;
|
||||
background: #1a1a2e;
|
||||
border: 2px solid #374151;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.editor-cell {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: #0f0f1a;
|
||||
cursor: crosshair;
|
||||
position: relative;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
.editor-cell:hover {
|
||||
outline: 2px solid #60a5fa;
|
||||
outline-offset: -2px;
|
||||
z-index: 10;
|
||||
}
|
||||
.palette-item {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
cursor: pointer;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 4px;
|
||||
background: #1f2937;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
.palette-item:hover { border-color: #60a5fa; }
|
||||
.palette-item.active { border-color: #fbbf24; background: #374151; }
|
||||
.tool-btn {
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
background: #1f2937;
|
||||
color: #d1d5db;
|
||||
border: 1px solid #374151;
|
||||
}
|
||||
.tool-btn:hover { background: #374151; }
|
||||
.tool-btn.active { background: #4f46e5; color: white; border-color: #4f46e5; }
|
||||
</style>
|
||||
|
||||
<div class="mb-4">
|
||||
<a href="/admin/dungeonbuilder/rooms" class="text-blue-400 hover:text-blue-300 text-sm">← Back to Rooms</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 xl:grid-cols-4 gap-4">
|
||||
<!-- Left Panel -->
|
||||
<div class="xl:col-span-1 space-y-4">
|
||||
<form method="post" id="roomForm">
|
||||
@Html.AntiForgeryToken()
|
||||
<input type="hidden" asp-for="Room.Id" />
|
||||
<input type="hidden" asp-for="Room.TileGridJson" id="tileGridJson" />
|
||||
<input type="hidden" asp-for="Room.ObjectPlacementsJson" id="objectPlacementsJson" />
|
||||
<input type="hidden" asp-for="Room.ConnectionPointsJson" id="connectionPointsJson" />
|
||||
<input type="hidden" asp-for="Room.MobSpawnsJson" id="mobSpawnsJson" />
|
||||
<input type="hidden" asp-for="Room.PlayerSpawnX" id="playerSpawnX" />
|
||||
<input type="hidden" asp-for="Room.PlayerSpawnY" id="playerSpawnY" />
|
||||
<input type="hidden" asp-for="Room.ExitPortalX" id="exitPortalX" />
|
||||
<input type="hidden" asp-for="Room.ExitPortalY" id="exitPortalY" />
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Room Settings</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Name</label>
|
||||
<input type="text" asp-for="Room.Name" class="input w-full text-sm" required />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Type</label>
|
||||
<select asp-for="Room.Type" class="input w-full text-sm">
|
||||
@foreach (var t in roomTypes)
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Width</label>
|
||||
<input type="number" asp-for="Room.Width" class="input w-full text-sm" min="3" max="50" id="roomWidth" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Height</label>
|
||||
<input type="number" asp-for="Room.Height" class="input w-full text-sm" min="3" max="50" id="roomHeight" />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Biome</label>
|
||||
<input type="text" asp-for="Room.Biome" class="input w-full text-sm" placeholder="dungeon" />
|
||||
</div>
|
||||
<button type="button" onclick="resizeGrid()" class="btn btn-secondary w-full text-sm">Resize Grid</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-3">Tools</h3>
|
||||
<div class="flex flex-wrap gap-2 mb-3">
|
||||
<button type="button" class="tool-btn active" data-tool="paint" onclick="setTool('paint')">🖌️ Paint</button>
|
||||
<button type="button" class="tool-btn" data-tool="erase" onclick="setTool('erase')">🧹 Erase</button>
|
||||
<button type="button" class="tool-btn" data-tool="fill" onclick="setTool('fill')">🪣 Fill</button>
|
||||
</div>
|
||||
<div class="border-t border-gray-700 pt-3">
|
||||
<label class="text-xs text-gray-400 mb-2 block">Layer</label>
|
||||
<div class="flex gap-1">
|
||||
<button type="button" class="tool-btn active flex-1 text-xs" data-layer="floor" onclick="setLayer('floor')">Floor</button>
|
||||
<button type="button" class="tool-btn flex-1 text-xs" data-layer="object" onclick="setLayer('object')">Object</button>
|
||||
<button type="button" class="tool-btn flex-1 text-xs" data-layer="spawn" onclick="setLayer('spawn')">Spawn</button>
|
||||
</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="Room.Weight" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Min Doors</label>
|
||||
<input type="number" asp-for="Room.MinConnections" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Max Doors</label>
|
||||
<input type="number" asp-for="Room.MaxConnections" class="input w-full text-sm" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Room.AllowRotation" class="rounded" />
|
||||
<label class="text-sm text-gray-300">Allow Rotation</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-full">
|
||||
@(Model.Room.Id == 0 ? "Create Room" : "Save Changes")
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Center: Grid -->
|
||||
<div class="xl:col-span-2">
|
||||
<div class="card p-4">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<h3 class="font-semibold text-white">Grid Editor</h3>
|
||||
<div class="flex gap-2">
|
||||
<button type="button" onclick="clearLayer()" class="text-xs text-gray-400 hover:text-white">Clear Layer</button>
|
||||
<button type="button" onclick="clearAll()" class="text-xs text-red-400 hover:text-red-300">Clear All</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overflow-auto bg-gray-900 rounded p-2" style="max-height: 75vh;">
|
||||
<div id="editorGrid" class="editor-grid inline-grid"></div>
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-gray-500 flex justify-between">
|
||||
<span id="cursorPos">(-, -)</span>
|
||||
<span id="statsInfo">Tiles: 0 | Objects: 0 | Spawns: 0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: Palette -->
|
||||
<div class="xl:col-span-1 space-y-4">
|
||||
<!-- Tile Palette -->
|
||||
<div class="card p-4" id="tilePaletteCard">
|
||||
<h3 class="font-semibold text-white mb-3">Tiles</h3>
|
||||
<select id="tileSheetSelect" class="input w-full text-sm mb-3" onchange="loadTilePalette()">
|
||||
<option value="">Select 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 id="tilePalette" class="flex flex-wrap gap-1 max-h-[250px] overflow-auto">
|
||||
<div class="text-gray-500 text-xs p-2">Select a sheet</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Object Palette -->
|
||||
<div class="card p-4 hidden" id="objectPaletteCard">
|
||||
<h3 class="font-semibold text-white mb-3">Objects</h3>
|
||||
<div id="objectPalette" class="flex flex-wrap gap-1 max-h-[250px] overflow-auto">
|
||||
@foreach (var obj in Model.Objects)
|
||||
{
|
||||
<div class="palette-item" data-type="object" data-id="@obj.Id" data-name="@obj.Name" title="@obj.Name" onclick="selectPaletteItem(this)">
|
||||
<span class="text-base">@GetObjIcon(obj.Type)</span>
|
||||
</div>
|
||||
}
|
||||
@if (!Model.Objects.Any())
|
||||
{
|
||||
<div class="text-gray-500 text-xs p-2">No objects. Create some first!</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Spawn Palette -->
|
||||
<div class="card p-4 hidden" id="spawnPaletteCard">
|
||||
<h3 class="font-semibold text-white mb-3">Spawns</h3>
|
||||
<div id="spawnPalette" class="flex flex-wrap gap-1">
|
||||
<div class="palette-item" data-type="spawn" data-spawn="player" title="Player Spawn" onclick="selectPaletteItem(this)">🧑</div>
|
||||
<div class="palette-item" data-type="spawn" data-spawn="exit" title="Exit Portal" onclick="selectPaletteItem(this)">🌀</div>
|
||||
<div class="palette-item" data-type="spawn" data-spawn="mob" title="Mob" onclick="selectPaletteItem(this)">👾</div>
|
||||
<div class="palette-item" data-type="spawn" data-spawn="elite" title="Elite" onclick="selectPaletteItem(this)">⭐</div>
|
||||
<div class="palette-item" data-type="spawn" data-spawn="boss" title="Boss" onclick="selectPaletteItem(this)">💀</div>
|
||||
<div class="palette-item" data-type="spawn" data-spawn="chest" title="Chest" onclick="selectPaletteItem(this)">📦</div>
|
||||
<div class="palette-item" data-type="spawn" data-spawn="door" title="Door/Connection" onclick="selectPaletteItem(this)">🚪</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Selected Info -->
|
||||
<div class="card p-4">
|
||||
<h3 class="font-semibold text-white mb-2">Selected</h3>
|
||||
<div id="selectionInfo" class="text-sm text-gray-400">Nothing</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const cdnBase = '@Model.CdnBaseUrl';
|
||||
let gw = @Model.Room.Width, gh = @Model.Room.Height;
|
||||
let tool = 'paint', layer = 'floor';
|
||||
let sel = null, sheet = null;
|
||||
let tileData = {}, objData = {}, spawnData = {};
|
||||
let mouseDown = false;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadData();
|
||||
buildGrid();
|
||||
});
|
||||
|
||||
function loadData() {
|
||||
try {
|
||||
const td = '@Html.Raw(Model.Room.TileGridJson ?? "[]")';
|
||||
JSON.parse(td).forEach(t => tileData[`${t.x},${t.y}`] = { sid: t.sheetId, f: t.frameIndex });
|
||||
} catch {}
|
||||
try {
|
||||
const od = '@Html.Raw(Model.Room.ObjectPlacementsJson ?? "[]")';
|
||||
JSON.parse(od).forEach(o => objData[`${o.X},${o.Y}`] = { id: o.ObjectTemplateId });
|
||||
} catch {}
|
||||
try {
|
||||
const md = '@Html.Raw(Model.Room.MobSpawnsJson ?? "[]")';
|
||||
JSON.parse(md).forEach(m => spawnData[`${m.X},${m.Y}`] = { t: m.Type });
|
||||
} catch {}
|
||||
@if (Model.Room.PlayerSpawnX.HasValue) { <text>spawnData['@Model.Room.PlayerSpawnX,@Model.Room.PlayerSpawnY'] = { t: 'player' };</text> }
|
||||
@if (Model.Room.ExitPortalX.HasValue) { <text>spawnData['@Model.Room.ExitPortalX,@Model.Room.ExitPortalY'] = { t: 'exit' };</text> }
|
||||
}
|
||||
|
||||
function buildGrid() {
|
||||
const g = document.getElementById('editorGrid');
|
||||
g.style.gridTemplateColumns = `repeat(${gw}, 32px)`;
|
||||
g.innerHTML = '';
|
||||
for (let y = 0; y < gh; y++) {
|
||||
for (let x = 0; x < gw; x++) {
|
||||
const c = document.createElement('div');
|
||||
c.className = 'editor-cell';
|
||||
c.dataset.x = x; c.dataset.y = y;
|
||||
c.onmousedown = e => { mouseDown = true; paint(x, y); };
|
||||
c.onmouseenter = () => { document.getElementById('cursorPos').textContent = `(${x}, ${y})`; if (mouseDown) paint(x, y); };
|
||||
g.appendChild(c);
|
||||
render(x, y);
|
||||
}
|
||||
}
|
||||
document.onmouseup = () => mouseDown = false;
|
||||
updateStats();
|
||||
}
|
||||
|
||||
function render(x, y) {
|
||||
const c = document.querySelector(`.editor-cell[data-x="${x}"][data-y="${y}"]`);
|
||||
if (!c) return;
|
||||
const k = `${x},${y}`;
|
||||
|
||||
// Tile bg
|
||||
const t = tileData[k];
|
||||
if (t && sheet && t.sid == sheet.id) {
|
||||
const col = t.f % sheet.cols, row = Math.floor(t.f / sheet.cols);
|
||||
c.style.background = `url('${cdnBase}/downloads/${sheet.cdn}') ${-col*sheet.tw}px ${-row*sheet.th}px no-repeat`;
|
||||
c.style.backgroundSize = `${sheet.sw}px ${sheet.sh}px`;
|
||||
} else if (t) {
|
||||
c.style.background = '#2d3748';
|
||||
} else {
|
||||
c.style.background = '#0f0f1a';
|
||||
}
|
||||
|
||||
// Overlays
|
||||
let html = '';
|
||||
if (objData[k]) html += `<div class="absolute inset-0 flex items-center justify-center bg-purple-500/30 text-sm">📦</div>`;
|
||||
const sp = spawnData[k];
|
||||
if (sp) {
|
||||
const icons = { player:'🧑', exit:'🌀', mob:'👾', elite:'⭐', boss:'💀', chest:'📦', door:'🚪' };
|
||||
const colors = { player:'bg-yellow-500/40', exit:'bg-blue-500/40', mob:'bg-red-500/30', elite:'bg-orange-500/40', boss:'bg-red-600/50', chest:'bg-amber-500/40', door:'bg-green-500/40' };
|
||||
html += `<div class="absolute inset-0 flex items-center justify-center ${colors[sp.t]||'bg-gray-500/30'} text-sm">${icons[sp.t]||'?'}</div>`;
|
||||
}
|
||||
c.innerHTML = html;
|
||||
}
|
||||
|
||||
function paint(x, y) {
|
||||
const k = `${x},${y}`;
|
||||
if (tool === 'paint' && sel) {
|
||||
if (layer === 'floor' && sel.type === 'tile') {
|
||||
tileData[k] = { sid: sel.sid, f: sel.f };
|
||||
} else if (layer === 'object' && sel.type === 'object') {
|
||||
objData[k] = { id: sel.id };
|
||||
} else if (layer === 'spawn' && sel.type === 'spawn') {
|
||||
if (sel.spawn === 'player' || sel.spawn === 'exit') {
|
||||
Object.keys(spawnData).forEach(key => { if (spawnData[key].t === sel.spawn) delete spawnData[key]; });
|
||||
}
|
||||
spawnData[k] = { t: sel.spawn };
|
||||
}
|
||||
} else if (tool === 'erase') {
|
||||
if (layer === 'floor') delete tileData[k];
|
||||
else if (layer === 'object') delete objData[k];
|
||||
else if (layer === 'spawn') delete spawnData[k];
|
||||
} else if (tool === 'fill' && sel?.type === 'tile') {
|
||||
floodFill(x, y);
|
||||
}
|
||||
render(x, y);
|
||||
updateStats();
|
||||
saveData();
|
||||
}
|
||||
|
||||
function floodFill(sx, sy) {
|
||||
const sk = `${sx},${sy}`;
|
||||
const startF = tileData[sk]?.f ?? -1;
|
||||
const visited = new Set(), queue = [[sx, sy]];
|
||||
while (queue.length && visited.size < 500) {
|
||||
const [x, y] = queue.shift();
|
||||
const k = `${x},${y}`;
|
||||
if (visited.has(k) || x < 0 || x >= gw || y < 0 || y >= gh) continue;
|
||||
if ((tileData[k]?.f ?? -1) !== startF) continue;
|
||||
visited.add(k);
|
||||
tileData[k] = { sid: sel.sid, f: sel.f };
|
||||
render(x, y);
|
||||
queue.push([x+1,y],[x-1,y],[x,y+1],[x,y-1]);
|
||||
}
|
||||
}
|
||||
|
||||
function setTool(t) {
|
||||
tool = t;
|
||||
document.querySelectorAll('[data-tool]').forEach(b => b.classList.toggle('active', b.dataset.tool === t));
|
||||
}
|
||||
|
||||
function setLayer(l) {
|
||||
layer = l;
|
||||
document.querySelectorAll('[data-layer]').forEach(b => b.classList.toggle('active', b.dataset.layer === l));
|
||||
document.getElementById('tilePaletteCard').classList.toggle('hidden', l !== 'floor');
|
||||
document.getElementById('objectPaletteCard').classList.toggle('hidden', l !== 'object');
|
||||
document.getElementById('spawnPaletteCard').classList.toggle('hidden', l !== 'spawn');
|
||||
sel = null;
|
||||
document.querySelectorAll('.palette-item').forEach(i => i.classList.remove('active'));
|
||||
document.getElementById('selectionInfo').textContent = 'Nothing';
|
||||
}
|
||||
|
||||
function loadTilePalette() {
|
||||
const opt = document.getElementById('tileSheetSelect').selectedOptions[0];
|
||||
if (!opt?.value) { sheet = null; document.getElementById('tilePalette').innerHTML = '<div class="text-gray-500 text-xs p-2">Select a 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, row = Math.floor(i / sheet.cols);
|
||||
html += `<div class="palette-item" data-type="tile" data-sid="${sheet.id}" data-f="${i}" title="Frame ${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;"
|
||||
onclick="selectPaletteItem(this)"></div>`;
|
||||
}
|
||||
document.getElementById('tilePalette').innerHTML = html;
|
||||
for (let y = 0; y < gh; y++) for (let x = 0; x < gw; x++) render(x, y);
|
||||
}
|
||||
|
||||
function selectPaletteItem(el) {
|
||||
document.querySelectorAll('.palette-item').forEach(i => i.classList.remove('active'));
|
||||
el.classList.add('active');
|
||||
const type = el.dataset.type;
|
||||
if (type === 'tile') sel = { type: 'tile', sid: +el.dataset.sid, f: +el.dataset.f };
|
||||
else if (type === 'object') sel = { type: 'object', id: +el.dataset.id, name: el.dataset.name };
|
||||
else if (type === 'spawn') sel = { type: 'spawn', spawn: el.dataset.spawn };
|
||||
document.getElementById('selectionInfo').textContent = type === 'tile' ? `Tile #${sel.f}` : type === 'object' ? sel.name : sel.spawn;
|
||||
}
|
||||
|
||||
function updateStats() {
|
||||
document.getElementById('statsInfo').textContent = `Tiles: ${Object.keys(tileData).length} | Objects: ${Object.keys(objData).length} | Spawns: ${Object.keys(spawnData).length}`;
|
||||
}
|
||||
|
||||
function saveData() {
|
||||
const tiles = Object.entries(tileData).map(([k,v]) => { const [x,y] = k.split(',').map(Number); return {x,y,sheetId:v.sid,frameIndex:v.f}; });
|
||||
document.getElementById('tileGridJson').value = JSON.stringify(tiles);
|
||||
|
||||
const objs = Object.entries(objData).map(([k,v]) => { const [x,y] = k.split(',').map(Number); return {X:x,Y:y,ObjectTemplateId:v.id}; });
|
||||
document.getElementById('objectPlacementsJson').value = JSON.stringify(objs);
|
||||
|
||||
const mobs = [], conns = [];
|
||||
let px = '', py = '', ex = '', ey = '';
|
||||
Object.entries(spawnData).forEach(([k,v]) => {
|
||||
const [x,y] = k.split(',').map(Number);
|
||||
if (v.t === 'player') { px = x; py = y; }
|
||||
else if (v.t === 'exit') { ex = x; ey = y; }
|
||||
else if (v.t === 'door') conns.push({X:x,Y:y,Direction:'north',Width:1});
|
||||
else mobs.push({X:x,Y:y,Type:v.t,Count:1});
|
||||
});
|
||||
document.getElementById('mobSpawnsJson').value = JSON.stringify(mobs);
|
||||
document.getElementById('connectionPointsJson').value = JSON.stringify(conns);
|
||||
document.getElementById('playerSpawnX').value = px;
|
||||
document.getElementById('playerSpawnY').value = py;
|
||||
document.getElementById('exitPortalX').value = ex;
|
||||
document.getElementById('exitPortalY').value = ey;
|
||||
}
|
||||
|
||||
function resizeGrid() {
|
||||
gw = +document.getElementById('roomWidth').value || 10;
|
||||
gh = +document.getElementById('roomHeight').value || 10;
|
||||
buildGrid();
|
||||
}
|
||||
|
||||
function clearLayer() {
|
||||
if (!confirm(`Clear all ${layer}?`)) return;
|
||||
if (layer === 'floor') tileData = {};
|
||||
else if (layer === 'object') objData = {};
|
||||
else spawnData = {};
|
||||
buildGrid();
|
||||
saveData();
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
if (!confirm('Clear everything?')) return;
|
||||
tileData = {}; objData = {}; spawnData = {};
|
||||
buildGrid();
|
||||
saveData();
|
||||
}
|
||||
|
||||
document.getElementById('roomForm').onsubmit = () => saveData();
|
||||
</script>
|
||||
|
||||
@functions {
|
||||
string GetObjIcon(ObjectTemplateType t) => t switch {
|
||||
ObjectTemplateType.Container => "📦", ObjectTemplateType.Trap => "⚠️", ObjectTemplateType.Door => "🚪",
|
||||
ObjectTemplateType.Light => "🔥", ObjectTemplateType.Shrine => "⛩️", ObjectTemplateType.Vendor => "🛒", _ => "🪨"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Server.Services.Admin.Pages.DungeonBuilder;
|
||||
|
||||
public class RoomEditModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public RoomEditModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public BuilderRoomTemplate Room { get; set; } = new();
|
||||
|
||||
public List<TileMapSheet> TileSheets { get; set; } = new();
|
||||
public List<ObjectTemplate> Objects { 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)
|
||||
{
|
||||
await LoadReferenceData();
|
||||
|
||||
if (id.HasValue)
|
||||
{
|
||||
var room = await _db.BuilderRoomTemplates.FindAsync(id.Value);
|
||||
if (room != null)
|
||||
{
|
||||
Room = room;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Defaults
|
||||
Room.IsEnabled = true;
|
||||
Room.Width = 10;
|
||||
Room.Height = 10;
|
||||
Room.Weight = 100;
|
||||
Room.MinConnections = 1;
|
||||
Room.MaxConnections = 4;
|
||||
Room.AllowRotation = true;
|
||||
Room.AllowMirror = true;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
await LoadReferenceData();
|
||||
|
||||
// Validate
|
||||
if (string.IsNullOrWhiteSpace(Room.Name))
|
||||
{
|
||||
IsError = true;
|
||||
Message = "Name is required.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
Room.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
// Handle nullable spawn coordinates
|
||||
if (Request.Form["Room.PlayerSpawnX"].ToString() == "") Room.PlayerSpawnX = null;
|
||||
if (Request.Form["Room.PlayerSpawnY"].ToString() == "") Room.PlayerSpawnY = null;
|
||||
if (Request.Form["Room.ExitPortalX"].ToString() == "") Room.ExitPortalX = null;
|
||||
if (Request.Form["Room.ExitPortalY"].ToString() == "") Room.ExitPortalY = null;
|
||||
|
||||
if (Room.Id == 0)
|
||||
{
|
||||
Room.CreatedAt = DateTime.UtcNow;
|
||||
_db.BuilderRoomTemplates.Add(Room);
|
||||
Message = "Room template created!";
|
||||
}
|
||||
else
|
||||
{
|
||||
var existing = await _db.BuilderRoomTemplates.FindAsync(Room.Id);
|
||||
if (existing == null)
|
||||
{
|
||||
IsError = true;
|
||||
Message = "Room not found.";
|
||||
return Page();
|
||||
}
|
||||
|
||||
existing.Name = Room.Name;
|
||||
existing.Description = Room.Description;
|
||||
existing.Type = Room.Type;
|
||||
existing.Tags = Room.Tags;
|
||||
existing.Biome = Room.Biome;
|
||||
existing.Width = Room.Width;
|
||||
existing.Height = Room.Height;
|
||||
existing.TileGridJson = Room.TileGridJson;
|
||||
existing.TilePlacementsJson = Room.TilePlacementsJson;
|
||||
existing.ObjectPlacementsJson = Room.ObjectPlacementsJson;
|
||||
existing.ConnectionPointsJson = Room.ConnectionPointsJson;
|
||||
existing.MobSpawnsJson = Room.MobSpawnsJson;
|
||||
existing.ItemSpawnsJson = Room.ItemSpawnsJson;
|
||||
existing.PlayerSpawnX = Room.PlayerSpawnX;
|
||||
existing.PlayerSpawnY = Room.PlayerSpawnY;
|
||||
existing.ExitPortalX = Room.ExitPortalX;
|
||||
existing.ExitPortalY = Room.ExitPortalY;
|
||||
existing.Weight = Room.Weight;
|
||||
existing.MinTier = Room.MinTier;
|
||||
existing.MaxTier = Room.MaxTier;
|
||||
existing.MinConnections = Room.MinConnections;
|
||||
existing.MaxConnections = Room.MaxConnections;
|
||||
existing.AllowRotation = Room.AllowRotation;
|
||||
existing.AllowMirror = Room.AllowMirror;
|
||||
existing.IsEnabled = Room.IsEnabled;
|
||||
existing.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
Message = "Changes saved!";
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage(new { id = Room.Id });
|
||||
}
|
||||
|
||||
private async Task LoadReferenceData()
|
||||
{
|
||||
TileSheets = await _db.TileMapSheets
|
||||
.Where(s => s.IsEnabled)
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync();
|
||||
|
||||
Objects = await _db.ObjectTemplates
|
||||
.Where(o => o.IsEnabled)
|
||||
.OrderBy(o => o.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
@page "/admin/dungeonbuilder/rooms"
|
||||
@model DungeonBuilder.RoomsModel
|
||||
@using DataServer.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = "Room Templates";
|
||||
var roomTypes = Enum.GetValues<RoomType>();
|
||||
}
|
||||
|
||||
<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">Room Templates</h1>
|
||||
<p class="text-gray-400 text-sm mt-1">Pre-built rooms with tiles, objects, and spawns</p>
|
||||
</div>
|
||||
<a href="/admin/dungeonbuilder/rooms/edit" class="btn btn-primary">+ New Room</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>
|
||||
}
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="card p-4 mb-4">
|
||||
<form method="get" class="flex flex-wrap gap-3">
|
||||
<div class="flex-1 min-w-[150px]">
|
||||
<input type="text" name="search" value="@Model.Search"
|
||||
class="input w-full text-sm" placeholder="Search by name..." />
|
||||
</div>
|
||||
<select name="type" class="input text-sm">
|
||||
<option value="">All Types</option>
|
||||
@foreach (var t in roomTypes)
|
||||
{
|
||||
<option value="@((int)t)" selected="@(Model.TypeFilter == (int)t)">@t</option>
|
||||
}
|
||||
</select>
|
||||
<select name="biome" class="input text-sm">
|
||||
<option value="">All Biomes</option>
|
||||
@foreach (var b in Model.Biomes)
|
||||
{
|
||||
<option value="@b" selected="@(Model.BiomeFilter == b)">@b</option>
|
||||
}
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary text-sm">Filter</button>
|
||||
<a href="/admin/dungeonbuilder/rooms" class="btn btn-ghost text-sm">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Rooms Grid -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
@foreach (var room in Model.Rooms)
|
||||
{
|
||||
<div class="card p-4 hover:border-green-500/50 transition-colors">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="flex-1 min-w-0">
|
||||
<h3 class="font-semibold text-white truncate">@room.Name</h3>
|
||||
<div class="text-xs text-gray-400 mt-1">
|
||||
<span class="@GetTypeColor(room.Type)">@room.Type</span>
|
||||
<span class="ml-2">@(room.Width)×@(room.Height)</span>
|
||||
@if (!string.IsNullOrEmpty(room.Biome))
|
||||
{
|
||||
<span class="ml-2 text-gray-500">@room.Biome</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Stats -->
|
||||
<div class="flex flex-wrap gap-2 mt-3">
|
||||
<span class="px-1.5 py-0.5 bg-gray-700 text-gray-300 rounded text-xs">
|
||||
@(room.MinConnections)-@(room.MaxConnections) doors
|
||||
</span>
|
||||
@if (room.PlayerSpawnX.HasValue)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-yellow-500/20 text-yellow-400 rounded text-xs">Spawn</span>
|
||||
}
|
||||
@if (room.ExitPortalX.HasValue)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded text-xs">Exit</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mini Preview -->
|
||||
<div class="w-16 h-16 bg-gray-900 rounded flex items-center justify-center flex-shrink-0 text-2xl">
|
||||
@GetRoomIcon(room.Type)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mt-3 pt-3 border-t border-gray-700">
|
||||
<span class="text-xs text-gray-500">ID: @room.Id</span>
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/dungeonbuilder/rooms/edit?id=@room.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 room?');">
|
||||
<input type="hidden" name="id" value="@room.Id" />
|
||||
<button type="submit" class="text-red-400 hover:text-red-300 text-sm">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!Model.Rooms.Any())
|
||||
{
|
||||
<div class="col-span-full card p-8 text-center text-gray-500">
|
||||
No room templates found. <a href="/admin/dungeonbuilder/rooms/edit" class="text-blue-400 hover:underline">Create one</a>!
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@functions {
|
||||
string GetTypeColor(RoomType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
RoomType.Entrance => "text-yellow-400",
|
||||
RoomType.Exit => "text-blue-400",
|
||||
RoomType.Boss => "text-red-400",
|
||||
RoomType.Treasure => "text-amber-400",
|
||||
RoomType.Secret => "text-purple-400",
|
||||
RoomType.Shop => "text-emerald-400",
|
||||
_ => "text-gray-400"
|
||||
};
|
||||
}
|
||||
|
||||
string GetRoomIcon(RoomType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
RoomType.Entrance => "🚪",
|
||||
RoomType.Exit => "🌀",
|
||||
RoomType.Boss => "💀",
|
||||
RoomType.Treasure => "💎",
|
||||
RoomType.Secret => "❓",
|
||||
RoomType.Shop => "🛒",
|
||||
_ => "🏠"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Server.Services.Admin.Pages.DungeonBuilder;
|
||||
|
||||
public class RoomsModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public RoomsModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public List<BuilderRoomTemplate> Rooms { get; set; } = new();
|
||||
public List<string> Biomes { get; set; } = new();
|
||||
|
||||
public string? Search { get; set; }
|
||||
public int? TypeFilter { get; set; }
|
||||
public string? BiomeFilter { get; set; }
|
||||
|
||||
public int CurrentPage { get; set; } = 1;
|
||||
public int TotalPages { get; set; }
|
||||
public int PageSize { get; set; } = 18;
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync(string? search, int? type, string? biome, int page = 1)
|
||||
{
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
BiomeFilter = biome;
|
||||
CurrentPage = Math.Max(1, page);
|
||||
|
||||
// Get unique biomes
|
||||
Biomes = await _db.BuilderRoomTemplates
|
||||
.Where(r => r.Biome != null)
|
||||
.Select(r => r.Biome!)
|
||||
.Distinct()
|
||||
.OrderBy(b => b)
|
||||
.ToListAsync();
|
||||
|
||||
// Build query
|
||||
var query = _db.BuilderRoomTemplates.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(search))
|
||||
{
|
||||
query = query.Where(r => r.Name.Contains(search) || (r.Tags != null && r.Tags.Contains(search)));
|
||||
}
|
||||
|
||||
if (type.HasValue)
|
||||
{
|
||||
query = query.Where(r => r.Type == (RoomType)type.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(biome))
|
||||
{
|
||||
query = query.Where(r => r.Biome == biome);
|
||||
}
|
||||
|
||||
var total = await query.CountAsync();
|
||||
TotalPages = (int)Math.Ceiling(total / (double)PageSize);
|
||||
|
||||
Rooms = await query
|
||||
.OrderBy(r => r.Name)
|
||||
.Skip((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var room = await _db.BuilderRoomTemplates.FindAsync(id);
|
||||
if (room != null)
|
||||
{
|
||||
_db.BuilderRoomTemplates.Remove(room);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Deleted room template: {room.Name}";
|
||||
}
|
||||
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
@page "/admin/dungeonbuilder/tiles"
|
||||
@model DungeonBuilder.TilesModel
|
||||
@using DataServer.Data.Entities
|
||||
@{
|
||||
ViewData["Title"] = "Tile Templates";
|
||||
var categories = Enum.GetValues<TileTemplateCategory>();
|
||||
}
|
||||
|
||||
<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">Tile Templates</h1>
|
||||
<p class="text-gray-400 text-sm mt-1">Reusable floor, wall, and door patterns</p>
|
||||
</div>
|
||||
<a href="/admin/dungeonbuilder/tiles/edit" class="btn btn-primary">+ New Template</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>
|
||||
}
|
||||
|
||||
<!-- Filters -->
|
||||
<div class="card p-4 mb-4">
|
||||
<form method="get" class="flex flex-wrap gap-3">
|
||||
<div class="flex-1 min-w-[150px]">
|
||||
<input type="text" name="search" value="@Model.Search"
|
||||
class="input w-full text-sm" placeholder="Search by name..." />
|
||||
</div>
|
||||
<select name="category" class="input text-sm">
|
||||
<option value="">All Categories</option>
|
||||
@foreach (var c in categories)
|
||||
{
|
||||
<option value="@((int)c)" selected="@(Model.CategoryFilter == (int)c)">@c</option>
|
||||
}
|
||||
</select>
|
||||
<select name="biome" class="input text-sm">
|
||||
<option value="">All Biomes</option>
|
||||
@foreach (var b in Model.Biomes)
|
||||
{
|
||||
<option value="@b" selected="@(Model.BiomeFilter == b)">@b</option>
|
||||
}
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary text-sm">Filter</button>
|
||||
<a href="/admin/dungeonbuilder/tiles" class="btn btn-ghost text-sm">Clear</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Templates Grid -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
@foreach (var tile in Model.Tiles)
|
||||
{
|
||||
<div class="card p-4 hover:border-blue-500/50 transition-colors">
|
||||
<div class="flex items-start gap-3">
|
||||
<!-- Preview -->
|
||||
<div class="w-16 h-16 bg-gray-900 rounded flex items-center justify-center flex-shrink-0">
|
||||
@if (tile.PrimaryTileDefinition?.TileMapSheet != null)
|
||||
{
|
||||
var sheet = tile.PrimaryTileDefinition.TileMapSheet;
|
||||
var cols = sheet.TileWidth > 0 ? sheet.SheetWidth / sheet.TileWidth : 1;
|
||||
var row = tile.PrimaryTileDefinition.FrameIndex / cols;
|
||||
var col = tile.PrimaryTileDefinition.FrameIndex % cols;
|
||||
var bgX = -col * sheet.TileWidth;
|
||||
var bgY = -row * sheet.TileHeight;
|
||||
var imgUrl = Model.GetCdnUrl(sheet.CdnPath);
|
||||
|
||||
<div style="width: @(sheet.TileWidth)px; height: @(sheet.TileHeight)px;
|
||||
background: url('@imgUrl') @(bgX)px @(bgY)px no-repeat;
|
||||
background-size: @(sheet.SheetWidth)px @(sheet.SheetHeight)px;
|
||||
image-rendering: pixelated;"></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="text-gray-600 text-2xl">🧱</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Info -->
|
||||
<div class="flex-1 min-w-0">
|
||||
<h3 class="font-semibold text-white truncate">@tile.Name</h3>
|
||||
<div class="text-xs text-gray-400 mt-1">
|
||||
<span class="@GetCategoryColor(tile.Category)">@tile.Category</span>
|
||||
@if (!string.IsNullOrEmpty(tile.Biome))
|
||||
{
|
||||
<span class="ml-2">@tile.Biome</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
<!-- Size & Flags -->
|
||||
<div class="flex flex-wrap gap-1 mt-2">
|
||||
@if (tile.Width > 1 || tile.Height > 1)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-gray-700 text-gray-400 rounded text-xs">@tile.Width×@tile.Height</span>
|
||||
}
|
||||
@if (!tile.IsWalkable)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-red-500/20 text-red-400 rounded text-xs">Solid</span>
|
||||
}
|
||||
@if (tile.BlocksLineOfSight)
|
||||
{
|
||||
<span class="px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded text-xs">Blocks LoS</span>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mt-3 pt-3 border-t border-gray-700">
|
||||
<span class="text-xs text-gray-500">Weight: @tile.Weight</span>
|
||||
<div class="flex gap-2">
|
||||
<a href="/admin/dungeonbuilder/tiles/edit?id=@tile.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 template?');">
|
||||
<input type="hidden" name="id" value="@tile.Id" />
|
||||
<button type="submit" class="text-red-400 hover:text-red-300 text-sm">Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!Model.Tiles.Any())
|
||||
{
|
||||
<div class="col-span-full card p-8 text-center text-gray-500">
|
||||
No tile templates found. <a href="/admin/dungeonbuilder/tiles/edit" class="text-blue-400 hover:underline">Create one</a>!
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@functions {
|
||||
string GetCategoryColor(TileTemplateCategory category)
|
||||
{
|
||||
return category switch
|
||||
{
|
||||
TileTemplateCategory.Floor => "text-green-400",
|
||||
TileTemplateCategory.Wall => "text-red-400",
|
||||
TileTemplateCategory.Door => "text-purple-400",
|
||||
TileTemplateCategory.Window => "text-cyan-400",
|
||||
TileTemplateCategory.Stairs => "text-yellow-400",
|
||||
TileTemplateCategory.Water => "text-blue-400",
|
||||
TileTemplateCategory.Lava => "text-orange-400",
|
||||
_ => "text-gray-400"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using DataServer.Data;
|
||||
using DataServer.Data.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Server.Services.Admin.Pages.DungeonBuilder;
|
||||
|
||||
public class TilesModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public TilesModel(GameDbContext db, IConfiguration config)
|
||||
{
|
||||
_db = db;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public List<TileTemplate> Tiles { get; set; } = new();
|
||||
public List<string> Biomes { get; set; } = new();
|
||||
|
||||
public string? Search { get; set; }
|
||||
public int? CategoryFilter { get; set; }
|
||||
public string? BiomeFilter { get; set; }
|
||||
|
||||
public string? Message { get; set; }
|
||||
public bool IsError { get; set; }
|
||||
|
||||
public async Task OnGetAsync(string? search, int? category, string? biome)
|
||||
{
|
||||
Search = search;
|
||||
CategoryFilter = category;
|
||||
BiomeFilter = biome;
|
||||
|
||||
// Get unique biomes
|
||||
Biomes = await _db.TileTemplates
|
||||
.Where(t => t.Biome != null)
|
||||
.Select(t => t.Biome!)
|
||||
.Distinct()
|
||||
.OrderBy(b => b)
|
||||
.ToListAsync();
|
||||
|
||||
// Build query
|
||||
var query = _db.TileTemplates
|
||||
.Include(t => t.PrimaryTileDefinition)
|
||||
.ThenInclude(td => td!.TileMapSheet)
|
||||
.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(search))
|
||||
{
|
||||
query = query.Where(t => t.Name.Contains(search) || (t.Tags != null && t.Tags.Contains(search)));
|
||||
}
|
||||
|
||||
if (category.HasValue)
|
||||
{
|
||||
query = query.Where(t => t.Category == (TileTemplateCategory)category.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(biome))
|
||||
{
|
||||
query = query.Where(t => t.Biome == biome);
|
||||
}
|
||||
|
||||
Tiles = await query
|
||||
.OrderBy(t => t.Category)
|
||||
.ThenBy(t => t.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var tile = await _db.TileTemplates.FindAsync(id);
|
||||
if (tile != null)
|
||||
{
|
||||
_db.TileTemplates.Remove(tile);
|
||||
await _db.SaveChangesAsync();
|
||||
Message = $"Deleted tile template: {tile.Name}";
|
||||
}
|
||||
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
public string GetCdnUrl(string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return "";
|
||||
|
||||
var baseUrl = _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? "";
|
||||
if (!baseUrl.EndsWith("/downloads"))
|
||||
{
|
||||
baseUrl += "/downloads";
|
||||
}
|
||||
|
||||
return $"{baseUrl}/{path.TrimStart('/')}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user