/** * Implements Tiled::MapReaderInterface */ Tiled::Map *PythonPlugin::read(const QString &fileName) { reloadModules(); QMapIterator<QString, PyObject*> it(mKnownExtClasses); while (it.hasNext()) { it.next(); if (!checkFileSupport(it.value(), fileName.toUtf8().data())) continue; log(QString("-- %1 supports %2\n").arg(it.key()).arg(fileName)); if (!PyObject_HasAttrString(it.value(), "read")) { mError = "Please define class that extends tiled.Plugin and " "has @classmethod read(cls, filename)"; return NULL; } PyObject *pinst = PyObject_CallMethod(it.value(), (char *)"read", (char *)"(s)", fileName.toUtf8().data()); Tiled::Map *ret = 0; if (!pinst) { PySys_WriteStderr("** Uncaught exception in script **\n"); } else { _wrap_convert_py2c__Tiled__Map___star__(pinst, &ret); Py_DECREF(pinst); } handleError(); if (ret) ret->setProperty("__script__", it.key()); return ret; } return NULL; }
Tiled::Map *PythonMapFormat::read(const QString &fileName) { mError = QString(); mPlugin.log(tr("-- Using script %1 to read %2").arg(mScriptFile, fileName)); if (!PyObject_HasAttrString(mClass, "read")) { mError = "Please define class that extends tiled.Plugin and " "has @classmethod read(cls, filename)"; return nullptr; } PyObject *pinst = PyObject_CallMethod(mClass, (char *)"read", (char *)"(s)", fileName.toUtf8().constData()); Tiled::Map *ret = nullptr; if (!pinst) { PySys_WriteStderr("** Uncaught exception in script **\n"); } else { _wrap_convert_py2c__Tiled__Map___star__(pinst, &ret); Py_DECREF(pinst); } handleError(); if (ret) ret->setProperty("__script__", mScriptFile); return ret; }