Add world editor region creation and document overworld client/runtime gaps
This commit is contained in:
@@ -89,6 +89,41 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-4 space-y-3">
|
||||||
|
<h2 class="text-lg font-semibold text-white">Region Management</h2>
|
||||||
|
<div>
|
||||||
|
<label class="label">Name</label>
|
||||||
|
<input id="newRegionName" type="text" class="input" placeholder="New Region Name" />
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
<div>
|
||||||
|
<label class="label">Zones X</label>
|
||||||
|
<input id="newZonesX" type="number" class="input" min="1" value="4" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label">Zones Y</label>
|
||||||
|
<input id="newZonesY" type="number" class="input" min="1" value="4" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label">Chunks X</label>
|
||||||
|
<input id="newChunksX" type="number" class="input" min="1" value="8" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label">Chunks Y</label>
|
||||||
|
<input id="newChunksY" type="number" class="input" min="1" value="8" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label">Chunk W</label>
|
||||||
|
<input id="newChunkW" type="number" class="input" min="8" value="64" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="label">Chunk H</label>
|
||||||
|
<input id="newChunkH" type="number" class="input" min="8" value="64" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn btn-primary w-full" onclick="createRegion()">Create Region</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="card p-4 space-y-3">
|
<div class="card p-4 space-y-3">
|
||||||
<h2 class="text-lg font-semibold text-white">Paint Mode</h2>
|
<h2 class="text-lg font-semibold text-white">Paint Mode</h2>
|
||||||
<div>
|
<div>
|
||||||
@@ -184,7 +219,7 @@
|
|||||||
|
|
||||||
@section Scripts {
|
@section Scripts {
|
||||||
<script>
|
<script>
|
||||||
const regions = @Html.Raw(regionsJson);
|
let regions = @Html.Raw(regionsJson);
|
||||||
const sheets = @Html.Raw(sheetsJson);
|
const sheets = @Html.Raw(sheetsJson);
|
||||||
const objectDefs = @Html.Raw(objectsJson);
|
const objectDefs = @Html.Raw(objectsJson);
|
||||||
const npcDefs = @Html.Raw(npcsJson);
|
const npcDefs = @Html.Raw(npcsJson);
|
||||||
@@ -226,8 +261,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const regionSel = document.getElementById('regionId');
|
const regionSel = document.getElementById('regionId');
|
||||||
regionSel.innerHTML = regions.map(r => `<option value="${r.id}">${r.name}</option>`).join('');
|
refreshRegionSelect('@Model.SelectedRegionId');
|
||||||
regionSel.value = '@Model.SelectedRegionId';
|
|
||||||
regionSel.addEventListener('change', () => {
|
regionSel.addEventListener('change', () => {
|
||||||
loadRegion();
|
loadRegion();
|
||||||
});
|
});
|
||||||
@@ -241,6 +275,16 @@
|
|||||||
document.getElementById('npcDefinitionId').innerHTML = npcDefs.map(n => `<option value="${n.id}">${n.name}</option>`).join('');
|
document.getElementById('npcDefinitionId').innerHTML = npcDefs.map(n => `<option value="${n.id}">${n.name}</option>`).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refreshRegionSelect(selectedId) {
|
||||||
|
const regionSel = document.getElementById('regionId');
|
||||||
|
regionSel.innerHTML = regions.map(r => `<option value="${r.id}">${r.name}</option>`).join('');
|
||||||
|
if (selectedId !== undefined && selectedId !== null && selectedId !== '') {
|
||||||
|
regionSel.value = String(selectedId);
|
||||||
|
} else if (regions.length) {
|
||||||
|
regionSel.value = String(regions[0].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getJson(url) {
|
async function getJson(url) {
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
return await res.json();
|
return await res.json();
|
||||||
@@ -782,6 +826,35 @@
|
|||||||
loadZone();
|
loadZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createRegion() {
|
||||||
|
const name = document.getElementById('newRegionName').value.trim();
|
||||||
|
if (!name) return;
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
name,
|
||||||
|
zonesPerRegionX: parseInt(document.getElementById('newZonesX').value, 10) || 4,
|
||||||
|
zonesPerRegionY: parseInt(document.getElementById('newZonesY').value, 10) || 4,
|
||||||
|
chunksPerZoneX: parseInt(document.getElementById('newChunksX').value, 10) || 8,
|
||||||
|
chunksPerZoneY: parseInt(document.getElementById('newChunksY').value, 10) || 8,
|
||||||
|
chunkWidthTiles: parseInt(document.getElementById('newChunkW').value, 10) || 64,
|
||||||
|
chunkHeightTiles: parseInt(document.getElementById('newChunkH').value, 10) || 64
|
||||||
|
};
|
||||||
|
|
||||||
|
const data = await postJson('/admin/worldeditor?handler=CreateRegion', payload);
|
||||||
|
if (!data.success || !data.region) return;
|
||||||
|
|
||||||
|
regions.push(data.region);
|
||||||
|
regions = regions.sort((a, b) => a.id - b.id);
|
||||||
|
refreshRegionSelect(data.region.id);
|
||||||
|
document.getElementById('zoneX').value = 0;
|
||||||
|
document.getElementById('zoneY').value = 0;
|
||||||
|
document.getElementById('chunkX').value = 0;
|
||||||
|
document.getElementById('chunkY').value = 0;
|
||||||
|
document.getElementById('newRegionName').value = '';
|
||||||
|
await loadRegion();
|
||||||
|
await loadChunk();
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('frameIndex').addEventListener('input', onSheetChanged);
|
document.getElementById('frameIndex').addEventListener('input', onSheetChanged);
|
||||||
sheetPickerCanvas.addEventListener('click', (e) => {
|
sheetPickerCanvas.addEventListener('click', (e) => {
|
||||||
const sheetId = parseInt(document.getElementById('sheetId').value, 10) || 0;
|
const sheetId = parseInt(document.getElementById('sheetId').value, 10) || 0;
|
||||||
|
|||||||
@@ -131,6 +131,62 @@ public class IndexModel : AdminPageModel
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostCreateRegionAsync(
|
||||||
|
string name,
|
||||||
|
int zonesPerRegionX = 4,
|
||||||
|
int zonesPerRegionY = 4,
|
||||||
|
int chunksPerZoneX = 8,
|
||||||
|
int chunksPerZoneY = 8,
|
||||||
|
int chunkWidthTiles = 64,
|
||||||
|
int chunkHeightTiles = 64)
|
||||||
|
{
|
||||||
|
name = (name ?? string.Empty).Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
return new JsonResult(new { success = false, error = "name_required" }) { StatusCode = 400 };
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = await _db.WorldRegions.AnyAsync(r => r.IsEnabled && r.Name == name);
|
||||||
|
if (exists)
|
||||||
|
{
|
||||||
|
return new JsonResult(new { success = false, error = "region_name_exists" }) { StatusCode = 409 };
|
||||||
|
}
|
||||||
|
|
||||||
|
var region = new WorldRegion
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
ZonesPerRegionX = Math.Clamp(zonesPerRegionX, 1, 32),
|
||||||
|
ZonesPerRegionY = Math.Clamp(zonesPerRegionY, 1, 32),
|
||||||
|
ChunksPerZoneX = Math.Clamp(chunksPerZoneX, 1, 32),
|
||||||
|
ChunksPerZoneY = Math.Clamp(chunksPerZoneY, 1, 32),
|
||||||
|
ChunkWidthTiles = Math.Clamp(chunkWidthTiles, 8, 512),
|
||||||
|
ChunkHeightTiles = Math.Clamp(chunkHeightTiles, 8, 512),
|
||||||
|
IsEnabled = true,
|
||||||
|
CreatedAt = DateTime.UtcNow,
|
||||||
|
UpdatedAt = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
_db.WorldRegions.Add(region);
|
||||||
|
await _db.SaveChangesAsync();
|
||||||
|
await EnsureZonesAsync(region);
|
||||||
|
|
||||||
|
return new JsonResult(new
|
||||||
|
{
|
||||||
|
success = true,
|
||||||
|
region = new
|
||||||
|
{
|
||||||
|
id = region.Id,
|
||||||
|
name = region.Name,
|
||||||
|
zonesX = region.ZonesPerRegionX,
|
||||||
|
zonesY = region.ZonesPerRegionY,
|
||||||
|
chunksPerZoneX = region.ChunksPerZoneX,
|
||||||
|
chunksPerZoneY = region.ChunksPerZoneY,
|
||||||
|
chunkWidthTiles = region.ChunkWidthTiles,
|
||||||
|
chunkHeightTiles = region.ChunkHeightTiles
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetZoneAsync(int regionId, int zoneX, int zoneY)
|
public async Task<IActionResult> OnGetZoneAsync(int regionId, int zoneX, int zoneY)
|
||||||
{
|
{
|
||||||
var region = await _db.WorldRegions.FirstOrDefaultAsync(r => r.Id == regionId && r.IsEnabled);
|
var region = await _db.WorldRegions.FirstOrDefaultAsync(r => r.Id == regionId && r.IsEnabled);
|
||||||
|
|||||||
@@ -114,6 +114,27 @@
|
|||||||
- `object_remove`: `{ id }`
|
- `object_remove`: `{ id }`
|
||||||
- `npc_upsert`: `{ id, x, y, npcDefinitionId, npcName, rotation, metadataJson }`
|
- `npc_upsert`: `{ id, x, y, npcDefinitionId, npcName, rotation, metadataJson }`
|
||||||
- `npc_remove`: `{ id }`
|
- `npc_remove`: `{ id }`
|
||||||
|
- `chunk_clear`: `{}`
|
||||||
|
- `chunk_deleted`: `{}`
|
||||||
|
|
||||||
|
### Browser world editor additions
|
||||||
|
|
||||||
|
- Region creation endpoint:
|
||||||
|
- `POST /admin/worldeditor?handler=CreateRegion`
|
||||||
|
- Request: `{ name, zonesPerRegionX, zonesPerRegionY, chunksPerZoneX, chunksPerZoneY, chunkWidthTiles, chunkHeightTiles }`
|
||||||
|
- Response: `{ success, region }`
|
||||||
|
- Chunk maintenance endpoints:
|
||||||
|
- `POST /admin/worldeditor?handler=ClearChunk`
|
||||||
|
- `POST /admin/worldeditor?handler=DeleteChunk`
|
||||||
|
- Tile paint now respects tile definition walkability when a definition exists for selected `sheetId + frameIndex`.
|
||||||
|
|
||||||
|
## Overworld Runtime Client Support (Still Needed)
|
||||||
|
|
||||||
|
- Browser world editor APIs are in place, but in-game overworld runtime streaming is still pending.
|
||||||
|
- Client still needs final runtime contract and handlers for:
|
||||||
|
- loading world region/zone/chunk state at player spawn
|
||||||
|
- receiving nearby chunk deltas from server during movement
|
||||||
|
- enforcing `isWalkable` and VIP paywall collision in live world movement
|
||||||
|
|
||||||
## Dungeon Portals and Ledge-Safe Movement
|
## Dungeon Portals and Ledge-Safe Movement
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user