Add UIGridPoint and UIGridPointState repr
This commit is contained in:
parent
03376897b8
commit
3fd5ad93e2
|
@ -98,6 +98,19 @@ PyGetSetDef UIGridPoint::getsetters[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyObject* UIGridPoint::repr(PyUIGridPointObject* self) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
if (!self->data) ss << "<GridPoint (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto gp = self->data;
|
||||||
|
ss << "<GridPoint (walkable=" << (gp->walkable ? "True" : "False") << ", transparent=" << (gp->transparent ? "True" : "False") <<
|
||||||
|
", tilesprite=" << gp->tilesprite << ", tile_overlay=" << gp->tile_overlay << ", uisprite=" << gp->uisprite <<
|
||||||
|
")>";
|
||||||
|
}
|
||||||
|
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) {
|
PyObject* UIGridPointState::get_bool_member(PyUIGridPointStateObject* self, void* closure) {
|
||||||
if (reinterpret_cast<long>(closure) == 0) { // visible
|
if (reinterpret_cast<long>(closure) == 0) { // visible
|
||||||
return PyBool_FromLong(self->data->visible);
|
return PyBool_FromLong(self->data->visible);
|
||||||
|
@ -132,3 +145,14 @@ PyGetSetDef UIGridPointState::getsetters[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyObject* UIGridPointState::repr(PyUIGridPointStateObject* self) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
if (!self->data) ss << "<GridPointState (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto gps = self->data;
|
||||||
|
ss << "<GridPointState (visible=" << (gps->visible ? "True" : "False") << ", discovered=" << (gps->discovered ? "True" : "False") <<
|
||||||
|
")>";
|
||||||
|
}
|
||||||
|
std::string repr_str = ss.str();
|
||||||
|
return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace");
|
||||||
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
static int set_bool_member(PyUIGridPointObject* self, PyObject* value, void* closure);
|
static int set_bool_member(PyUIGridPointObject* self, PyObject* value, void* closure);
|
||||||
static PyObject* get_bool_member(PyUIGridPointObject* self, void* closure);
|
static PyObject* get_bool_member(PyUIGridPointObject* self, void* closure);
|
||||||
static int set_color(PyUIGridPointObject* self, PyObject* value, void* closure);
|
static int set_color(PyUIGridPointObject* self, PyObject* value, void* closure);
|
||||||
|
static PyObject* repr(PyUIGridPointObject* self);
|
||||||
};
|
};
|
||||||
|
|
||||||
// UIGridPointState - entity-specific info for each cell
|
// UIGridPointState - entity-specific info for each cell
|
||||||
|
@ -60,6 +61,7 @@ public:
|
||||||
static PyObject* get_bool_member(PyUIGridPointStateObject* self, void* closure);
|
static PyObject* get_bool_member(PyUIGridPointStateObject* self, void* closure);
|
||||||
static int set_bool_member(PyUIGridPointStateObject* self, PyObject* value, void* closure);
|
static int set_bool_member(PyUIGridPointStateObject* self, PyObject* value, void* closure);
|
||||||
static PyGetSetDef getsetters[];
|
static PyGetSetDef getsetters[];
|
||||||
|
static PyObject* repr(PyUIGridPointStateObject* self);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
|
@ -68,7 +70,7 @@ namespace mcrfpydef {
|
||||||
.tp_name = "mcrfpy.GridPoint",
|
.tp_name = "mcrfpy.GridPoint",
|
||||||
.tp_basicsize = sizeof(PyUIGridPointObject),
|
.tp_basicsize = sizeof(PyUIGridPointObject),
|
||||||
.tp_itemsize = 0,
|
.tp_itemsize = 0,
|
||||||
// Methods omitted for brevity
|
.tp_repr = (reprfunc)UIGridPoint::repr,
|
||||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||||
.tp_doc = "UIGridPoint object",
|
.tp_doc = "UIGridPoint object",
|
||||||
.tp_getset = UIGridPoint::getsetters,
|
.tp_getset = UIGridPoint::getsetters,
|
||||||
|
@ -81,7 +83,7 @@ namespace mcrfpydef {
|
||||||
.tp_name = "mcrfpy.GridPointState",
|
.tp_name = "mcrfpy.GridPointState",
|
||||||
.tp_basicsize = sizeof(PyUIGridPointStateObject),
|
.tp_basicsize = sizeof(PyUIGridPointStateObject),
|
||||||
.tp_itemsize = 0,
|
.tp_itemsize = 0,
|
||||||
// Methods omitted for brevity
|
.tp_repr = (reprfunc)UIGridPointState::repr,
|
||||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||||
.tp_doc = "UIGridPointState object", // TODO: Add PyUIGridPointState tp_init
|
.tp_doc = "UIGridPointState object", // TODO: Add PyUIGridPointState tp_init
|
||||||
.tp_getset = UIGridPointState::getsetters,
|
.tp_getset = UIGridPointState::getsetters,
|
||||||
|
|
Loading…
Reference in New Issue