Namespace Cleanup, and some fun toys in the admin portal
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
@page "/admin/dungeons/view"
|
||||
@model Admin.Pages.Dungeons.ViewModel
|
||||
@model GameServices.Admin.Pages.Dungeons.ViewModel
|
||||
@{
|
||||
ViewData["Title"] = $"Dungeon View - Tier {Model.Dungeon?.Tier}";
|
||||
}
|
||||
@@ -19,7 +19,12 @@
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
pointer-events: none;
|
||||
cursor: pointer;
|
||||
transition: transform 0.1s;
|
||||
}
|
||||
.entity-dot:hover {
|
||||
transform: translate(-50%, -50%) scale(1.5);
|
||||
z-index: 100;
|
||||
}
|
||||
.player-dot {
|
||||
background: #4ade80;
|
||||
@@ -29,8 +34,11 @@
|
||||
}
|
||||
.mob-dot {
|
||||
background: #f87171;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
.mob-dot:hover {
|
||||
box-shadow: 0 0 8px #f87171;
|
||||
}
|
||||
.boss-dot {
|
||||
background: #fbbf24;
|
||||
@@ -38,6 +46,10 @@
|
||||
height: 12px;
|
||||
box-shadow: 0 0 8px #fbbf24;
|
||||
}
|
||||
.mob-dot.selected, .boss-dot.selected {
|
||||
outline: 2px solid white;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.stat-card {
|
||||
background: rgba(30, 30, 50, 0.8);
|
||||
border: 1px solid #374151;
|
||||
@@ -64,6 +76,22 @@
|
||||
background: linear-gradient(90deg, #ef4444, #22c55e);
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
.mob-inspector {
|
||||
background: rgba(20, 20, 40, 0.95);
|
||||
border: 1px solid #4f46e5;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
min-width: 280px;
|
||||
}
|
||||
.inspector-stat {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 4px 0;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.1);
|
||||
}
|
||||
.inspector-stat:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="mb-4">
|
||||
@@ -89,7 +117,7 @@ else
|
||||
<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>
|
||||
<span id="refreshRate">500ms</span>
|
||||
<button onclick="toggleAutoRefresh()" id="autoRefreshBtn" class="btn btn-sm btn-ghost ml-2">
|
||||
Auto: ON
|
||||
</button>
|
||||
@@ -108,7 +136,7 @@ else
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-2 h-2 rounded-full bg-red-400"></div>
|
||||
<span>Mobs</span>
|
||||
<span>Mobs (click to inspect)</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<div class="w-3 h-3 rounded-full bg-yellow-400"></div>
|
||||
@@ -118,10 +146,32 @@ else
|
||||
<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>
|
||||
|
||||
<!-- Mob Inspector (shown when mob is selected) -->
|
||||
<div id="mobInspector" class="mob-inspector mt-4 hidden">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<h3 class="text-lg font-semibold text-white" id="inspectorMobName">Mob Name</h3>
|
||||
<button onclick="closeMobInspector()" class="text-gray-400 hover:text-white">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div id="inspectorContent" class="space-y-1 text-sm">
|
||||
<!-- Populated by JS -->
|
||||
</div>
|
||||
<div class="flex gap-2 mt-4">
|
||||
<button onclick="killSelectedMob()" class="btn btn-danger btn-sm flex-1">
|
||||
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
|
||||
</svg>
|
||||
Kill Mob
|
||||
</button>
|
||||
<button onclick="teleportToMob()" class="btn btn-secondary btn-sm flex-1">
|
||||
📍 Copy Position
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -150,7 +200,7 @@ else
|
||||
</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")">
|
||||
<span class="@(Model.Dungeon.Simulation.Phase == GameServer.Dungeon.DungeonPhase.Active ? "text-green-400" : "text-blue-400")">
|
||||
@Model.Dungeon.Simulation.Phase
|
||||
</span>
|
||||
</div>
|
||||
@@ -194,6 +244,37 @@ else
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Spawn Mob -->
|
||||
<div class="stat-card">
|
||||
<h3 class="text-lg font-semibold text-white mb-3">Spawn Mob</h3>
|
||||
<div class="space-y-2">
|
||||
<select id="spawnMobSelect" class="input text-sm w-full">
|
||||
<option value="">Select a mob...</option>
|
||||
@foreach (var mob in Model.MobDefinitions)
|
||||
{
|
||||
<option value="@mob.Id">@mob.Name (T@mob.MinTier-@mob.MaxTier)</option>
|
||||
}
|
||||
</select>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">X</label>
|
||||
<input type="number" id="spawnX" class="input text-sm" placeholder="X pos" value="@(Model.MapWidth / 2 * 32)" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-xs text-gray-400">Y</label>
|
||||
<input type="number" id="spawnY" class="input text-sm" placeholder="Y pos" value="@(Model.MapHeight / 2 * 32)" />
|
||||
</div>
|
||||
</div>
|
||||
<button onclick="spawnMob()" class="btn btn-success w-full text-sm">
|
||||
<svg class="w-4 h-4 mr-1 inline" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
|
||||
</svg>
|
||||
Spawn Mob
|
||||
</button>
|
||||
<p class="text-xs text-gray-500">Click on map to set spawn position</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Players -->
|
||||
<div class="stat-card">
|
||||
<h3 class="text-lg font-semibold text-white mb-3">Players (@Model.Dungeon.Simulation.Players.Count)</h3>
|
||||
@@ -256,9 +337,13 @@ else
|
||||
const mapWidth = @(Model.MapWidth);
|
||||
const mapHeight = @(Model.MapHeight);
|
||||
const walkableData = @Html.Raw(Model.WalkableJson);
|
||||
const tileSize = 32;
|
||||
|
||||
let autoRefresh = true;
|
||||
let refreshInterval;
|
||||
let selectedMobId = null;
|
||||
let currentMobs = [];
|
||||
let mapScale = 4;
|
||||
|
||||
function initMap() {
|
||||
const canvas = document.getElementById('mapCanvas');
|
||||
@@ -266,14 +351,14 @@ else
|
||||
if (!canvas || !container) return;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
const scale = Math.min(
|
||||
mapScale = Math.min(
|
||||
(container.clientWidth - 20) / mapWidth,
|
||||
(container.clientHeight - 20) / mapHeight,
|
||||
8 // Max scale
|
||||
);
|
||||
|
||||
canvas.width = mapWidth * scale;
|
||||
canvas.height = mapHeight * scale;
|
||||
canvas.width = mapWidth * mapScale;
|
||||
canvas.height = mapHeight * mapScale;
|
||||
canvas.style.width = canvas.width + 'px';
|
||||
canvas.style.height = canvas.height + 'px';
|
||||
|
||||
@@ -284,16 +369,25 @@ else
|
||||
const walkable = walkableData[idx];
|
||||
|
||||
ctx.fillStyle = walkable ? '#1e3a5f' : '#1a1a2e';
|
||||
ctx.fillRect(x * scale, y * scale, scale, scale);
|
||||
ctx.fillRect(x * mapScale, y * mapScale, mapScale, mapScale);
|
||||
|
||||
// Grid lines
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.05)';
|
||||
ctx.strokeRect(x * scale, y * scale, scale, scale);
|
||||
ctx.strokeRect(x * mapScale, y * mapScale, mapScale, mapScale);
|
||||
}
|
||||
}
|
||||
|
||||
// Store scale for entity positioning
|
||||
canvas.dataset.scale = scale;
|
||||
canvas.dataset.scale = mapScale;
|
||||
|
||||
// Click handler for spawn position
|
||||
canvas.onclick = function(e) {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const x = Math.floor((e.clientX - rect.left) / mapScale) * tileSize + tileSize / 2;
|
||||
const y = Math.floor((e.clientY - rect.top) / mapScale) * tileSize + tileSize / 2;
|
||||
document.getElementById('spawnX').value = Math.round(x);
|
||||
document.getElementById('spawnY').value = Math.round(y);
|
||||
};
|
||||
}
|
||||
|
||||
function updateEntities(players, mobs) {
|
||||
@@ -301,18 +395,16 @@ else
|
||||
const overlay = document.getElementById('entityOverlay');
|
||||
if (!canvas || !overlay) return;
|
||||
|
||||
const scale = parseFloat(canvas.dataset.scale) || 4;
|
||||
const tileSize = 32; // Game tile size
|
||||
|
||||
currentMobs = mobs;
|
||||
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;
|
||||
div.style.left = (p.x / tileSize * mapScale) + 'px';
|
||||
div.style.top = (p.y / tileSize * mapScale) + 'px';
|
||||
div.title = `${p.name} (${Math.round(p.x)}, ${Math.round(p.y)})`;
|
||||
overlay.appendChild(div);
|
||||
});
|
||||
|
||||
@@ -321,13 +413,105 @@ else
|
||||
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;
|
||||
if (m.id === selectedMobId) div.classList.add('selected');
|
||||
div.style.left = (m.x / tileSize * mapScale) + 'px';
|
||||
div.style.top = (m.y / tileSize * mapScale) + 'px';
|
||||
div.title = `${m.name} - Click to inspect`;
|
||||
div.dataset.mobId = m.id;
|
||||
div.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
selectMob(m);
|
||||
};
|
||||
overlay.appendChild(div);
|
||||
});
|
||||
}
|
||||
|
||||
function selectMob(mob) {
|
||||
selectedMobId = mob.id;
|
||||
|
||||
// Update selection visual
|
||||
document.querySelectorAll('.entity-dot').forEach(d => d.classList.remove('selected'));
|
||||
document.querySelector(`[data-mob-id="${mob.id}"]`)?.classList.add('selected');
|
||||
|
||||
// Show inspector
|
||||
const inspector = document.getElementById('mobInspector');
|
||||
inspector.classList.remove('hidden');
|
||||
|
||||
document.getElementById('inspectorMobName').textContent = mob.name + (mob.isBoss ? ' ⭐' : '');
|
||||
|
||||
document.getElementById('inspectorContent').innerHTML = `
|
||||
<div class="inspector-stat"><span class="text-gray-400">ID</span><span class="text-white font-mono text-xs">${mob.id}</span></div>
|
||||
<div class="inspector-stat"><span class="text-gray-400">Type</span><span class="text-white">${mob.type || 'Normal'}</span></div>
|
||||
<div class="inspector-stat"><span class="text-gray-400">Health</span><span class="text-white">${mob.health} / ${mob.maxHealth}</span></div>
|
||||
<div class="inspector-stat"><span class="text-gray-400">Position</span><span class="text-white">${Math.round(mob.x)}, ${Math.round(mob.y)}</span></div>
|
||||
<div class="inspector-stat"><span class="text-gray-400">State</span><span class="text-white">${mob.state || 'Unknown'}</span></div>
|
||||
<div class="inspector-stat"><span class="text-gray-400">Definition ID</span><span class="text-white">${mob.definitionId || 'N/A'}</span></div>
|
||||
`;
|
||||
}
|
||||
|
||||
function closeMobInspector() {
|
||||
selectedMobId = null;
|
||||
document.getElementById('mobInspector').classList.add('hidden');
|
||||
document.querySelectorAll('.entity-dot').forEach(d => d.classList.remove('selected'));
|
||||
}
|
||||
|
||||
async function killSelectedMob() {
|
||||
if (!selectedMobId) return;
|
||||
|
||||
try {
|
||||
const resp = await fetch(`/admin/dungeons/view?handler=KillMob&id=${dungeonId}&mobId=${selectedMobId}`, {
|
||||
method: 'POST',
|
||||
headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
|
||||
});
|
||||
|
||||
if (resp.ok) {
|
||||
closeMobInspector();
|
||||
fetchUpdate();
|
||||
} else {
|
||||
alert('Failed to kill mob');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to kill mob:', e);
|
||||
alert('Error killing mob');
|
||||
}
|
||||
}
|
||||
|
||||
function teleportToMob() {
|
||||
const mob = currentMobs.find(m => m.id === selectedMobId);
|
||||
if (mob) {
|
||||
navigator.clipboard.writeText(`${Math.round(mob.x)}, ${Math.round(mob.y)}`);
|
||||
alert(`Position copied: ${Math.round(mob.x)}, ${Math.round(mob.y)}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function spawnMob() {
|
||||
const mobDefId = document.getElementById('spawnMobSelect').value;
|
||||
const x = document.getElementById('spawnX').value;
|
||||
const y = document.getElementById('spawnY').value;
|
||||
|
||||
if (!mobDefId) {
|
||||
alert('Please select a mob to spawn');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await fetch(`/admin/dungeons/view?handler=SpawnMob&id=${dungeonId}&mobDefId=${mobDefId}&x=${x}&y=${y}`, {
|
||||
method: 'POST',
|
||||
headers: { 'RequestVerificationToken': document.querySelector('[name="__RequestVerificationToken"]').value }
|
||||
});
|
||||
|
||||
if (resp.ok) {
|
||||
fetchUpdate();
|
||||
} else {
|
||||
const text = await resp.text();
|
||||
alert('Failed to spawn mob: ' + text);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to spawn mob:', e);
|
||||
alert('Error spawning mob');
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchUpdate() {
|
||||
try {
|
||||
const resp = await fetch(`/admin/dungeons/view?handler=Status&id=${dungeonId}`);
|
||||
@@ -337,6 +521,16 @@ else
|
||||
document.getElementById('mobCount').textContent = data.mobsAlive;
|
||||
document.getElementById('duration').textContent = data.duration;
|
||||
updateEntities(data.players, data.mobs);
|
||||
|
||||
// Update selected mob info if still selected
|
||||
if (selectedMobId) {
|
||||
const mob = data.mobs.find(m => m.id === selectedMobId);
|
||||
if (mob && mob.alive) {
|
||||
selectMob(mob);
|
||||
} else {
|
||||
closeMobInspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch update:', e);
|
||||
@@ -348,7 +542,7 @@ else
|
||||
document.getElementById('autoRefreshBtn').textContent = 'Auto: ' + (autoRefresh ? 'ON' : 'OFF');
|
||||
|
||||
if (autoRefresh) {
|
||||
refreshInterval = setInterval(fetchUpdate, 2000);
|
||||
refreshInterval = setInterval(fetchUpdate, 500);
|
||||
} else {
|
||||
clearInterval(refreshInterval);
|
||||
}
|
||||
@@ -363,8 +557,8 @@ else
|
||||
const initialMobs = @Html.Raw(Model.MobsJson);
|
||||
updateEntities(initialPlayers, initialMobs);
|
||||
|
||||
// Start auto-refresh
|
||||
refreshInterval = setInterval(fetchUpdate, 2000);
|
||||
// Start auto-refresh at 500ms (faster updates)
|
||||
refreshInterval = setInterval(fetchUpdate, 500);
|
||||
});
|
||||
|
||||
// Handle resize
|
||||
|
||||
Reference in New Issue
Block a user