fix: TileRegistry floor-range warning, GroupViewsByFloor tests, stopwatch cleanup
This commit is contained in:
@@ -42,8 +42,8 @@ namespace Infrastructure.Unity
|
|||||||
yield return GenerateFloorAsync(0, MapPatterns.GenerateSquare(gridSizeX, gridSizeY), soundManager, registry, camera, rumble, stopwatch);
|
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(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);
|
yield return GenerateFloorAsync(2, MapPatterns.GenerateCircle(gridSizeX), soundManager, registry, camera, rumble, stopwatch);
|
||||||
|
|
||||||
stopwatch?.Stop();
|
stopwatch.Stop();
|
||||||
onComplete?.Invoke();
|
onComplete?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Core.Domain;
|
using Core.Domain;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Infrastructure.Unity
|
namespace Infrastructure.Unity
|
||||||
{
|
{
|
||||||
@@ -30,7 +31,12 @@ namespace Infrastructure.Unity
|
|||||||
|
|
||||||
foreach (var tile in _tiles)
|
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);
|
floors[tile.Floor].Add(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,31 @@ namespace DecayGrid.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TryGetView_ReturnsFalse_WhenNoViewRegistered()
|
public void TryGetView_ReturnsFalse_WhenTileHasNoView()
|
||||||
{
|
{
|
||||||
var tile = new Tile("0_0_0", 0, 0.5f, 2f);
|
var tile = new Tile("0_0_0", 0, 0.5f, 2f);
|
||||||
_registry.Register(tile); // no view
|
_registry.Register(tile); // no view
|
||||||
Assert.IsFalse(_registry.TryGetView("0_0_0", out _));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user