Add world editor chunk clear/delete, zoom, sprite tile rendering, and tile-definition-driven paint
This commit is contained in:
@@ -23,6 +23,7 @@ public class IndexModel : AdminPageModel
|
||||
|
||||
public List<WorldRegion> Regions { get; set; } = new();
|
||||
public List<TileMapSheet> TileSheets { get; set; } = new();
|
||||
public List<TileDefinition> TileDefinitions { get; set; } = new();
|
||||
public List<DungeonObjectDefinition> ObjectDefinitions { get; set; } = new();
|
||||
public List<DungeonNpcDefinition> NpcDefinitions { get; set; } = new();
|
||||
|
||||
@@ -58,6 +59,20 @@ public class IndexModel : AdminPageModel
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync();
|
||||
|
||||
var enabledSheetIds = TileSheets.Select(s => s.Id).ToList();
|
||||
TileDefinitions = await _db.TileDefinitions
|
||||
.Where(t => t.IsEnabled && enabledSheetIds.Contains(t.TileMapSheetId))
|
||||
.Select(t => new TileDefinition
|
||||
{
|
||||
Id = t.Id,
|
||||
TileMapSheetId = t.TileMapSheetId,
|
||||
FrameIndex = t.FrameIndex,
|
||||
Name = t.Name,
|
||||
Type = t.Type,
|
||||
IsWalkable = t.IsWalkable
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
ObjectDefinitions = await _db.DungeonObjects
|
||||
.Where(o => o.IsEnabled)
|
||||
.OrderBy(o => o.Name)
|
||||
@@ -325,7 +340,11 @@ public class IndexModel : AdminPageModel
|
||||
|
||||
tile.SheetId = sheetId;
|
||||
tile.FrameIndex = frameIndex;
|
||||
tile.IsWalkable = isWalkable;
|
||||
var tileDef = await _db.TileDefinitions
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.IsEnabled && t.TileMapSheetId == sheetId && t.FrameIndex == frameIndex);
|
||||
var effectiveWalkable = tileDef?.IsWalkable ?? isWalkable;
|
||||
tile.IsWalkable = effectiveWalkable;
|
||||
tile.IsInvisiblePaywall = isInvisiblePaywall;
|
||||
|
||||
var fromVersion = locate.Chunk.Version;
|
||||
@@ -340,7 +359,7 @@ public class IndexModel : AdminPageModel
|
||||
y,
|
||||
sheetId,
|
||||
frameIndex,
|
||||
isWalkable,
|
||||
isWalkable = effectiveWalkable,
|
||||
isInvisiblePaywall
|
||||
};
|
||||
PublishDelta(regionId, zoneX, zoneY, chunkX, chunkY, fromVersion, locate.Chunk.Version, op);
|
||||
@@ -355,6 +374,62 @@ public class IndexModel : AdminPageModel
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostClearChunkAsync(int regionId, int zoneX, int zoneY, int chunkX, int chunkY)
|
||||
{
|
||||
var locate = await GetOrCreateChunkAsync(regionId, zoneX, zoneY, chunkX, chunkY);
|
||||
if (!locate.Success || locate.Chunk == null)
|
||||
{
|
||||
return new JsonResult(new { success = false, error = locate.Error }) { StatusCode = 400 };
|
||||
}
|
||||
|
||||
var fromVersion = locate.Chunk.Version;
|
||||
|
||||
var tiles = _db.WorldChunkTiles.Where(t => t.WorldChunkId == locate.Chunk.Id);
|
||||
var objects = _db.WorldChunkObjects.Where(o => o.WorldChunkId == locate.Chunk.Id);
|
||||
var npcs = _db.WorldChunkNpcSpawns.Where(n => n.WorldChunkId == locate.Chunk.Id);
|
||||
|
||||
_db.WorldChunkTiles.RemoveRange(tiles);
|
||||
_db.WorldChunkObjects.RemoveRange(objects);
|
||||
_db.WorldChunkNpcSpawns.RemoveRange(npcs);
|
||||
|
||||
locate.Chunk.Version++;
|
||||
locate.Chunk.UpdatedAt = DateTime.UtcNow;
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
var op = new { type = "chunk_clear" };
|
||||
PublishDelta(regionId, zoneX, zoneY, chunkX, chunkY, fromVersion, locate.Chunk.Version, op);
|
||||
|
||||
return new JsonResult(new
|
||||
{
|
||||
success = true,
|
||||
chunkVersion = locate.Chunk.Version,
|
||||
fromVersion,
|
||||
toVersion = locate.Chunk.Version,
|
||||
op
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteChunkAsync(int regionId, int zoneX, int zoneY, int chunkX, int chunkY)
|
||||
{
|
||||
var locate = await GetOrCreateChunkAsync(regionId, zoneX, zoneY, chunkX, chunkY);
|
||||
if (!locate.Success || locate.Chunk == null)
|
||||
{
|
||||
return new JsonResult(new { success = false, error = locate.Error }) { StatusCode = 400 };
|
||||
}
|
||||
|
||||
var fromVersion = locate.Chunk.Version;
|
||||
_db.WorldChunks.Remove(locate.Chunk);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
PublishDelta(regionId, zoneX, zoneY, chunkX, chunkY, fromVersion, fromVersion + 1, new { type = "chunk_deleted" });
|
||||
|
||||
return new JsonResult(new
|
||||
{
|
||||
success = true,
|
||||
op = new { type = "chunk_deleted" }
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostRemoveTileAsync(int regionId, int zoneX, int zoneY, int chunkX, int chunkY, int x, int y)
|
||||
{
|
||||
var locate = await GetOrCreateChunkAsync(regionId, zoneX, zoneY, chunkX, chunkY);
|
||||
|
||||
Reference in New Issue
Block a user