Dungeon Builder Change
This commit is contained in:
@@ -20,6 +20,7 @@ public class EditModel : AdminPageModel
|
||||
public TileMapSheet Sheet { get; set; } = new();
|
||||
|
||||
public List<TileDefinition> TileDefinitions { get; set; } = new();
|
||||
public List<TileDefinitionRow> TileDefinitionRows { get; set; } = new();
|
||||
public List<ClientAsset> CdnImages { get; set; } = new();
|
||||
public string CdnBaseUrl { get; set; } = "";
|
||||
|
||||
@@ -54,6 +55,7 @@ public class EditModel : AdminPageModel
|
||||
{
|
||||
Sheet = sheet;
|
||||
TileDefinitions = sheet.Tiles?.OrderBy(t => t.FrameIndex).ToList() ?? new();
|
||||
await LoadTileDefinitionRows();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -109,6 +111,8 @@ public class EditModel : AdminPageModel
|
||||
.Where(t => t.TileMapSheetId == Sheet.Id)
|
||||
.OrderBy(t => t.FrameIndex)
|
||||
.ToListAsync();
|
||||
|
||||
await LoadTileDefinitionRows();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -296,4 +300,44 @@ public class EditModel : AdminPageModel
|
||||
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
private async Task LoadTileDefinitionRows()
|
||||
{
|
||||
if (Sheet.Id == 0)
|
||||
{
|
||||
TileDefinitionRows = new();
|
||||
return;
|
||||
}
|
||||
|
||||
var tileDefs = await _db.TileDefinitions
|
||||
.Where(t => t.TileMapSheetId == Sheet.Id)
|
||||
.OrderBy(t => t.FrameIndex)
|
||||
.ToListAsync();
|
||||
|
||||
var tileIds = tileDefs.Select(t => t.Id).ToList();
|
||||
|
||||
var bucketCounts = await _db.TileDefinitionBuckets
|
||||
.Where(b => tileIds.Contains(b.TileDefinitionId))
|
||||
.GroupBy(b => b.TileDefinitionId)
|
||||
.Select(g => new { TileDefinitionId = g.Key, Count = g.Count() })
|
||||
.ToDictionaryAsync(g => g.TileDefinitionId, g => g.Count);
|
||||
|
||||
TileDefinitionRows = tileDefs.Select(t => new TileDefinitionRow
|
||||
{
|
||||
Id = t.Id,
|
||||
FrameIndex = t.FrameIndex,
|
||||
Name = t.Name,
|
||||
Type = t.Type.ToString(),
|
||||
BucketCount = bucketCounts.TryGetValue(t.Id, out var count) ? count : 0
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public class TileDefinitionRow
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int FrameIndex { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string Type { get; set; } = "";
|
||||
public int BucketCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user