Files
systemrevivalserver/Services/Admin/Pages/RoomTemplates/Edit.cshtml
T
2025-12-28 09:46:58 -05:00

648 lines
30 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@page "/admin/roomtemplates/edit"
@model RoomTemplates.EditModel
@using DataServer.Data.Entities
@{
ViewData["Title"] = Model.Room.Id == 0 ? "New Room Template" : $"Edit: {Model.Room.Name}";
var roomTypes = Enum.GetValues<RoomType>();
var tileTypes = Enum.GetValues<TileType>();
}
<div class="mb-4">
<a href="/admin/roomtemplates" class="text-blue-400 hover:text-blue-300 text-sm">&larr; Back to Room Templates</a>
</div>
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="mb-4 p-3 rounded text-sm @(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-3 gap-4">
<!-- Room Settings -->
<div class="card p-4">
<h2 class="text-lg font-semibold text-white mb-4">Room Settings</h2>
<form method="post" id="roomForm">
@Html.AntiForgeryToken()
<input type="hidden" asp-for="Room.Id" />
<input type="hidden" asp-for="Room.TileDataJson" id="tileDataJson" />
<input type="hidden" asp-for="Room.SpawnPointsJson" id="spawnPointsJson" />
<input type="hidden" asp-for="Room.ConnectionPointsJson" id="connectionPointsJson" />
<div class="space-y-3">
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Name</label>
<input type="text" asp-for="Room.Name" class="input w-full text-sm" placeholder="Treasure Room A" required />
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Type</label>
<select asp-for="Room.Type" class="input w-full text-sm">
@foreach (var t in roomTypes)
{
<option value="@((int)t)">@t</option>
}
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Description</label>
<textarea asp-for="Room.Description" class="input w-full text-sm" rows="2" placeholder="Optional description"></textarea>
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Tags</label>
<input type="text" asp-for="Room.Tags" class="input w-full text-sm" placeholder="treasure, medium, stone" />
</div>
<div class="grid grid-cols-2 gap-2">
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Width</label>
<input type="number" asp-for="Room.Width" class="input w-full text-sm" min="3" max="50" onchange="resizeGrid()" />
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Height</label>
<input type="number" asp-for="Room.Height" class="input w-full text-sm" min="3" max="50" onchange="resizeGrid()" />
</div>
</div>
<div class="grid grid-cols-2 gap-2">
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Min Tier</label>
<input type="number" asp-for="Room.MinTier" class="input w-full text-sm" min="1" />
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Max Tier (0=∞)</label>
<input type="number" asp-for="Room.MaxTier" class="input w-full text-sm" min="0" />
</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-300 mb-1">Weight</label>
<input type="number" asp-for="Room.Weight" class="input w-full text-sm" min="1" />
<p class="text-xs text-gray-500 mt-1">Higher = more common in generation</p>
</div>
<div class="flex items-center gap-2">
<input type="checkbox" asp-for="Room.IsEnabled" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" />
<label asp-for="Room.IsEnabled" class="text-sm text-gray-300">Enabled</label>
</div>
<div class="pt-3 border-t border-gray-700">
<button type="submit" class="btn btn-primary w-full">Save Room Template</button>
</div>
</div>
</form>
</div>
<!-- Tile Palette & Tools -->
<div class="card p-4">
<h2 class="text-lg font-semibold text-white mb-4">Tools & Palette</h2>
<!-- Tool Mode Selector -->
<div class="mb-4 p-2 bg-gray-800 rounded">
<div class="flex gap-1 mb-2">
<button onclick="setMode('tiles')" class="flex-1 px-2 py-1.5 text-xs rounded mode-btn active" data-mode="tiles">🎨 Tiles</button>
<button onclick="setMode('spawns')" class="flex-1 px-2 py-1.5 text-xs rounded mode-btn" data-mode="spawns">📍 Spawns</button>
<button onclick="setMode('connections')" class="flex-1 px-2 py-1.5 text-xs rounded mode-btn" data-mode="connections">🚪 Connections</button>
</div>
</div>
<!-- Tile Mode Panel -->
<div id="tileModePanel">
@if (Model.TileMapSheets.Count == 0)
{
<p class="text-gray-400 text-sm">No tilemap sheets found. <a href="/admin/tilemaps" class="text-blue-400">Create one first.</a></p>
}
else
{
<!-- TileMap Sheet Selector -->
<div class="mb-3">
<select id="sheetSelector" class="input w-full text-sm" onchange="selectSheet(this.value)">
@foreach (var sheet in Model.TileMapSheets)
{
<option value="@sheet.Id">@sheet.Name (@(sheet.Tiles?.Count ?? 0) tiles)</option>
}
</select>
</div>
<!-- Type Filter -->
<div class="mb-3 flex flex-wrap gap-1">
<button onclick="filterTiles('all')" class="px-2 py-0.5 text-xs rounded bg-gray-700 hover:bg-gray-600 tile-filter active" data-filter="all">All</button>
<button onclick="filterTiles('Floor')" class="px-2 py-0.5 text-xs rounded bg-gray-700 hover:bg-gray-600 tile-filter" data-filter="Floor">Floor</button>
<button onclick="filterTiles('Wall')" class="px-2 py-0.5 text-xs rounded bg-gray-700 hover:bg-gray-600 tile-filter" data-filter="Wall">Wall</button>
<button onclick="filterTiles('Door')" class="px-2 py-0.5 text-xs rounded bg-gray-700 hover:bg-gray-600 tile-filter" data-filter="Door">Door</button>
</div>
<!-- Tile Grid -->
<div id="tilePalette" class="bg-gray-900 rounded p-2 overflow-auto" style="max-height: 35vh;">
<!-- Populated by JavaScript -->
</div>
<!-- Selected Tile Info -->
<div id="selectedTileInfo" class="mt-3 p-2 bg-gray-800 rounded text-xs hidden">
<span class="text-gray-400">Selected:</span>
<span id="selectedTileName" class="text-white ml-1">None</span>
</div>
<!-- Tools -->
<div class="mt-3 flex flex-wrap gap-2">
<button onclick="setTool('paint')" class="btn btn-secondary text-xs py-1 px-2 tool-btn active" data-tool="paint">🖌️ Paint</button>
<button onclick="setTool('erase')" class="btn btn-secondary text-xs py-1 px-2 tool-btn" data-tool="erase">🧹 Erase</button>
<button onclick="setTool('fill')" class="btn btn-secondary text-xs py-1 px-2 tool-btn" data-tool="fill">🪣 Fill</button>
<button onclick="clearAllTiles()" class="btn bg-red-600 hover:bg-red-700 text-xs py-1 px-2">Clear</button>
</div>
}
</div>
<!-- Spawn Mode Panel -->
<div id="spawnModePanel" class="hidden">
<p class="text-sm text-gray-400 mb-3">Click on the grid to place spawn points.</p>
<div class="space-y-2">
<button onclick="setSpawnType('PlayerSpawn')" class="w-full px-3 py-2 text-sm rounded flex items-center gap-2 spawn-type-btn" data-spawn="PlayerSpawn">
<span class="w-6 h-6 bg-green-500 rounded-full flex items-center justify-center text-white text-xs">P</span>
<span>Player Spawn</span>
</button>
<button onclick="setSpawnType('MobSpawn')" class="w-full px-3 py-2 text-sm rounded flex items-center gap-2 spawn-type-btn active" data-spawn="MobSpawn">
<span class="w-6 h-6 bg-red-500 rounded-full flex items-center justify-center text-white text-xs">M</span>
<span>Mob Spawn</span>
</button>
<button onclick="setSpawnType('BossSpawn')" class="w-full px-3 py-2 text-sm rounded flex items-center gap-2 spawn-type-btn" data-spawn="BossSpawn">
<span class="w-6 h-6 bg-purple-500 rounded-full flex items-center justify-center text-white text-xs">B</span>
<span>Boss Spawn</span>
</button>
<button onclick="setSpawnType('ChestSpawn')" class="w-full px-3 py-2 text-sm rounded flex items-center gap-2 spawn-type-btn" data-spawn="ChestSpawn">
<span class="w-6 h-6 bg-yellow-500 rounded-full flex items-center justify-center text-white text-xs">C</span>
<span>Chest Spawn</span>
</button>
</div>
<div class="mt-4 p-2 bg-gray-800 rounded text-xs">
<p class="text-gray-400 mb-2">Spawn Points: <span id="spawnCount">0</span></p>
<button onclick="clearAllSpawns()" class="btn bg-red-600 hover:bg-red-700 text-xs py-1 px-2">Clear All Spawns</button>
</div>
</div>
<!-- Connection Mode Panel -->
<div id="connectionModePanel" class="hidden">
<p class="text-sm text-gray-400 mb-3">Click on room edges to add/remove connection points (where hallways attach).</p>
<div class="grid grid-cols-2 gap-2 mb-4">
<div class="p-2 bg-gray-800 rounded text-center">
<span class="text-cyan-400 font-bold">N</span>
<p class="text-xs text-gray-500">North: <span id="connNorth">0</span></p>
</div>
<div class="p-2 bg-gray-800 rounded text-center">
<span class="text-cyan-400 font-bold">S</span>
<p class="text-xs text-gray-500">South: <span id="connSouth">0</span></p>
</div>
<div class="p-2 bg-gray-800 rounded text-center">
<span class="text-cyan-400 font-bold">E</span>
<p class="text-xs text-gray-500">East: <span id="connEast">0</span></p>
</div>
<div class="p-2 bg-gray-800 rounded text-center">
<span class="text-cyan-400 font-bold">W</span>
<p class="text-xs text-gray-500">West: <span id="connWest">0</span></p>
</div>
</div>
<div class="p-2 bg-gray-800 rounded text-xs">
<p class="text-gray-400 mb-2">Connection Width:</p>
<input type="number" id="connectionWidth" value="2" min="1" max="5" class="input w-full text-sm" />
</div>
<button onclick="clearAllConnections()" class="mt-3 btn bg-red-600 hover:bg-red-700 text-xs py-1 px-2">Clear All Connections</button>
</div>
</div>
<!-- Room Editor Canvas -->
<div class="card p-4 xl:col-span-1">
<div class="flex items-center justify-between mb-4">
<h2 class="text-lg font-semibold text-white">Room Editor</h2>
<span id="gridInfo" class="text-sm text-gray-400">@Model.Room.Width × @Model.Room.Height</span>
</div>
<div class="bg-gray-900 rounded p-2 overflow-auto" style="max-height: 70vh;">
<div id="roomCanvas" class="relative inline-block" style="image-rendering: pixelated;">
<!-- Grid will be rendered by JavaScript -->
</div>
</div>
<div class="mt-3 text-xs text-gray-400">
<p>Tiles: Click to place • Right-click to erase • Drag to paint</p>
<p>Spawns: Click to place/remove • Connections: Click room edges</p>
</div>
<!-- Legend -->
<div class="mt-3 p-2 bg-gray-800 rounded">
<p class="text-xs text-gray-400 mb-2">Legend:</p>
<div class="flex flex-wrap gap-2 text-xs">
<span class="flex items-center gap-1"><span class="w-3 h-3 bg-green-500 rounded-full"></span> Player</span>
<span class="flex items-center gap-1"><span class="w-3 h-3 bg-red-500 rounded-full"></span> Mob</span>
<span class="flex items-center gap-1"><span class="w-3 h-3 bg-purple-500 rounded-full"></span> Boss</span>
<span class="flex items-center gap-1"><span class="w-3 h-3 bg-yellow-500 rounded-full"></span> Chest</span>
<span class="flex items-center gap-1"><span class="w-3 h-3 bg-cyan-500 rounded"></span> Connection</span>
</div>
</div>
</div>
</div>
@section Scripts {
<script>
// Configuration
const TILE_DISPLAY_SIZE = 24;
let roomWidth = @Model.Room.Width;
let roomHeight = @Model.Room.Height;
let currentMode = 'tiles'; // tiles, spawns, connections
let currentTool = 'paint';
let selectedTile = null;
let selectedSheetId = @(Model.TileMapSheets.FirstOrDefault()?.Id ?? 0);
let isMouseDown = false;
let currentFilter = 'all';
let selectedSpawnType = 'MobSpawn';
// Room data
let roomTiles = @Html.Raw(Model.Room.TileDataJson ?? "[]");
let spawnPoints = @Html.Raw(Model.Room.SpawnPointsJson ?? "[]");
let connectionPoints = @Html.Raw(Model.Room.ConnectionPointsJson ?? "[]");
// Tilemap sheets data
const sheets = @Html.Raw(System.Text.Json.JsonSerializer.Serialize(Model.TileMapSheets.Select(s => new {
s.Id, s.Name, s.CdnPath, s.TileWidth, s.TileHeight, s.SheetWidth, s.SheetHeight, s.Columns, s.Rows,
Tiles = (s.Tiles ?? new List<TileDefinition>()).Select(t => new { t.Id, t.FrameIndex, t.Name, Type = (int)t.Type, t.Tags, t.IsWalkable }).ToArray()
})));
const cdnBaseUrl = '@Model.CdnBaseUrl';
const TileType = { Floor: 0, Wall: 1, Door: 2, Water: 3, Lava: 4, Pit: 5, Stairs: 6, PlayerSpawn: 10, MobSpawn: 11, BossSpawn: 12, ChestSpawn: 13 };
const TileTypeName = { 0: 'Floor', 1: 'Wall', 2: 'Door', 3: 'Water', 4: 'Lava', 5: 'Pit', 6: 'Stairs', 10: 'PlayerSpawn', 11: 'MobSpawn', 12: 'BossSpawn', 13: 'ChestSpawn' };
const SpawnColors = { PlayerSpawn: '#22c55e', MobSpawn: '#ef4444', BossSpawn: '#a855f7', ChestSpawn: '#eab308' };
const SpawnLetters = { PlayerSpawn: 'P', MobSpawn: 'M', BossSpawn: 'B', ChestSpawn: 'C' };
// Initialize
document.addEventListener('DOMContentLoaded', () => {
if (sheets.length > 0) {
selectSheet(sheets[0].Id);
}
renderRoomGrid();
updateCounters();
});
// Mode switching
function setMode(mode) {
currentMode = mode;
document.querySelectorAll('.mode-btn').forEach(b => b.classList.remove('active', 'bg-blue-600'));
document.querySelector(`.mode-btn[data-mode="${mode}"]`)?.classList.add('active', 'bg-blue-600');
document.getElementById('tileModePanel').classList.toggle('hidden', mode !== 'tiles');
document.getElementById('spawnModePanel').classList.toggle('hidden', mode !== 'spawns');
document.getElementById('connectionModePanel').classList.toggle('hidden', mode !== 'connections');
renderRoomGrid();
}
// Tile palette
function selectSheet(sheetId) {
selectedSheetId = parseInt(sheetId);
renderTilePalette();
}
function renderTilePalette() {
const sheet = sheets.find(s => s.Id === selectedSheetId);
if (!sheet) return;
const palette = document.getElementById('tilePalette');
const imgUrl = `${cdnBaseUrl}/${sheet.CdnPath}`;
const displaySize = 32;
const scale = displaySize / sheet.TileWidth;
const scaledSheetW = sheet.SheetWidth * scale;
const scaledSheetH = sheet.SheetHeight * scale;
let html = `<div class="grid gap-1" style="grid-template-columns: repeat(auto-fill, minmax(${displaySize}px, 1fr));">`;
for (const tile of sheet.Tiles) {
if (currentFilter !== 'all' && tile.Type !== TileType[currentFilter]) continue;
const col = tile.FrameIndex % sheet.Columns;
const row = Math.floor(tile.FrameIndex / sheet.Columns);
const bgPosX = col * sheet.TileWidth * scale;
const bgPosY = row * sheet.TileHeight * scale;
const isSelected = selectedTile && selectedTile.id === tile.Id;
const borderClass = isSelected ? 'border-yellow-400 border-2' : 'border-gray-600 border';
html += `<div class="cursor-pointer ${borderClass} hover:border-yellow-300 transition-all"
onclick="selectTile(${tile.Id}, ${sheet.Id})"
title="${tile.Name || 'Tile ' + tile.FrameIndex} (${TileTypeName[tile.Type]})"
style="width: ${displaySize}px; height: ${displaySize}px; background-image: url('${imgUrl}'); background-position: -${bgPosX}px -${bgPosY}px; background-size: ${scaledSheetW}px ${scaledSheetH}px; image-rendering: pixelated;">
</div>`;
}
html += '</div>';
palette.innerHTML = html;
}
function selectTile(tileId, sheetId) {
const sheet = sheets.find(s => s.Id === sheetId);
const tile = sheet?.Tiles.find(t => t.Id === tileId);
if (tile) {
selectedTile = { id: tile.Id, sheetId: sheetId, frameIndex: tile.FrameIndex, name: tile.Name || `Tile ${tile.FrameIndex}` };
document.getElementById('selectedTileInfo').classList.remove('hidden');
document.getElementById('selectedTileName').textContent = selectedTile.name;
renderTilePalette();
}
}
function filterTiles(filter) {
currentFilter = filter;
document.querySelectorAll('.tile-filter').forEach(b => b.classList.remove('active', 'bg-blue-600'));
document.querySelector(`.tile-filter[data-filter="${filter}"]`)?.classList.add('active', 'bg-blue-600');
renderTilePalette();
}
function setTool(tool) {
currentTool = tool;
document.querySelectorAll('.tool-btn').forEach(b => b.classList.remove('active', 'bg-blue-600'));
document.querySelector(`.tool-btn[data-tool="${tool}"]`)?.classList.add('active', 'bg-blue-600');
}
function setSpawnType(type) {
selectedSpawnType = type;
document.querySelectorAll('.spawn-type-btn').forEach(b => b.classList.remove('active', 'bg-gray-700'));
document.querySelector(`.spawn-type-btn[data-spawn="${type}"]`)?.classList.add('active', 'bg-gray-700');
}
// Room grid rendering
function renderRoomGrid() {
const canvas = document.getElementById('roomCanvas');
const width = parseInt(document.getElementById('Room_Width').value) || roomWidth;
const height = parseInt(document.getElementById('Room_Height').value) || roomHeight;
roomWidth = width;
roomHeight = height;
document.getElementById('gridInfo').textContent = `${width} × ${height}`;
let html = `<div class="grid relative" style="grid-template-columns: repeat(${width}, ${TILE_DISPLAY_SIZE}px);">`;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const placement = roomTiles.find(t => t.X === x && t.Y === y);
let bgStyle = 'background-color: #1f2937;';
if (placement) {
for (const sheet of sheets) {
const tile = sheet.Tiles.find(t => t.Id === placement.TileDefinitionId);
if (tile) {
const col = tile.FrameIndex % sheet.Columns;
const row = Math.floor(tile.FrameIndex / sheet.Columns);
const scale = TILE_DISPLAY_SIZE / sheet.TileWidth;
bgStyle = `background-image: url('${cdnBaseUrl}/${sheet.CdnPath}'); background-position: -${col * sheet.TileWidth * scale}px -${row * sheet.TileHeight * scale}px; background-size: ${sheet.SheetWidth * scale}px ${sheet.SheetHeight * scale}px;`;
break;
}
}
}
// Check for spawn point
const spawn = spawnPoints.find(s => s.X === x && s.Y === y);
let spawnOverlay = '';
if (spawn) {
const color = SpawnColors[spawn.Type] || '#888';
const letter = SpawnLetters[spawn.Type] || '?';
spawnOverlay = `<div class="absolute inset-0 flex items-center justify-center pointer-events-none">
<span class="w-5 h-5 rounded-full flex items-center justify-center text-white text-xs font-bold" style="background: ${color};">${letter}</span>
</div>`;
}
// Check for connection point
const conn = connectionPoints.find(c => c.X === x && c.Y === y);
let connOverlay = '';
if (conn) {
connOverlay = `<div class="absolute inset-0 border-2 border-cyan-400 pointer-events-none"></div>`;
}
// Edge detection for connection mode
const isEdge = (x === 0 || x === width - 1 || y === 0 || y === height - 1);
const edgeClass = currentMode === 'connections' && isEdge ? 'ring-1 ring-cyan-500/50' : '';
html += `<div class="relative border border-gray-700/50 hover:border-blue-400 cursor-crosshair ${edgeClass}"
style="width: ${TILE_DISPLAY_SIZE}px; height: ${TILE_DISPLAY_SIZE}px; ${bgStyle} image-rendering: pixelated;"
data-x="${x}" data-y="${y}"
onmousedown="handleGridClick(event, ${x}, ${y})"
onmouseenter="handleGridHover(event, ${x}, ${y})"
oncontextmenu="event.preventDefault(); handleRightClick(${x}, ${y});">
${spawnOverlay}${connOverlay}
</div>`;
}
}
html += '</div>';
canvas.innerHTML = html;
}
// Grid interactions
function handleGridClick(event, x, y) {
event.preventDefault();
isMouseDown = true;
if (currentMode === 'tiles') {
if (event.button === 2 || currentTool === 'erase') {
eraseTile(x, y);
} else if (currentTool === 'fill') {
floodFill(x, y);
} else if (selectedTile) {
placeTile(x, y);
}
} else if (currentMode === 'spawns') {
toggleSpawn(x, y);
} else if (currentMode === 'connections') {
toggleConnection(x, y);
}
}
function handleGridHover(event, x, y) {
if (!isMouseDown || currentMode !== 'tiles') return;
if (currentTool === 'erase') {
eraseTile(x, y);
} else if (currentTool === 'paint' && selectedTile) {
placeTile(x, y);
}
}
function handleRightClick(x, y) {
if (currentMode === 'tiles') {
eraseTile(x, y);
} else if (currentMode === 'spawns') {
removeSpawn(x, y);
} else if (currentMode === 'connections') {
removeConnection(x, y);
}
}
document.addEventListener('mouseup', () => { isMouseDown = false; });
// Tile operations
function placeTile(x, y) {
if (!selectedTile) return;
roomTiles = roomTiles.filter(t => !(t.X === x && t.Y === y));
roomTiles.push({ X: x, Y: y, TileDefinitionId: selectedTile.id, Layer: 0, Rotation: 0, FlipX: false, FlipY: false });
updateAllData();
renderRoomGrid();
}
function eraseTile(x, y) {
roomTiles = roomTiles.filter(t => !(t.X === x && t.Y === y));
updateAllData();
renderRoomGrid();
}
function floodFill(startX, startY) {
if (!selectedTile) return;
const existingTile = roomTiles.find(t => t.X === startX && t.Y === startY);
const targetTileId = existingTile?.TileDefinitionId ?? null;
if (targetTileId === selectedTile.id) return;
const stack = [[startX, startY]];
const visited = new Set();
while (stack.length > 0) {
const [x, y] = stack.pop();
const key = `${x},${y}`;
if (visited.has(key) || x < 0 || x >= roomWidth || y < 0 || y >= roomHeight) continue;
visited.add(key);
const tile = roomTiles.find(t => t.X === x && t.Y === y);
if ((tile?.TileDefinitionId ?? null) !== targetTileId) continue;
roomTiles = roomTiles.filter(t => !(t.X === x && t.Y === y));
roomTiles.push({ X: x, Y: y, TileDefinitionId: selectedTile.id, Layer: 0, Rotation: 0, FlipX: false, FlipY: false });
stack.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]);
}
updateAllData();
renderRoomGrid();
}
function clearAllTiles() {
if (!confirm('Clear all tiles?')) return;
roomTiles = [];
updateAllData();
renderRoomGrid();
}
// Spawn operations
function toggleSpawn(x, y) {
const existing = spawnPoints.findIndex(s => s.X === x && s.Y === y);
if (existing >= 0) {
spawnPoints.splice(existing, 1);
} else {
spawnPoints.push({ X: x, Y: y, Type: selectedSpawnType, EntityId: null, Tags: null });
}
updateAllData();
updateCounters();
renderRoomGrid();
}
function removeSpawn(x, y) {
spawnPoints = spawnPoints.filter(s => !(s.X === x && s.Y === y));
updateAllData();
updateCounters();
renderRoomGrid();
}
function clearAllSpawns() {
if (!confirm('Clear all spawn points?')) return;
spawnPoints = [];
updateAllData();
updateCounters();
renderRoomGrid();
}
// Connection operations
function toggleConnection(x, y) {
// Only allow on edges
const isNorth = y === 0;
const isSouth = y === roomHeight - 1;
const isWest = x === 0;
const isEast = x === roomWidth - 1;
if (!isNorth && !isSouth && !isWest && !isEast) return;
const existing = connectionPoints.findIndex(c => c.X === x && c.Y === y);
if (existing >= 0) {
connectionPoints.splice(existing, 1);
} else {
let direction = 'north';
if (isNorth) direction = 'north';
else if (isSouth) direction = 'south';
else if (isEast) direction = 'east';
else if (isWest) direction = 'west';
const width = parseInt(document.getElementById('connectionWidth').value) || 2;
connectionPoints.push({ X: x, Y: y, Direction: direction, Width: width });
}
updateAllData();
updateCounters();
renderRoomGrid();
}
function removeConnection(x, y) {
connectionPoints = connectionPoints.filter(c => !(c.X === x && c.Y === y));
updateAllData();
updateCounters();
renderRoomGrid();
}
function clearAllConnections() {
if (!confirm('Clear all connection points?')) return;
connectionPoints = [];
updateAllData();
updateCounters();
renderRoomGrid();
}
// Utilities
function resizeGrid() {
const newWidth = parseInt(document.getElementById('Room_Width').value) || 10;
const newHeight = parseInt(document.getElementById('Room_Height').value) || 10;
roomTiles = roomTiles.filter(t => t.X < newWidth && t.Y < newHeight);
spawnPoints = spawnPoints.filter(s => s.X < newWidth && s.Y < newHeight);
connectionPoints = connectionPoints.filter(c => c.X < newWidth && c.Y < newHeight);
roomWidth = newWidth;
roomHeight = newHeight;
updateAllData();
updateCounters();
renderRoomGrid();
}
function updateAllData() {
document.getElementById('tileDataJson').value = JSON.stringify(roomTiles);
document.getElementById('spawnPointsJson').value = JSON.stringify(spawnPoints);
document.getElementById('connectionPointsJson').value = JSON.stringify(connectionPoints);
}
function updateCounters() {
document.getElementById('spawnCount').textContent = spawnPoints.length;
document.getElementById('connNorth').textContent = connectionPoints.filter(c => c.Direction === 'north').length;
document.getElementById('connSouth').textContent = connectionPoints.filter(c => c.Direction === 'south').length;
document.getElementById('connEast').textContent = connectionPoints.filter(c => c.Direction === 'east').length;
document.getElementById('connWest').textContent = connectionPoints.filter(c => c.Direction === 'west').length;
}
// Save on form submit
document.getElementById('roomForm').addEventListener('submit', () => {
updateAllData();
});
</script>
<style>
.tool-btn.active, .tile-filter.active, .mode-btn.active { background-color: #2563eb !important; }
.spawn-type-btn { background-color: #374151; }
.spawn-type-btn:hover { background-color: #4b5563; }
.spawn-type-btn.active { background-color: #4b5563; border: 1px solid #6b7280; }
</style>
}