feat: Add dynamic layer system for Grid (closes #147)

Implements ColorLayer and TileLayer classes with z_index ordering:
- ColorLayer: stores RGBA color per cell for overlays, fog of war, etc.
- TileLayer: stores sprite index per cell with optional texture
- z_index < 0: renders below entities
- z_index >= 0: renders above entities

Python API:
- grid.add_layer(type, z_index, texture) - create layer
- grid.remove_layer(layer) - remove layer
- grid.layers - list of layers sorted by z_index
- grid.layer(z_index) - get layer by z_index
- layer.at(x,y) / layer.set(x,y,value) - cell access
- layer.fill(value) - fill entire layer

Layers are allocated separately from UIGridPoint, reducing memory
for grids that don't need all features. Base grid retains walkable/
transparent arrays for TCOD pathfinding.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
John McCardle 2025-11-28 21:35:38 -05:00
commit 4b05a95efe
6 changed files with 1342 additions and 19 deletions

View file

@ -20,6 +20,7 @@
#include "UIEntity.h"
#include "UIDrawable.h"
#include "UIBase.h"
#include "GridLayers.h"
class UIGrid: public UIDrawable
{
@ -81,6 +82,16 @@ public:
std::shared_ptr<std::vector<std::shared_ptr<UIDrawable>>> children;
bool children_need_sort = true; // Dirty flag for z_index sorting
// Dynamic layer system (#147)
std::vector<std::shared_ptr<GridLayer>> layers;
bool layers_need_sort = true; // Dirty flag for z_index sorting
// Layer management
std::shared_ptr<ColorLayer> addColorLayer(int z_index);
std::shared_ptr<TileLayer> addTileLayer(int z_index, std::shared_ptr<PyTexture> texture = nullptr);
void removeLayer(std::shared_ptr<GridLayer> layer);
void sortLayers();
// Background rendering
sf::Color fill_color;
@ -147,7 +158,12 @@ public:
static PyObject* get_on_cell_click(PyUIGridObject* self, void* closure);
static int set_on_cell_click(PyUIGridObject* self, PyObject* value, void* closure);
static PyObject* get_hovered_cell(PyUIGridObject* self, void* closure);
// #147 - Layer system Python API
static PyObject* py_add_layer(PyUIGridObject* self, PyObject* args, PyObject* kwds);
static PyObject* py_remove_layer(PyUIGridObject* self, PyObject* args);
static PyObject* get_layers(PyUIGridObject* self, void* closure);
static PyObject* py_layer(PyUIGridObject* self, PyObject* args);
};
typedef struct {