Persist player overworld location and add world mob spawn editing/runtime payloads
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
var objectsJson = JsonSerializer.Serialize(Model.ObjectDefinitions.Select(o => new { id = o.Id, name = o.Name }));
|
||||
var npcsJson = JsonSerializer.Serialize(Model.NpcDefinitions.Select(n => new { id = n.Id, name = n.Name }));
|
||||
var mobsJson = JsonSerializer.Serialize(Model.MobDefinitions.Select(m => new { id = m.Id, name = m.Name }));
|
||||
var tileDefsJson = JsonSerializer.Serialize(Model.TileDefinitions.Select(t => new
|
||||
{
|
||||
id = t.Id,
|
||||
@@ -45,7 +46,7 @@
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold text-white">World Editor</h1>
|
||||
<p class="text-gray-400 mt-1">Live chunk editing for tiles, objects, and NPC spawns</p>
|
||||
<p class="text-gray-400 mt-1">Live chunk editing for tiles, objects, NPC spawns, and mob spawns</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -132,6 +133,7 @@
|
||||
<option value="tile">Tile</option>
|
||||
<option value="object">Object</option>
|
||||
<option value="npc">NPC</option>
|
||||
<option value="mob">Mob</option>
|
||||
<option value="erase">Erase</option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -141,6 +143,7 @@
|
||||
<option value="tile">Tile</option>
|
||||
<option value="object">Object</option>
|
||||
<option value="npc">NPC</option>
|
||||
<option value="mob">Mob</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -186,6 +189,22 @@
|
||||
<label class="label">NPC</label>
|
||||
<select id="npcDefinitionId" class="input"></select>
|
||||
</div>
|
||||
|
||||
<div class="card p-4 space-y-3">
|
||||
<h2 class="text-lg font-semibold text-white">Mob Tool</h2>
|
||||
<label class="label">Mob</label>
|
||||
<select id="mobDefinitionId" class="input"></select>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<div>
|
||||
<label class="label">Spawn Count</label>
|
||||
<input id="mobSpawnCount" type="number" class="input" min="1" value="1" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">Respawn Sec</label>
|
||||
<input id="mobRespawnSeconds" type="number" class="input" min="0" step="1" value="30" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="xl:col-span-9 space-y-4">
|
||||
@@ -223,6 +242,7 @@
|
||||
const sheets = @Html.Raw(sheetsJson);
|
||||
const objectDefs = @Html.Raw(objectsJson);
|
||||
const npcDefs = @Html.Raw(npcsJson);
|
||||
const mobDefs = @Html.Raw(mobsJson);
|
||||
const tileDefs = @Html.Raw(tileDefsJson);
|
||||
const cdnBaseUrl = '@Model.CdnBaseUrl';
|
||||
|
||||
@@ -232,6 +252,7 @@
|
||||
let currentTiles = new Map();
|
||||
let currentObjects = [];
|
||||
let currentNpcs = [];
|
||||
let currentMobs = [];
|
||||
let eventSource = null;
|
||||
let chunkZoom = 1;
|
||||
const tileDefBySprite = {};
|
||||
@@ -273,6 +294,7 @@
|
||||
|
||||
document.getElementById('objectDefinitionId').innerHTML = objectDefs.map(o => `<option value="${o.id}">${o.name}</option>`).join('');
|
||||
document.getElementById('npcDefinitionId').innerHTML = npcDefs.map(n => `<option value="${n.id}">${n.name}</option>`).join('');
|
||||
document.getElementById('mobDefinitionId').innerHTML = mobDefs.map(m => `<option value="${m.id}">${m.name}</option>`).join('');
|
||||
}
|
||||
|
||||
function refreshRegionSelect(selectedId) {
|
||||
@@ -346,6 +368,7 @@
|
||||
for (const t of data.tiles) preloadSheetImage(t.sheetId);
|
||||
currentObjects = data.objects || [];
|
||||
currentNpcs = data.npcs || [];
|
||||
currentMobs = data.mobs || [];
|
||||
document.getElementById('chunkMeta').textContent = `Chunk ${s.zoneX}:${s.zoneY}:${s.chunkX}:${s.chunkY} v${currentChunk.version} (${currentChunk.width}x${currentChunk.height})`;
|
||||
renderChunk();
|
||||
startStream();
|
||||
@@ -405,15 +428,23 @@
|
||||
else currentNpcs.push({ ...op });
|
||||
} else if (op.type === 'npc_remove') {
|
||||
currentNpcs = currentNpcs.filter(n => n.id !== op.id);
|
||||
} else if (op.type === 'mob_upsert') {
|
||||
const idx = currentMobs.findIndex(m => m.id === op.id);
|
||||
if (idx >= 0) currentMobs[idx] = { ...currentMobs[idx], ...op };
|
||||
else currentMobs.push({ ...op });
|
||||
} else if (op.type === 'mob_remove') {
|
||||
currentMobs = currentMobs.filter(m => m.id !== op.id);
|
||||
} else if (op.type === 'chunk_clear') {
|
||||
currentTiles.clear();
|
||||
currentObjects = [];
|
||||
currentNpcs = [];
|
||||
currentMobs = [];
|
||||
} else if (op.type === 'chunk_deleted') {
|
||||
currentChunk = null;
|
||||
currentTiles.clear();
|
||||
currentObjects = [];
|
||||
currentNpcs = [];
|
||||
currentMobs = [];
|
||||
chunkCtx.clearRect(0, 0, chunkCanvas.width, chunkCanvas.height);
|
||||
document.getElementById('chunkMeta').textContent = 'Chunk deleted';
|
||||
loadZone();
|
||||
@@ -554,6 +585,17 @@
|
||||
chunkCtx.rect(px - Math.max(2, tileSize * 0.2), py - Math.max(2, tileSize * 0.2), Math.max(4, tileSize * 0.4), Math.max(4, tileSize * 0.4));
|
||||
chunkCtx.fill();
|
||||
}
|
||||
for (const m of currentMobs) {
|
||||
const px = m.x * tileSize + tileSize / 2;
|
||||
const py = m.y * tileSize + tileSize / 2;
|
||||
chunkCtx.fillStyle = '#ef4444';
|
||||
chunkCtx.beginPath();
|
||||
chunkCtx.moveTo(px, py - Math.max(3, tileSize * 0.28));
|
||||
chunkCtx.lineTo(px + Math.max(3, tileSize * 0.28), py + Math.max(3, tileSize * 0.28));
|
||||
chunkCtx.lineTo(px - Math.max(3, tileSize * 0.28), py + Math.max(3, tileSize * 0.28));
|
||||
chunkCtx.closePath();
|
||||
chunkCtx.fill();
|
||||
}
|
||||
|
||||
const mode = document.getElementById('paintMode').value;
|
||||
document.getElementById('eraseTargetWrap').classList.toggle('hidden', mode !== 'erase');
|
||||
@@ -636,6 +678,25 @@
|
||||
if (idx >= 0) currentNpcs[idx] = { ...currentNpcs[idx], ...data.op };
|
||||
else currentNpcs.push(data.op);
|
||||
}
|
||||
} else if (mode === 'mob') {
|
||||
const mobDefinitionId = parseInt(document.getElementById('mobDefinitionId').value, 10) || 0;
|
||||
const spawnCount = parseInt(document.getElementById('mobSpawnCount').value, 10) || 1;
|
||||
const respawnSeconds = parseFloat(document.getElementById('mobRespawnSeconds').value) || 30;
|
||||
const data = await postJson('/admin/worldeditor?handler=UpsertMob', {
|
||||
...s,
|
||||
mobDefinitionId,
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
rotation: 0,
|
||||
spawnCount,
|
||||
respawnSeconds
|
||||
});
|
||||
if (data.success) {
|
||||
currentChunk.version = data.chunkVersion;
|
||||
const idx = currentMobs.findIndex(m => m.id === data.op.id);
|
||||
if (idx >= 0) currentMobs[idx] = { ...currentMobs[idx], ...data.op };
|
||||
else currentMobs.push(data.op);
|
||||
}
|
||||
} else if (mode === 'erase') {
|
||||
const eraseTarget = document.getElementById('eraseTarget').value;
|
||||
if (eraseTarget === 'tile') {
|
||||
@@ -662,6 +723,15 @@
|
||||
currentNpcs = currentNpcs.filter(n => n.id !== hit.id);
|
||||
}
|
||||
}
|
||||
} else if (eraseTarget === 'mob') {
|
||||
const hit = currentMobs.find(m => m.x === pos.x && m.y === pos.y);
|
||||
if (hit) {
|
||||
const data = await postJson('/admin/worldeditor?handler=RemoveMob', { ...s, id: hit.id });
|
||||
if (data.success) {
|
||||
currentChunk.version = data.chunkVersion;
|
||||
currentMobs = currentMobs.filter(m => m.id !== hit.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -807,13 +877,14 @@
|
||||
currentTiles.clear();
|
||||
currentObjects = [];
|
||||
currentNpcs = [];
|
||||
currentMobs = [];
|
||||
renderChunk();
|
||||
loadZone();
|
||||
}
|
||||
|
||||
async function deleteChunk() {
|
||||
if (!currentChunk) return;
|
||||
if (!confirm('Delete this chunk and all contained tiles/objects/NPC spawns?')) return;
|
||||
if (!confirm('Delete this chunk and all contained tiles/objects/NPC spawns/mob spawns?')) return;
|
||||
const s = selection();
|
||||
const data = await postJson('/admin/worldeditor?handler=DeleteChunk', s);
|
||||
if (!data.success) return;
|
||||
@@ -821,6 +892,7 @@
|
||||
currentTiles.clear();
|
||||
currentObjects = [];
|
||||
currentNpcs = [];
|
||||
currentMobs = [];
|
||||
chunkCtx.clearRect(0, 0, chunkCanvas.width, chunkCanvas.height);
|
||||
document.getElementById('chunkMeta').textContent = 'Chunk deleted';
|
||||
loadZone();
|
||||
|
||||
Reference in New Issue
Block a user