diff --git a/Game/Dungeon/DungeonGeneratorV2.cs b/Game/Dungeon/DungeonGeneratorV2.cs index 36ca672..31dafc6 100644 --- a/Game/Dungeon/DungeonGeneratorV2.cs +++ b/Game/Dungeon/DungeonGeneratorV2.cs @@ -139,6 +139,8 @@ public class DungeonGeneratorV2 // Build tile data for client layout.BuildClientTileData(_tileDefinitions, _defaultSheet); + Console.WriteLine($"[DungeonGenV2] Generation complete: {rooms.Count} rooms, {layout.TileDetails.Count} visual tiles, {layout.TileMapSheets.Count} sheets"); + return layout; } @@ -156,7 +158,9 @@ public class DungeonGeneratorV2 _normalTemplates = templates.Where(t => t.Type == RoomType.Normal).ToList(); _hallwayTemplates = templates.Where(t => t.Type == RoomType.Hallway).ToList(); - // Load tile definitions + Console.WriteLine($"[DungeonGenV2] Loaded templates for tier {_tier}: Entrance={_entranceTemplates.Count}, Exit={_exitTemplates.Count}, Boss={_bossTemplates.Count}, Treasure={_treasureTemplates.Count}, Normal={_normalTemplates.Count}"); + + // Load tile definitions from templates var tileIds = templates .Where(t => !string.IsNullOrEmpty(t.TileDataJson)) .SelectMany(t => { @@ -177,9 +181,10 @@ public class DungeonGeneratorV2 _tileDefinitions = tiles.ToDictionary(t => t.Id); _defaultSheet = tiles.FirstOrDefault()?.TileMapSheet; + Console.WriteLine($"[DungeonGenV2] Loaded {tiles.Count} tile definitions from templates"); } - // If no templates, load a default sheet for basic generation + // Always load a default sheet for fallback generation if (_defaultSheet == null) { _defaultSheet = await _db.TileMapSheets @@ -190,10 +195,18 @@ public class DungeonGeneratorV2 { foreach (var tile in _defaultSheet.Tiles) { + tile.TileMapSheet = _defaultSheet; // Ensure navigation property is set _tileDefinitions[tile.Id] = tile; } + Console.WriteLine($"[DungeonGenV2] Loaded {_defaultSheet.Tiles.Count} tiles from default sheet '{_defaultSheet.Name}'"); + } + else + { + Console.WriteLine($"[DungeonGenV2] WARNING: No tilemap sheets found in database!"); } } + + Console.WriteLine($"[DungeonGenV2] Total tile definitions: {_tileDefinitions.Count}"); } private RoomType DetermineNextRoomType(List existing, int targetCount) diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index 21083a2..ea78a01 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -745,8 +745,12 @@ public sealed partial class DungeonHandler : IClientMessageHandler object? tileSheets = null; object? visualTiles = null; + _log.LogInformation("LayoutV2 is null: {IsNull}, TileDetails count: {Count}", + instance.LayoutV2 == null, instance.LayoutV2?.TileDetails?.Count ?? 0); + if (instance.LayoutV2 != null && instance.LayoutV2.TileDetails.Count > 0) { + // Materialize to arrays for JSON serialization tileSheets = instance.LayoutV2.TileMapSheets.Select(s => new { id = s.Id, @@ -756,7 +760,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler sheetW = s.SheetWidth, sheetH = s.SheetHeight, cols = s.Columns - }); + }).ToArray(); visualTiles = instance.LayoutV2.TileDetails.Select(t => new { @@ -769,9 +773,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler r = t.Rotation, fx = t.FlipX, fy = t.FlipY - }); + }).ToArray(); - _log.LogInformation("Sending {TileCount} visual tiles to client", instance.LayoutV2.TileDetails.Count); + _log.LogInformation("Sending {SheetCount} sheets, {TileCount} visual tiles to client", + instance.LayoutV2.TileMapSheets.Count, instance.LayoutV2.TileDetails.Count); } await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new