From 232105a89335ee775b73ae076e761eeb7c6f70a4 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Sat, 20 Apr 2024 18:33:18 -0400 Subject: [PATCH] Squashed commit of the following: [reprs_and_member_names] Closes #22 Closes #23 Closes #24 Closes #25 Closes #31 Closes #56 commit 43fac8f4f37bb3d6aaeaa9e4f870e673b1133fb1 Author: John McCardle Date: Sat Apr 20 18:32:52 2024 -0400 Typo in UIFrame repr commit 3fd5ad93e2412706f38c491849172e78ed8c5f48 Author: John McCardle Date: Sat Apr 20 18:32:30 2024 -0400 Add UIGridPoint and UIGridPointState repr commit 03376897b850c0b89bd12650d205905df71c443d Author: John McCardle Date: Sat Apr 20 18:32:17 2024 -0400 Add UIGrid repr commit 48af072a33cc97877d38441bae6314068ae14dde Author: John McCardle Date: Sat Apr 20 18:32:05 2024 -0400 Add UIEntity repr --- src/UIEntity.cpp | 12 ++++++++++++ src/UIEntity.h | 3 ++- src/UIFrame.cpp | 2 +- src/UIGrid.cpp | 31 +++++++++++++++++++++++++++++++ src/UIGrid.h | 3 ++- src/UIGridPoint.cpp | 24 ++++++++++++++++++++++++ src/UIGridPoint.h | 6 ++++-- 7 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/UIEntity.cpp b/src/UIEntity.cpp index 57aeeae..01ebd83 100644 --- a/src/UIEntity.cpp +++ b/src/UIEntity.cpp @@ -163,3 +163,15 @@ PyGetSetDef UIEntity::getsetters[] = { {"sprite_number", (getter)UIEntity::get_spritenumber, (setter)UIEntity::set_spritenumber, "Sprite number (index) on the texture on the display", NULL}, {NULL} /* Sentinel */ }; + +PyObject* UIEntity::repr(PyUIEntityObject* self) { + std::ostringstream ss; + if (!self->data) ss << ""; + else { + auto ent = self->data; + ss << ""; + } + std::string repr_str = ss.str(); + return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace"); +} diff --git a/src/UIEntity.h b/src/UIEntity.h index 852cbb3..b5050ff 100644 --- a/src/UIEntity.h +++ b/src/UIEntity.h @@ -55,6 +55,7 @@ public: static int set_spritenumber(PyUIEntityObject* self, PyObject* value, void* closure); static PyMethodDef methods[]; static PyGetSetDef getsetters[]; + static PyObject* repr(PyUIEntityObject* self); }; namespace mcrfpydef { @@ -63,7 +64,7 @@ namespace mcrfpydef { .tp_name = "mcrfpy.Entity", .tp_basicsize = sizeof(PyUIEntityObject), .tp_itemsize = 0, - // Methods omitted for brevity + .tp_repr = (reprfunc)UIEntity::repr, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "UIEntity objects", .tp_methods = UIEntity::methods, diff --git a/src/UIFrame.cpp b/src/UIFrame.cpp index 8c9561c..42adc47 100644 --- a/src/UIFrame.cpp +++ b/src/UIFrame.cpp @@ -225,7 +225,7 @@ PyObject* UIFrame::repr(PyUIFrameObject* self) auto box = self->data->box; auto fc = box.getFillColor(); auto oc = box.getOutlineColor(); - ss << "data->box.setPosition(val, self->data->box.getPosition().y); +// else if (member_ptr == 1) // y +// self->data->box.setPosition(self->data->box.getPosition().x, val); +// else if (member_ptr == 2) // w +// self->data->box.setSize(sf::Vector2f(val, self->data->box.getSize().y)); +// else if (member_ptr == 3) // h +// self->data->box.setSize(sf::Vector2f(self->data->box.getSize().x, val)); +// else if (member_ptr == 4) // center_x +// self->data->center_x = val; +// else if (member_ptr == 5) // center_y +// self->data->center_y = val; +// else if (member_ptr == 6) // zoom +// self->data->zoom = val; + + std::ostringstream ss; + if (!self->data) ss << ""; + else { + auto grid = self->data; + auto box = grid->box; + ss << "center_x << ", " << grid->center_y << "), zoom=" << grid->zoom << + ")>"; + } + std::string repr_str = ss.str(); + return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace"); +} + /* // TODO standard pointer would need deleted, but I opted for a shared pointer. tp_dealloc currently not even defined in the PyTypeObject void PyUIGrid_dealloc(PyUIGridObject* self) { delete self->data; // Clean up the allocated UIGrid object diff --git a/src/UIGrid.h b/src/UIGrid.h index 8804705..bb09152 100644 --- a/src/UIGrid.h +++ b/src/UIGrid.h @@ -58,6 +58,7 @@ public: static PyMethodDef methods[]; static PyGetSetDef getsetters[]; static PyObject* get_children(PyUIGridObject* self, void* closure); + static PyObject* repr(PyUIGridObject* self); }; @@ -109,7 +110,7 @@ namespace mcrfpydef { // Py_TYPE(self)->tp_free(self); //}, //TODO - PyUIGrid REPR def: - // .tp_repr = (reprfunc)UIGrid::repr, + .tp_repr = (reprfunc)UIGrid::repr, //.tp_hash = NULL, //.tp_iter //.tp_iternext diff --git a/src/UIGridPoint.cpp b/src/UIGridPoint.cpp index b30d493..e255c3a 100644 --- a/src/UIGridPoint.cpp +++ b/src/UIGridPoint.cpp @@ -98,6 +98,19 @@ PyGetSetDef UIGridPoint::getsetters[] = { {NULL} /* Sentinel */ }; +PyObject* UIGridPoint::repr(PyUIGridPointObject* self) { + std::ostringstream ss; + if (!self->data) ss << ""; + else { + auto gp = self->data; + ss << ""; + } + std::string repr_str = ss.str(); + return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace"); +} + PyObject* UIGridPointState::get_bool_member(PyUIGridPointStateObject* self, void* closure) { if (reinterpret_cast(closure) == 0) { // visible return PyBool_FromLong(self->data->visible); @@ -132,3 +145,14 @@ PyGetSetDef UIGridPointState::getsetters[] = { {NULL} /* Sentinel */ }; +PyObject* UIGridPointState::repr(PyUIGridPointStateObject* self) { + std::ostringstream ss; + if (!self->data) ss << ""; + else { + auto gps = self->data; + ss << ""; + } + std::string repr_str = ss.str(); + return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace"); +} diff --git a/src/UIGridPoint.h b/src/UIGridPoint.h index 8161df8..627c3d6 100644 --- a/src/UIGridPoint.h +++ b/src/UIGridPoint.h @@ -49,6 +49,7 @@ public: static int set_bool_member(PyUIGridPointObject* self, PyObject* value, void* closure); static PyObject* get_bool_member(PyUIGridPointObject* self, void* closure); static int set_color(PyUIGridPointObject* self, PyObject* value, void* closure); + static PyObject* repr(PyUIGridPointObject* self); }; // UIGridPointState - entity-specific info for each cell @@ -60,6 +61,7 @@ public: static PyObject* get_bool_member(PyUIGridPointStateObject* self, void* closure); static int set_bool_member(PyUIGridPointStateObject* self, PyObject* value, void* closure); static PyGetSetDef getsetters[]; + static PyObject* repr(PyUIGridPointStateObject* self); }; namespace mcrfpydef { @@ -68,7 +70,7 @@ namespace mcrfpydef { .tp_name = "mcrfpy.GridPoint", .tp_basicsize = sizeof(PyUIGridPointObject), .tp_itemsize = 0, - // Methods omitted for brevity + .tp_repr = (reprfunc)UIGridPoint::repr, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "UIGridPoint object", .tp_getset = UIGridPoint::getsetters, @@ -81,7 +83,7 @@ namespace mcrfpydef { .tp_name = "mcrfpy.GridPointState", .tp_basicsize = sizeof(PyUIGridPointStateObject), .tp_itemsize = 0, - // Methods omitted for brevity + .tp_repr = (reprfunc)UIGridPointState::repr, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "UIGridPointState object", // TODO: Add PyUIGridPointState tp_init .tp_getset = UIGridPointState::getsetters,