feat: Add GridPoint.entities and GridPointState.point properties
GridPoint.entities (#114): - Returns list of entities at this grid cell position - Enables convenient cell-based entity queries without manual iteration - Example: grid.at(5, 5).entities → [<Entity>, <Entity>] GridPointState.point (#16): - Returns GridPoint if entity has discovered this cell, None otherwise - Respects entity's perspective: undiscovered cells return None - Enables entity.at(x,y).point.walkable style access - Live reference: changes to GridPoint are immediately visible This provides a simpler solution for #16 without the complexity of caching stale GridPoint copies. The visible/discovered flags indicate whether the entity "should" trust the data; Python can implement memory systems if needed. closes #114, closes #16 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a529e5eac3
commit
f33e79a123
5 changed files with 367 additions and 6 deletions
|
|
@ -120,9 +120,12 @@ PyObject* UIEntity::at(PyUIEntityObject* self, PyObject* o) {
|
|||
|
||||
auto type = (PyTypeObject*)PyObject_GetAttrString(McRFPy_API::mcrf_module, "GridPointState");
|
||||
auto obj = (PyUIGridPointStateObject*)type->tp_alloc(type, 0);
|
||||
Py_DECREF(type);
|
||||
obj->data = &(self->data->gridstate[y * self->data->grid->grid_x + x]);
|
||||
obj->grid = self->data->grid;
|
||||
obj->entity = self->data;
|
||||
obj->x = x; // #16 - Store position for .point property
|
||||
obj->y = y;
|
||||
return (PyObject*)obj;
|
||||
}
|
||||
|
||||
|
|
@ -312,23 +315,29 @@ sf::Vector2i PyObject_to_sfVector2i(PyObject* obj) {
|
|||
}
|
||||
|
||||
PyObject* UIGridPointState_to_PyObject(const UIGridPointState& state) {
|
||||
// Create a new GridPointState Python object
|
||||
// Create a new GridPointState Python object (detached - no grid/entity context)
|
||||
auto type = (PyTypeObject*)PyObject_GetAttrString(McRFPy_API::mcrf_module, "GridPointState");
|
||||
if (!type) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
auto obj = (PyUIGridPointStateObject*)type->tp_alloc(type, 0);
|
||||
if (!obj) {
|
||||
Py_DECREF(type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// Allocate new data and copy values
|
||||
obj->data = new UIGridPointState();
|
||||
obj->data->visible = state.visible;
|
||||
obj->data->discovered = state.discovered;
|
||||
|
||||
|
||||
// Initialize context fields (detached state has no grid/entity context)
|
||||
obj->grid = nullptr;
|
||||
obj->entity = nullptr;
|
||||
obj->x = -1;
|
||||
obj->y = -1;
|
||||
|
||||
Py_DECREF(type);
|
||||
return (PyObject*)obj;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue