Navigation Menu

Skip to content

Commit

Permalink
Python plugin: Added some missing API to the Cell class
Browse files Browse the repository at this point in the history
Now cells can be compared, changed and the flipping states are
available.

Prompted by
https://discourse.mapeditor.org/t/flip-value-in-export-python-script/3248
  • Loading branch information
bjorn committed Jun 6, 2018
1 parent d591a4f commit e3b1f87
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 5 deletions.
214 changes: 209 additions & 5 deletions src/plugins/python/pythonbind.cpp
Expand Up @@ -4853,6 +4853,159 @@ PyTypeObject PyTiledMap_Type = {



static PyObject* _wrap_PyTiledCell__get_flippedHorizontally(PyTiledCell *self, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;

py_retval = Py_BuildValue((char *) "N", PyBool_FromLong(self->obj->flippedHorizontally()));
return py_retval;
}
static int _wrap_PyTiledCell__set_flippedHorizontally(PyTiledCell *self, PyObject *value, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;
bool tmp_value;
PyObject *py_boolretval;

py_retval = Py_BuildValue((char *) "(O)", value);
if (!PyArg_ParseTuple(py_retval, (char *) "O", &py_boolretval)) {
Py_DECREF(py_retval);
return -1;
}
tmp_value = PyObject_IsTrue(py_boolretval);
self->obj->setFlippedHorizontally(tmp_value);
Py_DECREF(py_retval);
return 0;
}
static PyObject* _wrap_PyTiledCell__get_flippedVertically(PyTiledCell *self, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;

py_retval = Py_BuildValue((char *) "N", PyBool_FromLong(self->obj->flippedVertically()));
return py_retval;
}
static int _wrap_PyTiledCell__set_flippedVertically(PyTiledCell *self, PyObject *value, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;
bool tmp_value;
PyObject *py_boolretval;

py_retval = Py_BuildValue((char *) "(O)", value);
if (!PyArg_ParseTuple(py_retval, (char *) "O", &py_boolretval)) {
Py_DECREF(py_retval);
return -1;
}
tmp_value = PyObject_IsTrue(py_boolretval);
self->obj->setFlippedVertically(tmp_value);
Py_DECREF(py_retval);
return 0;
}
static PyObject* _wrap_PyTiledCell__get_flippedAntiDiagonally(PyTiledCell *self, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;

py_retval = Py_BuildValue((char *) "N", PyBool_FromLong(self->obj->flippedAntiDiagonally()));
return py_retval;
}
static int _wrap_PyTiledCell__set_flippedAntiDiagonally(PyTiledCell *self, PyObject *value, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;
bool tmp_value;
PyObject *py_boolretval;

py_retval = Py_BuildValue((char *) "(O)", value);
if (!PyArg_ParseTuple(py_retval, (char *) "O", &py_boolretval)) {
Py_DECREF(py_retval);
return -1;
}
tmp_value = PyObject_IsTrue(py_boolretval);
self->obj->setFlippedAntiDiagonally(tmp_value);
Py_DECREF(py_retval);
return 0;
}
static PyObject* _wrap_PyTiledCell__get_rotatedHexagonal120(PyTiledCell *self, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;

py_retval = Py_BuildValue((char *) "N", PyBool_FromLong(self->obj->rotatedHexagonal120()));
return py_retval;
}
static int _wrap_PyTiledCell__set_rotatedHexagonal120(PyTiledCell *self, PyObject *value, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;
bool tmp_value;
PyObject *py_boolretval;

py_retval = Py_BuildValue((char *) "(O)", value);
if (!PyArg_ParseTuple(py_retval, (char *) "O", &py_boolretval)) {
Py_DECREF(py_retval);
return -1;
}
tmp_value = PyObject_IsTrue(py_boolretval);
self->obj->setRotatedHexagonal120(tmp_value);
Py_DECREF(py_retval);
return 0;
}
static PyObject* _wrap_PyTiledCell__get_checked(PyTiledCell *self, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;

py_retval = Py_BuildValue((char *) "N", PyBool_FromLong(self->obj->checked()));
return py_retval;
}
static int _wrap_PyTiledCell__set_checked(PyTiledCell *self, PyObject *value, void * PYBINDGEN_UNUSED(closure))
{
PyObject *py_retval;
bool tmp_value;
PyObject *py_boolretval;

py_retval = Py_BuildValue((char *) "(O)", value);
if (!PyArg_ParseTuple(py_retval, (char *) "O", &py_boolretval)) {
Py_DECREF(py_retval);
return -1;
}
tmp_value = PyObject_IsTrue(py_boolretval);
self->obj->setChecked(tmp_value);
Py_DECREF(py_retval);
return 0;
}
static PyGetSetDef PyTiledCell__getsets[] = {
{
(char*) "flippedVertically", /* attribute name */
(getter) _wrap_PyTiledCell__get_flippedVertically, /* C function to get the attribute */
(setter) _wrap_PyTiledCell__set_flippedVertically, /* C function to set the attribute */
NULL, /* optional doc string */
NULL /* optional additional data for getter and setter */
},
{
(char*) "rotatedHexagonal120", /* attribute name */
(getter) _wrap_PyTiledCell__get_rotatedHexagonal120, /* C function to get the attribute */
(setter) _wrap_PyTiledCell__set_rotatedHexagonal120, /* C function to set the attribute */
NULL, /* optional doc string */
NULL /* optional additional data for getter and setter */
},
{
(char*) "checked", /* attribute name */
(getter) _wrap_PyTiledCell__get_checked, /* C function to get the attribute */
(setter) _wrap_PyTiledCell__set_checked, /* C function to set the attribute */
NULL, /* optional doc string */
NULL /* optional additional data for getter and setter */
},
{
(char*) "flippedAntiDiagonally", /* attribute name */
(getter) _wrap_PyTiledCell__get_flippedAntiDiagonally, /* C function to get the attribute */
(setter) _wrap_PyTiledCell__set_flippedAntiDiagonally, /* C function to set the attribute */
NULL, /* optional doc string */
NULL /* optional additional data for getter and setter */
},
{
(char*) "flippedHorizontally", /* attribute name */
(getter) _wrap_PyTiledCell__get_flippedHorizontally, /* C function to get the attribute */
(setter) _wrap_PyTiledCell__set_flippedHorizontally, /* C function to set the attribute */
NULL, /* optional doc string */
NULL /* optional additional data for getter and setter */
},
{ NULL, NULL, NULL, NULL, NULL }
};


static int
Expand Down Expand Up @@ -4942,6 +5095,26 @@ _wrap_PyTiledCell_tile(PyTiledCell *self)
}


