Dungeon Builder p4
This commit is contained in:
@@ -85,64 +85,136 @@
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<input type="checkbox" asp-for="Room.IsEnabled" class="rounded" />
|
||||
<label asp-for="Room.IsEnabled" class="text-gray-300 text-sm">Enabled</label>
|
||||
<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>
|
||||
|
||||
<button type="submit" class="btn btn-primary w-full">
|
||||
@(Model.Room.Id == 0 ? "Create Room" : "Save Changes")
|
||||
</button>
|
||||
<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 -->
|
||||
<!-- Tile Palette & Tools -->
|
||||
<div class="card p-4">
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Tile Palette</h2>
|
||||
<h2 class="text-lg font-semibold text-white mb-4">Tools & Palette</h2>
|
||||
|
||||
@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>
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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 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>
|
||||
|
||||
<!-- Tile Grid -->
|
||||
<div id="tilePalette" class="bg-gray-900 rounded p-2 overflow-auto" style="max-height: 50vh;">
|
||||
<!-- Populated by JavaScript -->
|
||||
<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>
|
||||
|
||||
<!-- 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 All</button>
|
||||
</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 -->
|
||||
@@ -158,8 +230,21 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-3 flex flex-wrap gap-2 text-xs">
|
||||
<span class="text-gray-400">Click to place • Right-click to erase • Drag to paint</span>
|
||||
<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>
|
||||
@@ -167,17 +252,21 @@
|
||||
@section Scripts {
|
||||
<script>
|
||||
// Configuration
|
||||
const TILE_DISPLAY_SIZE = 24; // Display size of tiles in editor
|
||||
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 - array of tile placements
|
||||
// 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 {
|
||||
@@ -187,14 +276,34 @@
|
||||
|
||||
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();
|
||||
@@ -206,8 +315,6 @@
|
||||
|
||||
const palette = document.getElementById('tilePalette');
|
||||
const imgUrl = `${cdnBaseUrl}/${sheet.CdnPath}`;
|
||||
|
||||
// Calculate scale to fit tiles in 32x32 display boxes
|
||||
const displaySize = 32;
|
||||
const scale = displaySize / sheet.TileWidth;
|
||||
const scaledSheetW = sheet.SheetWidth * scale;
|
||||
@@ -220,7 +327,6 @@
|
||||
|
||||
const col = tile.FrameIndex % sheet.Columns;
|
||||
const row = Math.floor(tile.FrameIndex / sheet.Columns);
|
||||
// Scale the position too
|
||||
const bgPosX = col * sheet.TileWidth * scale;
|
||||
const bgPosY = row * sheet.TileHeight * scale;
|
||||
|
||||
@@ -238,9 +344,6 @@
|
||||
palette.innerHTML = html;
|
||||
}
|
||||
|
||||
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' };
|
||||
|
||||
function selectTile(tileId, sheetId) {
|
||||
const sheet = sheets.find(s => s.Id === sheetId);
|
||||
const tile = sheet?.Tiles.find(t => t.Id === tileId);
|
||||
@@ -248,7 +351,7 @@
|
||||
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(); // Refresh to show selection
|
||||
renderTilePalette();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,6 +368,13 @@
|
||||
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;
|
||||
@@ -274,7 +384,7 @@
|
||||
|
||||
document.getElementById('gridInfo').textContent = `${width} × ${height}`;
|
||||
|
||||
let html = `<div class="grid" style="grid-template-columns: repeat(${width}, ${TILE_DISPLAY_SIZE}px);">`;
|
||||
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++) {
|
||||
@@ -282,7 +392,6 @@
|
||||
let bgStyle = 'background-color: #1f2937;';
|
||||
|
||||
if (placement) {
|
||||
// Find the tile and render it
|
||||
for (const sheet of sheets) {
|
||||
const tile = sheet.Tiles.find(t => t.Id === placement.TileDefinitionId);
|
||||
if (tile) {
|
||||
@@ -295,12 +404,35 @@
|
||||
}
|
||||
}
|
||||
|
||||
html += `<div class="border border-gray-700/50 hover:border-blue-400 cursor-crosshair"
|
||||
// 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="handleTileClick(event, ${x}, ${y})"
|
||||
onmouseenter="handleTileHover(event, ${x}, ${y})"
|
||||
oncontextmenu="event.preventDefault(); eraseTile(${x}, ${y});">
|
||||
onmousedown="handleGridClick(event, ${x}, ${y})"
|
||||
onmouseenter="handleGridHover(event, ${x}, ${y})"
|
||||
oncontextmenu="event.preventDefault(); handleRightClick(${x}, ${y});">
|
||||
${spawnOverlay}${connOverlay}
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
@@ -309,21 +441,28 @@
|
||||
canvas.innerHTML = html;
|
||||
}
|
||||
|
||||
function handleTileClick(event, x, y) {
|
||||
// Grid interactions
|
||||
function handleGridClick(event, x, y) {
|
||||
event.preventDefault();
|
||||
isMouseDown = true;
|
||||
|
||||
if (event.button === 2 || currentTool === 'erase') {
|
||||
eraseTile(x, y);
|
||||
} else if (currentTool === 'fill') {
|
||||
floodFill(x, y);
|
||||
} else if (selectedTile) {
|
||||
placeTile(x, y);
|
||||
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 handleTileHover(event, x, y) {
|
||||
if (!isMouseDown) return;
|
||||
function handleGridHover(event, x, y) {
|
||||
if (!isMouseDown || currentMode !== 'tiles') return;
|
||||
|
||||
if (currentTool === 'erase') {
|
||||
eraseTile(x, y);
|
||||
@@ -332,42 +471,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Remove existing tile at this position
|
||||
roomTiles = roomTiles.filter(t => !(t.X === x && t.Y === y));
|
||||
|
||||
// Add new tile
|
||||
roomTiles.push({
|
||||
X: x,
|
||||
Y: y,
|
||||
TileDefinitionId: selectedTile.id,
|
||||
Layer: 0,
|
||||
Rotation: 0,
|
||||
FlipX: false,
|
||||
FlipY: false
|
||||
});
|
||||
|
||||
updateTileData();
|
||||
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));
|
||||
updateTileData();
|
||||
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; // Already same tile
|
||||
if (targetTileId === selectedTile.id) return;
|
||||
|
||||
const stack = [[startX, startY]];
|
||||
const visited = new Set();
|
||||
@@ -375,60 +510,138 @@
|
||||
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);
|
||||
const currentTileId = tile?.TileDefinitionId ?? null;
|
||||
if ((tile?.TileDefinitionId ?? null) !== targetTileId) continue;
|
||||
|
||||
if (currentTileId !== targetTileId) continue;
|
||||
|
||||
// Place tile
|
||||
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
|
||||
});
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
updateTileData();
|
||||
updateAllData();
|
||||
renderRoomGrid();
|
||||
}
|
||||
|
||||
function clearAllTiles() {
|
||||
if (!confirm('Clear all tiles from this room?')) return;
|
||||
if (!confirm('Clear all tiles?')) return;
|
||||
roomTiles = [];
|
||||
updateTileData();
|
||||
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;
|
||||
|
||||
// Remove tiles outside new bounds
|
||||
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;
|
||||
updateTileData();
|
||||
updateAllData();
|
||||
updateCounters();
|
||||
renderRoomGrid();
|
||||
}
|
||||
|
||||
function updateTileData() {
|
||||
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', () => {
|
||||
updateTileData();
|
||||
updateAllData();
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
.tool-btn.active, .tile-filter.active { background-color: #2563eb !important; }
|
||||
.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>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user