Compare commits
4 Commits
c2de9b08d6
...
43fac8f4f3
Author | SHA1 | Date |
---|---|---|
John McCardle | 43fac8f4f3 | |
John McCardle | 3fd5ad93e2 | |
John McCardle | 03376897b8 | |
John McCardle | 48af072a33 |
|
@ -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},
|
{"sprite_number", (getter)UIEntity::get_spritenumber, (setter)UIEntity::set_spritenumber, "Sprite number (index) on the texture on the display", NULL},
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyObject* UIEntity::repr(PyUIEntityObject* self) {
|
||||||
|
std::ostringstream ss;
|
||||||
|
if (!self->data) ss << "<Entity (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto ent = self->data;
|
||||||
|
ss << "<Entity (x=" << self->data->position.x << ", y=" << self->data->position.y << ", sprite_number=" << self->data->sprite.getSpriteIndex() <<
|
||||||
|
")>";
|
||||||
|
}
|
||||||
|
std::string repr_str = ss.str();
|
||||||
|
return PyUnicode_DecodeUTF8(repr_str.c_str(), repr_str.size(), "replace");
|
||||||
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
static int set_spritenumber(PyUIEntityObject* self, PyObject* value, void* closure);
|
static int set_spritenumber(PyUIEntityObject* self, PyObject* value, void* closure);
|
||||||
static PyMethodDef methods[];
|
static PyMethodDef methods[];
|
||||||
static PyGetSetDef getsetters[];
|
static PyGetSetDef getsetters[];
|
||||||
|
static PyObject* repr(PyUIEntityObject* self);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace mcrfpydef {
|
namespace mcrfpydef {
|
||||||
|
@ -63,7 +64,7 @@ namespace mcrfpydef {
|
||||||
.tp_name = "mcrfpy.Entity",
|
.tp_name = "mcrfpy.Entity",
|
||||||
.tp_basicsize = sizeof(PyUIEntityObject),
|
.tp_basicsize = sizeof(PyUIEntityObject),
|
||||||
.tp_itemsize = 0,
|
.tp_itemsize = 0,
|
||||||
// Methods omitted for brevity
|
.tp_repr = (reprfunc)UIEntity::repr,
|
||||||
.tp_flags = Py_TPFLAGS_DEFAULT,
|
.tp_flags = Py_TPFLAGS_DEFAULT,
|
||||||
.tp_doc = "UIEntity objects",
|
.tp_doc = "UIEntity objects",
|
||||||
.tp_methods = UIEntity::methods,
|
.tp_methods = UIEntity::methods,
|
||||||
|
|
|
@ -225,7 +225,7 @@ PyObject* UIFrame::repr(PyUIFrameObject* self)
|
||||||
auto box = self->data->box;
|
auto box = self->data->box;
|
||||||
auto fc = box.getFillColor();
|
auto fc = box.getFillColor();
|
||||||
auto oc = box.getOutlineColor();
|
auto oc = box.getOutlineColor();
|
||||||
ss << "<Frame (x=" << box.getPosition().x << ", y=" << box.getPosition().y << ", x=" <<
|
ss << "<Frame (x=" << box.getPosition().x << ", y=" << box.getPosition().y << ", w=" <<
|
||||||
box.getSize().x << ", w=" << box.getSize().y << ", " <<
|
box.getSize().x << ", w=" << box.getSize().y << ", " <<
|
||||||
"outline=" << box.getOutlineThickness() << ", " <<
|
"outline=" << box.getOutlineThickness() << ", " <<
|
||||||
"fill_color=(" << (int)fc.r << ", " << (int)fc.g << ", " << (int)fc.b << ", " << (int)fc.a <<"), " <<
|
"fill_color=(" << (int)fc.r << ", " << (int)fc.g << ", " << (int)fc.b << ", " << (int)fc.a <<"), " <<
|
||||||
|
|
|
@ -421,6 +421,37 @@ PyObject* UIGrid::get_children(PyUIGridObject* self, void* closure)
|
||||||
return (PyObject*)o;
|
return (PyObject*)o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* UIGrid::repr(PyUIGridObject* self)
|
||||||
|
{
|
||||||
|
|
||||||
|
// if (member_ptr == 0) // x
|
||||||
|
// self->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 << "<Grid (invalid internal object)>";
|
||||||
|
else {
|
||||||
|
auto grid = self->data;
|
||||||
|
auto box = grid->box;
|
||||||
|
ss << "<Grid (x=" << box.getPosition().x << ", y=" << box.getPosition().y << ", w=" << box.getSize().x << ", h=" << box.getSize().y << ", " <<
|
||||||
|
"center=(" << grid->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
|
/* // 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) {
|
void PyUIGrid_dealloc(PyUIGridObject* self) {
|
||||||
delete self->data; // Clean up the allocated UIGrid object
|
delete self->data; // Clean up the allocated UIGrid object
|
||||||
|
|
|
@ -58,6 +58,7 @@ public:
|
||||||
static PyMethodDef methods[];
|
static PyMethodDef methods[];
|
||||||
static PyGetSetDef getsetters[];
|
static PyGetSetDef getsetters[];
|
||||||
static PyObject* get_children(PyUIGridObject* self, void* closure);
|
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);
|
// Py_TYPE(self)->tp_free(self);
|
||||||
//},
|
//},
|
||||||
//TODO - PyUIGrid REPR def:
|
//TODO - PyUIGrid REPR def:
|
||||||
// .tp_repr = (reprfunc)UIGrid::repr,
|
.tp_repr = (reprfunc)UIGrid::repr,
|
||||||
//.tp_hash = NULL,
|
//.tp_hash = NULL,
|
||||||
//.tp_iter
|
//.tp_iter
|
||||||
//.tp_iternext
|
//.tp_iternext
|
||||||
|
|
|
@ -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