Phase 4.1: Extract GridData base class from UIGrid (#252, #270, #271, #277)

Extract all grid data members and methods into GridData base class.
UIGrid now inherits from both UIDrawable (rendering) and GridData (state).

- GridData holds: grid dimensions, cell storage (flat/chunked), entities,
  spatial hash, TCOD map, FOV state, Dijkstra caches, layers, cell
  callbacks, children collection
- GridData provides: at(), syncTCODMap/Cell(), computeFOV(), isInFOV(),
  layer management (add/remove/sort/getByName), initStorage()
- UIGrid retains: texture, box, sprites, renderTexture, camera (center,
  zoom, rotation), fill_color, perspective, cell hover/click dispatch,
  all Python API static methods, render()

Fix dangling parent_grid pointers: change UIGrid* to GridData* in
GridLayer, UIGridPoint, GridChunk, ChunkManager (closes #270, closes
#271, closes #277). All 258 tests pass unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-03-16 07:45:12 -04:00
commit 13d5512a41
9 changed files with 379 additions and 340 deletions

View file

@ -150,7 +150,7 @@ static sf::Color LerpColor(const sf::Color& a, const sf::Color& b, float t) {
// GridLayer base class
// =============================================================================
GridLayer::GridLayer(GridLayerType type, int z_index, int grid_x, int grid_y, UIGrid* parent)
GridLayer::GridLayer(GridLayerType type, int z_index, int grid_x, int grid_y, GridData* parent)
: type(type), z_index(z_index), grid_x(grid_x), grid_y(grid_y),
parent_grid(parent), visible(true),
chunks_x(0), chunks_y(0),
@ -244,7 +244,7 @@ void GridLayer::ensureChunkTexture(int chunk_idx, int cell_width, int cell_heigh
// ColorLayer implementation
// =============================================================================
ColorLayer::ColorLayer(int z_index, int grid_x, int grid_y, UIGrid* parent)
ColorLayer::ColorLayer(int z_index, int grid_x, int grid_y, GridData* parent)
: GridLayer(GridLayerType::Color, z_index, grid_x, grid_y, parent),
colors(grid_x * grid_y, sf::Color::Transparent),
perspective_visible(255, 255, 200, 64),
@ -515,7 +515,7 @@ void ColorLayer::render(sf::RenderTarget& target,
// TileLayer implementation
// =============================================================================
TileLayer::TileLayer(int z_index, int grid_x, int grid_y, UIGrid* parent,
TileLayer::TileLayer(int z_index, int grid_x, int grid_y, GridData* parent,
std::shared_ptr<PyTexture> texture)
: GridLayer(GridLayerType::Tile, z_index, grid_x, grid_y, parent),
tiles(grid_x * grid_y, -1), // -1 = no tile