refactor: TileRegistry replaces parallel tile/view collections
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Core.Domain;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Infrastructure.Unity
|
||||
@@ -10,44 +9,13 @@ namespace Infrastructure.Unity
|
||||
[SerializeField] private float fadeSpeed = 5f;
|
||||
[SerializeField] private float hiddenAlpha = 0.1f;
|
||||
[SerializeField] private float visibleAlpha = 1.0f;
|
||||
|
||||
private GameSession _gameSession;
|
||||
|
||||
private List<List<TileViewAdapter>> _floors;
|
||||
private int _currentFloorIndex = -1;
|
||||
|
||||
public void Initialize(GameSession gameSession, List<Tile> allTiles, Dictionary<string, TileViewAdapter> tileViews, int totalFloors)
|
||||
|
||||
public void Initialize(TileRegistry registry, int totalFloors)
|
||||
{
|
||||
_gameSession = gameSession;
|
||||
|
||||
_floors = new List<List<TileViewAdapter>>();
|
||||
for (var i = 0; i < totalFloors; i++)
|
||||
{
|
||||
_floors.Add(new List<TileViewAdapter>());
|
||||
}
|
||||
|
||||
foreach (var tile in allTiles)
|
||||
{
|
||||
if (tileViews.TryGetValue(tile.Id, out var view))
|
||||
{
|
||||
// Safety check for array bounds
|
||||
if (tile.Floor < _floors.Count)
|
||||
{
|
||||
_floors[tile.Floor].Add(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_gameSession == null) return;
|
||||
|
||||
// Check if player changed floors
|
||||
// We read the private field _playerFloorIndex via a public getter we need to add,
|
||||
// OR we just track it locally if you updated GameSession to expose it.
|
||||
// Assuming GameSession doesn't expose it publically yet, let's rely on GameBootstrap passing it or just hack it:
|
||||
// Ideally, GameSession should emit an event 'OnFloorChanged'.
|
||||
// For now, let's assume we can get it or we passed the player reference.
|
||||
_floors = registry.GroupViewsByFloor(totalFloors);
|
||||
}
|
||||
|
||||
// Call this from GameBootstrap.Update()
|
||||
@@ -75,9 +43,9 @@ namespace Infrastructure.Unity
|
||||
tile.SetAlpha(targetAlpha);
|
||||
}
|
||||
}
|
||||
|
||||
if (i % 2 == 0) yield return null;
|
||||
|
||||
if (i % 2 == 0) yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user