Admin updates, dungeon viewer

This commit is contained in:
dingo
2026-01-10 13:43:59 -05:00
parent c43a334d8b
commit ff7357c557
15 changed files with 1033 additions and 1403 deletions
+373
View File
@@ -0,0 +1,373 @@
@page "/admin/dungeons/view"
@model Admin.Pages.Dungeons.ViewModel
@{
ViewData["Title"] = $"Dungeon View - Tier {Model.Dungeon?.Tier}";
}
<style>
.dungeon-map {
background: #0a0a15;
border: 2px solid #374151;
border-radius: 8px;
overflow: hidden;
position: relative;
}
.map-canvas {
image-rendering: pixelated;
}
.entity-dot {
position: absolute;
border-radius: 50%;
transform: translate(-50%, -50%);
pointer-events: none;
}
.player-dot {
background: #4ade80;
width: 10px;
height: 10px;
box-shadow: 0 0 6px #4ade80;
}
.mob-dot {
background: #f87171;
width: 6px;
height: 6px;
}
.boss-dot {
background: #fbbf24;
width: 12px;
height: 12px;
box-shadow: 0 0 8px #fbbf24;
}
.stat-card {
background: rgba(30, 30, 50, 0.8);
border: 1px solid #374151;
border-radius: 8px;
padding: 12px;
}
.player-list-item {
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
background: rgba(30, 30, 50, 0.5);
border-radius: 6px;
margin-bottom: 4px;
}
.health-bar {
height: 4px;
background: #374151;
border-radius: 2px;
overflow: hidden;
}
.health-bar-fill {
height: 100%;
background: linear-gradient(90deg, #ef4444, #22c55e);
transition: width 0.3s ease;
}
</style>
<div class="mb-4">
<a href="/admin/dungeons" class="text-blue-400 hover:text-blue-300 text-sm">&larr; Back to Dungeons</a>
</div>
@if (Model.Dungeon == null)
{
<div class="card p-8 text-center">
<div class="text-4xl mb-2">❌</div>
<h2 class="text-xl font-semibold text-white mb-2">Dungeon Not Found</h2>
<p class="text-gray-400">This dungeon may have been closed or doesn't exist.</p>
<a href="/admin/dungeons" class="btn btn-primary mt-4">Back to Dungeons</a>
</div>
}
else
{
<div class="flex flex-col lg:flex-row gap-6">
<!-- Left: Map View -->
<div class="flex-1">
<div class="card p-4">
<div class="flex items-center justify-between mb-4">
<h2 class="text-xl font-semibold text-white">Live Dungeon Map</h2>
<div class="flex items-center gap-2 text-sm text-gray-400">
<div class="w-2 h-2 bg-green-400 rounded-full animate-pulse"></div>
<span>Live</span>
<button onclick="toggleAutoRefresh()" id="autoRefreshBtn" class="btn btn-sm btn-ghost ml-2">
Auto: ON
</button>
</div>
</div>
<div class="dungeon-map" id="mapContainer" style="height: 500px;">
<canvas id="mapCanvas" class="map-canvas"></canvas>
<div id="entityOverlay"></div>
</div>
<div class="flex items-center justify-center gap-6 mt-3 text-xs text-gray-400">
<div class="flex items-center gap-1">
<div class="w-3 h-3 rounded-full bg-green-400"></div>
<span>Players</span>
</div>
<div class="flex items-center gap-1">
<div class="w-2 h-2 rounded-full bg-red-400"></div>
<span>Mobs</span>
</div>
<div class="flex items-center gap-1">
<div class="w-3 h-3 rounded-full bg-yellow-400"></div>
<span>Boss</span>
</div>
<div class="flex items-center gap-1">
<div class="w-3 h-3 bg-blue-400"></div>
<span>Floor</span>
</div>
<div class="flex items-center gap-1">
<div class="w-3 h-3 bg-gray-700"></div>
<span>Wall</span>
</div>
</div>
</div>
</div>
<!-- Right: Info Panel -->
<div class="w-full lg:w-80 space-y-4">
<!-- Dungeon Info -->
<div class="stat-card">
<h3 class="text-lg font-semibold text-white mb-3">Dungeon Info</h3>
<div class="space-y-2 text-sm">
<div class="flex justify-between">
<span class="text-gray-400">ID</span>
<span class="text-white font-mono text-xs">@Model.Dungeon.Id.ToString()[..12]...</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Tier</span>
<span class="text-white">@Model.Dungeon.Tier</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Level Bracket</span>
<span class="text-white">@Model.Dungeon.LevelBracketMin - @Model.Dungeon.LevelBracketMax</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Seed</span>
<span class="text-white font-mono">@Model.Dungeon.Seed</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Phase</span>
<span class="@(Model.Dungeon.Simulation.Phase == DungeonPhase.Active ? "text-green-400" : "text-blue-400")">
@Model.Dungeon.Simulation.Phase
</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Creator</span>
<span class="text-white">@Model.Dungeon.CreatorName</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Created</span>
<span class="text-white">@Model.Dungeon.CreatedAt.ToString("HH:mm:ss")</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Duration</span>
<span class="text-white" id="duration">@Model.Duration</span>
</div>
</div>
</div>
<!-- Stats -->
<div class="stat-card">
<h3 class="text-lg font-semibold text-white mb-3">Stats</h3>
<div class="grid grid-cols-2 gap-3">
<div class="text-center p-2 bg-gray-800/50 rounded">
<div class="text-2xl font-bold text-green-400" id="playerCount">@Model.Dungeon.Simulation.Players.Count</div>
<div class="text-xs text-gray-400">Players</div>
</div>
<div class="text-center p-2 bg-gray-800/50 rounded">
<div class="text-2xl font-bold text-red-400" id="mobCount">@Model.Dungeon.Simulation.Mobs.Values.Count(m => m.IsAlive)</div>
<div class="text-xs text-gray-400">Mobs Alive</div>
</div>
<div class="text-center p-2 bg-gray-800/50 rounded">
<div class="text-2xl font-bold text-blue-400">@Model.RoomCount</div>
<div class="text-xs text-gray-400">Rooms</div>
</div>
<div class="text-center p-2 bg-gray-800/50 rounded">
<div class="text-2xl font-bold @(Model.Dungeon.BossKilled ? "text-yellow-400" : "text-gray-500")">
@(Model.Dungeon.BossKilled ? "✓" : "✗")
</div>
<div class="text-xs text-gray-400">Boss Killed</div>
</div>
</div>
</div>
<!-- Players -->
<div class="stat-card">
<h3 class="text-lg font-semibold text-white mb-3">Players (@Model.Dungeon.Simulation.Players.Count)</h3>
<div id="playerList" class="space-y-1 max-h-48 overflow-y-auto">
@foreach (var player in Model.Dungeon.Simulation.Players.Values)
{
var healthPct = player.MaxHealth > 0 ? (player.Health * 100 / player.MaxHealth) : 0;
<div class="player-list-item">
<div class="w-2 h-2 rounded-full bg-green-400"></div>
<div class="flex-1 min-w-0">
<div class="text-white text-sm truncate">@player.CharacterName</div>
<div class="health-bar mt-1">
<div class="health-bar-fill" style="width: @healthPct%"></div>
</div>
</div>
<div class="text-xs text-gray-400">@player.Health/@player.MaxHealth</div>
</div>
}
@if (Model.Dungeon.Simulation.Players.Count == 0)
{
<div class="text-gray-500 text-sm text-center py-2">No players</div>
}
</div>
</div>
<!-- Actions -->
<div class="stat-card">
<h3 class="text-lg font-semibold text-white mb-3">Actions</h3>
<div class="space-y-2">
<form method="post" asp-page-handler="KillAllMobs">
@Html.AntiForgeryToken()
<input type="hidden" name="id" value="@Model.Dungeon.Id" />
<button type="submit" class="btn btn-secondary w-full text-sm" onclick="return confirm('Kill all mobs in this dungeon?')">
Kill All Mobs
</button>
</form>
<form method="post" asp-page-handler="CompleteDungeon">
@Html.AntiForgeryToken()
<input type="hidden" name="id" value="@Model.Dungeon.Id" />
<button type="submit" class="btn btn-secondary w-full text-sm" onclick="return confirm('Force complete this dungeon?')">
Force Complete
</button>
</form>
<form method="post" asp-page-handler="Delete">
@Html.AntiForgeryToken()
<input type="hidden" name="id" value="@Model.Dungeon.Id" />
<button type="submit" class="btn btn-danger w-full text-sm" onclick="return confirm('Delete this dungeon? All players will be removed.')">
Delete Dungeon
</button>
</form>
</div>
</div>
</div>
</div>
}
@section Scripts {
<script>
const dungeonId = '@Model.Dungeon?.Id';
const mapWidth = @(Model.MapWidth);
const mapHeight = @(Model.MapHeight);
const walkableData = @Html.Raw(Model.WalkableJson);
let autoRefresh = true;
let refreshInterval;
function initMap() {
const canvas = document.getElementById('mapCanvas');
const container = document.getElementById('mapContainer');
if (!canvas || !container) return;
const ctx = canvas.getContext('2d');
const scale = Math.min(
(container.clientWidth - 20) / mapWidth,
(container.clientHeight - 20) / mapHeight,
8 // Max scale
);
canvas.width = mapWidth * scale;
canvas.height = mapHeight * scale;
canvas.style.width = canvas.width + 'px';
canvas.style.height = canvas.height + 'px';
// Draw tiles
for (let y = 0; y < mapHeight; y++) {
for (let x = 0; x < mapWidth; x++) {
const idx = y * mapWidth + x;
const walkable = walkableData[idx];
ctx.fillStyle = walkable ? '#1e3a5f' : '#1a1a2e';
ctx.fillRect(x * scale, y * scale, scale, scale);
// Grid lines
ctx.strokeStyle = 'rgba(255,255,255,0.05)';
ctx.strokeRect(x * scale, y * scale, scale, scale);
}
}
// Store scale for entity positioning
canvas.dataset.scale = scale;
}
function updateEntities(players, mobs) {
const canvas = document.getElementById('mapCanvas');
const overlay = document.getElementById('entityOverlay');
if (!canvas || !overlay) return;
const scale = parseFloat(canvas.dataset.scale) || 4;
const tileSize = 32; // Game tile size
overlay.innerHTML = '';
// Draw players
players.forEach(p => {
const div = document.createElement('div');
div.className = 'entity-dot player-dot';
div.style.left = (p.x / tileSize * scale) + 'px';
div.style.top = (p.y / tileSize * scale) + 'px';
div.title = p.name;
overlay.appendChild(div);
});
// Draw mobs
mobs.forEach(m => {
if (!m.alive) return;
const div = document.createElement('div');
div.className = 'entity-dot ' + (m.isBoss ? 'boss-dot' : 'mob-dot');
div.style.left = (m.x / tileSize * scale) + 'px';
div.style.top = (m.y / tileSize * scale) + 'px';
div.title = m.name;
overlay.appendChild(div);
});
}
async function fetchUpdate() {
try {
const resp = await fetch(`/admin/dungeons/view?handler=Status&id=${dungeonId}`);
if (resp.ok) {
const data = await resp.json();
document.getElementById('playerCount').textContent = data.playerCount;
document.getElementById('mobCount').textContent = data.mobsAlive;
document.getElementById('duration').textContent = data.duration;
updateEntities(data.players, data.mobs);
}
} catch (e) {
console.error('Failed to fetch update:', e);
}
}
function toggleAutoRefresh() {
autoRefresh = !autoRefresh;
document.getElementById('autoRefreshBtn').textContent = 'Auto: ' + (autoRefresh ? 'ON' : 'OFF');
if (autoRefresh) {
refreshInterval = setInterval(fetchUpdate, 2000);
} else {
clearInterval(refreshInterval);
}
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
initMap();
// Initial entity positions
const initialPlayers = @Html.Raw(Model.PlayersJson);
const initialMobs = @Html.Raw(Model.MobsJson);
updateEntities(initialPlayers, initialMobs);
// Start auto-refresh
refreshInterval = setInterval(fetchUpdate, 2000);
});
// Handle resize
window.addEventListener('resize', initMap);
</script>
}