Dungeon Builder. CONT

This commit is contained in:
dingo
2026-01-04 12:04:45 -05:00
parent 2ba9df6485
commit b8af3545a8
2 changed files with 662 additions and 0 deletions
@@ -0,0 +1,278 @@
@page "/admin/dungeonbuilder/testgen"
@model DungeonBuilder.TestGenModel
@{
ViewData["Title"] = "Test Generator";
}
<style>
.dungeon-grid {
display: grid;
gap: 0;
background: #0a0a0f;
border: 2px solid #374151;
border-radius: 4px;
overflow: auto;
max-height: 70vh;
}
.dungeon-cell {
width: 16px;
height: 16px;
image-rendering: pixelated;
position: relative;
}
.dungeon-cell.wall { background: #1a1a2e; }
.dungeon-cell.floor { background: #2d3748; }
.dungeon-cell.door { background: #805ad5; }
.dungeon-cell.player { background: #48bb78; }
.dungeon-cell.exit { background: #4299e1; }
.dungeon-cell.mob { background: #f56565; }
.dungeon-cell.chest { background: #ecc94b; }
.dungeon-cell.object { background: #9f7aea; }
.cell-icon {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
}
.legend-box {
width: 16px;
height: 16px;
border-radius: 2px;
}
</style>
<div class="mb-4">
<a href="/admin/dungeonbuilder" class="text-blue-400 hover:text-blue-300 text-sm">&larr; 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">Test Generator</h1>
<p class="text-gray-400 text-sm mt-1">Preview dungeon generation with your templates</p>
</div>
</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 lg:grid-cols-4 gap-6">
<!-- Left: Controls -->
<div class="space-y-4">
<form method="post" id="genForm">
@Html.AntiForgeryToken()
<div class="card p-4">
<h3 class="font-semibold text-white mb-3">Generation Settings</h3>
<div class="space-y-3">
<div>
<label class="text-xs text-gray-400">Palette</label>
<select name="paletteId" class="input w-full text-sm">
<option value="">-- Use defaults --</option>
@foreach (var p in Model.Palettes)
{
<option value="@p.Id" selected="@(Model.SelectedPaletteId == p.Id)">@p.Name</option>
}
</select>
</div>
<div>
<label class="text-xs text-gray-400">Tier</label>
<input type="number" name="tier" value="@Model.Tier" class="input w-full text-sm" min="1" max="20" />
</div>
<div>
<label class="text-xs text-gray-400">Seed (optional)</label>
<input type="number" name="seed" value="@Model.Seed" class="input w-full text-sm" placeholder="Random" />
</div>
</div>
</div>
<div class="card p-4">
<h3 class="font-semibold text-white mb-3">Size Override</h3>
<div class="space-y-3">
<div class="grid grid-cols-2 gap-2">
<div>
<label class="text-xs text-gray-400">Width</label>
<input type="number" name="width" value="@Model.Width" class="input w-full text-sm" min="20" max="200" />
</div>
<div>
<label class="text-xs text-gray-400">Height</label>
<input type="number" name="height" value="@Model.Height" class="input w-full text-sm" min="20" max="200" />
</div>
</div>
<div class="grid grid-cols-2 gap-2">
<div>
<label class="text-xs text-gray-400">Min Rooms</label>
<input type="number" name="minRooms" value="@Model.MinRooms" class="input w-full text-sm" min="1" />
</div>
<div>
<label class="text-xs text-gray-400">Max Rooms</label>
<input type="number" name="maxRooms" value="@Model.MaxRooms" class="input w-full text-sm" min="1" />
</div>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary w-full">
🎲 Generate Dungeon
</button>
</form>
@if (Model.GeneratedDungeon != null)
{
<div class="card p-4">
<h3 class="font-semibold text-white mb-3">Results</h3>
<div class="space-y-2 text-sm">
<div class="flex justify-between">
<span class="text-gray-400">Size:</span>
<span class="text-white">@Model.GeneratedDungeon.Width × @Model.GeneratedDungeon.Height</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Rooms:</span>
<span class="text-white">@Model.GeneratedDungeon.RoomCount</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Mobs:</span>
<span class="text-white">@Model.GeneratedDungeon.MobCount</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Chests:</span>
<span class="text-white">@Model.GeneratedDungeon.ChestCount</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Objects:</span>
<span class="text-white">@Model.GeneratedDungeon.ObjectCount</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Seed:</span>
<span class="text-white font-mono text-xs">@Model.GeneratedDungeon.Seed</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Gen Time:</span>
<span class="text-white">@Model.GeneratedDungeon.GenerationTimeMs ms</span>
</div>
</div>
</div>
}
<div class="card p-4">
<h3 class="font-semibold text-white mb-3">Legend</h3>
<div class="space-y-2">
<div class="legend-item"><div class="legend-box bg-gray-700"></div><span class="text-gray-300">Floor</span></div>
<div class="legend-item"><div class="legend-box bg-gray-900"></div><span class="text-gray-300">Wall</span></div>
<div class="legend-item"><div class="legend-box bg-purple-600"></div><span class="text-gray-300">Door</span></div>
<div class="legend-item"><div class="legend-box bg-green-500"></div><span class="text-gray-300">Player Spawn</span></div>
<div class="legend-item"><div class="legend-box bg-blue-500"></div><span class="text-gray-300">Exit Portal</span></div>
<div class="legend-item"><div class="legend-box bg-red-500"></div><span class="text-gray-300">Mob Spawn</span></div>
<div class="legend-item"><div class="legend-box bg-yellow-500"></div><span class="text-gray-300">Chest</span></div>
<div class="legend-item"><div class="legend-box bg-purple-400"></div><span class="text-gray-300">Object</span></div>
</div>
</div>
</div>
<!-- Right: Dungeon Preview -->
<div class="lg:col-span-3">
<div class="card p-4">
<div class="flex items-center justify-between mb-3">
<h3 class="font-semibold text-white">Dungeon Preview</h3>
@if (Model.GeneratedDungeon != null)
{
<div class="flex gap-2">
<button type="button" onclick="zoomIn()" class="btn btn-ghost text-sm">➕</button>
<button type="button" onclick="zoomOut()" class="btn btn-ghost text-sm">➖</button>
<span class="text-xs text-gray-500" id="zoomLevel">16px</span>
</div>
}
</div>
@if (Model.GeneratedDungeon != null)
{
<div class="dungeon-grid" id="dungeonGrid"
style="grid-template-columns: repeat(@Model.GeneratedDungeon.Width, 16px);">
@for (int y = 0; y < Model.GeneratedDungeon.Height; y++)
{
@for (int x = 0; x < Model.GeneratedDungeon.Width; x++)
{
var cell = Model.GeneratedDungeon.GetCell(x, y);
<div class="dungeon-cell @cell.CssClass" title="@x,@y: @cell.Type">
@if (!string.IsNullOrEmpty(cell.Icon))
{
<span class="cell-icon">@cell.Icon</span>
}
</div>
}
}
</div>
}
else
{
<div class="flex items-center justify-center h-96 text-gray-500">
<div class="text-center">
<div class="text-4xl mb-2">🗺️</div>
<p>Click "Generate Dungeon" to preview</p>
</div>
</div>
}
</div>
@if (Model.GeneratedDungeon?.Rooms != null && Model.GeneratedDungeon.Rooms.Any())
{
<div class="card p-4 mt-4">
<h3 class="font-semibold text-white mb-3">Rooms (@Model.GeneratedDungeon.Rooms.Count)</h3>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 max-h-48 overflow-auto">
@foreach (var room in Model.GeneratedDungeon.Rooms)
{
<div class="bg-gray-800 rounded p-2 text-xs">
<div class="font-semibold text-white">@room.Type</div>
<div class="text-gray-400">@room.X,@room.Y → @(room.X + room.Width),@(room.Y + room.Height)</div>
<div class="text-gray-500">@room.Width×@room.Height</div>
</div>
}
</div>
</div>
}
</div>
</div>
<script>
let cellSize = 16;
function zoomIn() {
cellSize = Math.min(32, cellSize + 4);
updateZoom();
}
function zoomOut() {
cellSize = Math.max(4, cellSize - 4);
updateZoom();
}
function updateZoom() {
const grid = document.getElementById('dungeonGrid');
if (!grid) return;
const width = @(Model.GeneratedDungeon?.Width ?? 0);
grid.style.gridTemplateColumns = `repeat(${width}, ${cellSize}px)`;
document.querySelectorAll('.dungeon-cell').forEach(cell => {
cell.style.width = cellSize + 'px';
cell.style.height = cellSize + 'px';
});
document.querySelectorAll('.cell-icon').forEach(icon => {
icon.style.fontSize = Math.max(8, cellSize * 0.6) + 'px';
});
document.getElementById('zoomLevel').textContent = cellSize + 'px';
}
</script>