Add world editor region creation and document overworld client/runtime gaps
This commit is contained in:
@@ -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)
|
||||
{
|
||||
var region = await _db.WorldRegions.FirstOrDefaultAsync(r => r.Id == regionId && r.IsEnabled);
|
||||
|
||||
Reference in New Issue
Block a user