PyObject *
_wrap_PyTiledCell_tileset(PyTiledCell *self)
{
PyObject *py_retval;
Tiled::Tileset *retval;
PyTiledTileset *py_Tileset;

retval = self->obj->tileset();
if (!(retval)) {
Py_INCREF(Py_None);
return Py_None;
}
py_Tileset = PyObject_New(PyTiledTileset, &PyTiledTileset_Type);
py_Tileset->obj = retval;
py_Tileset->flags = PYBINDGEN_WRAPPER_FLAG_OBJECT_NOT_OWNED;
py_retval = Py_BuildValue((char *) "N", py_Tileset);
return py_retval;
}


PyObject *
_wrap_PyTiledCell_isEmpty(PyTiledCell *self)
{
Expand All @@ -4954,6 +5127,25 @@ _wrap_PyTiledCell_isEmpty(PyTiledCell *self)
}


PyObject *
_wrap_PyTiledCell_setTile(PyTiledCell *self, PyObject *args, PyObject *kwargs)
{
PyObject *py_retval;
PyTiledTile *tile;
Tiled::Tile *tile_ptr;
const char *keywords[] = {"tile", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "O!", (char **) keywords, &PyTiledTile_Type, &tile)) {
return NULL;
}
tile_ptr = (tile ? tile->obj : NULL);
self->obj->setTile(tile_ptr);
Py_INCREF(Py_None);
py_retval = Py_None;
return py_retval;
}


