From 67df6bf6d65260736c2fe166fa36a4b6741097fc Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 14 May 2026 01:15:48 +0200 Subject: [PATCH] fix: TileRegistry floor-range warning, GroupViewsByFloor tests, stopwatch cleanup --- .../Infrastructure/Unity/LevelGenerator.cs | 4 ++-- .../Infrastructure/Unity/TileRegistry.cs | 8 ++++++- Assets/Tests/EditMode/TileRegistryTests.cs | 22 ++++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Infrastructure/Unity/LevelGenerator.cs b/Assets/Scripts/Infrastructure/Unity/LevelGenerator.cs index a5b76b5..6c2ebcc 100644 --- a/Assets/Scripts/Infrastructure/Unity/LevelGenerator.cs +++ b/Assets/Scripts/Infrastructure/Unity/LevelGenerator.cs @@ -42,8 +42,8 @@ namespace Infrastructure.Unity yield return GenerateFloorAsync(0, MapPatterns.GenerateSquare(gridSizeX, gridSizeY), soundManager, registry, camera, rumble, stopwatch); yield return GenerateFloorAsync(1, MapPatterns.GenerateDonut(gridSizeX, Mathf.FloorToInt(gridSizeX / 3f)), soundManager, registry, camera, rumble, stopwatch); yield return GenerateFloorAsync(2, MapPatterns.GenerateCircle(gridSizeX), soundManager, registry, camera, rumble, stopwatch); - - stopwatch?.Stop(); + + stopwatch.Stop(); onComplete?.Invoke(); } diff --git a/Assets/Scripts/Infrastructure/Unity/TileRegistry.cs b/Assets/Scripts/Infrastructure/Unity/TileRegistry.cs index 2364730..b509067 100644 --- a/Assets/Scripts/Infrastructure/Unity/TileRegistry.cs +++ b/Assets/Scripts/Infrastructure/Unity/TileRegistry.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Core.Domain; +using UnityEngine; namespace Infrastructure.Unity { @@ -30,7 +31,12 @@ namespace Infrastructure.Unity foreach (var tile in _tiles) { - if (tile.Floor < floorCount && _views.TryGetValue(tile.Id, out var view)) + if (tile.Floor >= floorCount) + { + Debug.LogWarning($"TileRegistry: tile '{tile.Id}' floor {tile.Floor} >= floorCount {floorCount}, skipping"); + continue; + } + if (_views.TryGetValue(tile.Id, out var view)) floors[tile.Floor].Add(view); } diff --git a/Assets/Tests/EditMode/TileRegistryTests.cs b/Assets/Tests/EditMode/TileRegistryTests.cs index 3ca79ab..a3407d4 100644 --- a/Assets/Tests/EditMode/TileRegistryTests.cs +++ b/Assets/Tests/EditMode/TileRegistryTests.cs @@ -39,11 +39,31 @@ namespace DecayGrid.Tests } [Test] - public void TryGetView_ReturnsFalse_WhenNoViewRegistered() + public void TryGetView_ReturnsFalse_WhenTileHasNoView() { var tile = new Tile("0_0_0", 0, 0.5f, 2f); _registry.Register(tile); // no view Assert.IsFalse(_registry.TryGetView("0_0_0", out _)); } + + [Test] + public void GroupViewsByFloor_PlacesTileOnCorrectFloor() + { + // Can't create TileViewAdapter in EditMode (MonoBehaviour), so just verify tile with no view doesn't crash + var tile = new Tile("1_5_5", 1, 0.5f, 2f); + _registry.Register(tile); // no view + var floors = _registry.GroupViewsByFloor(3); + Assert.AreEqual(3, floors.Count); + // Tile has no view registered, so no view should appear in any floor + Assert.AreEqual(0, floors[1].Count); + } + + [Test] + public void GroupViewsByFloor_OutOfRangeTile_DoesNotThrow() + { + var tile = new Tile("5_0_0", 5, 0.5f, 2f); // floor 5, but only 3 floors + _registry.Register(tile); + Assert.DoesNotThrow(() => _registry.GroupViewsByFloor(3)); + } } }