static PyObject*
_wrap_PyTiledCell__copy__(PyTiledCell *self)
{
Expand All @@ -4967,7 +5159,9 @@ _wrap_PyTiledCell__copy__(PyTiledCell *self)

static PyMethodDef PyTiledCell_methods[] = {
{(char *) "tile", (PyCFunction) _wrap_PyTiledCell_tile, METH_NOARGS, "tile()\n\n" },
{(char *) "tileset", (PyCFunction) _wrap_PyTiledCell_tileset, METH_NOARGS, "tileset()\n\n" },
{(char *) "isEmpty", (PyCFunction) _wrap_PyTiledCell_isEmpty, METH_NOARGS, "isEmpty()\n\n" },
{(char *) "setTile", (PyCFunction) _wrap_PyTiledCell_setTile, METH_KEYWORDS|METH_VARARGS, "setTile(tile)\n\ntype: tile: Tiled::Tile *" },
{(char *) "__copy__", (PyCFunction) _wrap_PyTiledCell__copy__, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL}
};
Expand Down Expand Up @@ -5000,11 +5194,21 @@ _wrap_PyTiledCell__tp_richcompare (PyTiledCell *PYBINDGEN_UNUSED(self), PyTiledC
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
case Py_EQ:
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
if (*self->obj == *other->obj) {
Py_INCREF(Py_True);
return Py_True;
} else {
Py_INCREF(Py_False);
return Py_False;
}
case Py_NE:
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
if (*self->obj != *other->obj) {
Py_INCREF(Py_True);
return Py_True;
} else {
Py_INCREF(Py_False);
return Py_False;
}
case Py_GE:
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
Expand Down Expand Up @@ -5051,7 +5255,7 @@ PyTypeObject PyTiledCell_Type = {
(iternextfunc)NULL, /* tp_iternext */
(struct PyMethodDef*)PyTiledCell_methods, /* tp_methods */
(struct PyMemberDef*)0, /* tp_members */
0, /* tp_getset */
PyTiledCell__getsets, /* tp_getset */
NULL, /* tp_base */
NULL, /* tp_dict */
(descrgetfunc)NULL, /* tp_descr_get */
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/python/tiledbinding.py
Expand Up @@ -135,8 +135,17 @@
cls_cell = tiled.add_class('Cell')
cls_cell.add_constructor([param('Tiled::Tile*','tile',transfer_ownership=False)])
cls_cell.add_copy_constructor()
cls_cell.add_binary_comparison_operator('==')
cls_cell.add_binary_comparison_operator('!=')
cls_cell.add_method('isEmpty', 'bool', [])
cls_cell.add_instance_attribute('flippedHorizontally', 'bool', getter='flippedHorizontally', setter='setFlippedHorizontally')
cls_cell.add_instance_attribute('flippedVertically', 'bool', getter='flippedVertically', setter='setFlippedVertically')
cls_cell.add_instance_attribute('flippedAntiDiagonally', 'bool', getter='flippedAntiDiagonally', setter='setFlippedAntiDiagonally')
cls_cell.add_instance_attribute('rotatedHexagonal120', 'bool', getter='rotatedHexagonal120', setter='setRotatedHexagonal120')
cls_cell.add_instance_attribute('checked', 'bool', getter='checked', setter='setChecked')
cls_cell.add_method('tile', retval('Tiled::Tile*',reference_existing_object=True), [])
cls_cell.add_method('tileset', retval('Tiled::Tileset*',reference_existing_object=True), [])
cls_cell.add_method('setTile', None, [param('Tiled::Tile*','tile',transfer_ownership=False)])

cls_tilelayer = tiled.add_class('TileLayer', cls_layer)
cls_tilelayer.add_constructor([('QString','name'), ('int','x'), ('int','y'),
Expand Down

0 comments on commit e3b1f87

Please sign in to comment.