From 2fcb932e16f022520e53d2bd7dd128438db0b144 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sun, 10 Jan 2016 19:50:19 +0100 Subject: [PATCH] allow for game plugins to be written in python --- src/runner/proxypluginwrappers.cpp | 51 ++++++++++++++++++++++++++++++ src/runner/proxypluginwrappers.h | 4 ++- src/runner/pythonrunner.cpp | 13 +++++--- src/runner/uibasewrappers.h | 5 ++- 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/runner/proxypluginwrappers.cpp b/src/runner/proxypluginwrappers.cpp index 49d458c..e82fea2 100644 --- a/src/runner/proxypluginwrappers.cpp +++ b/src/runner/proxypluginwrappers.cpp @@ -13,6 +13,57 @@ using namespace MOBase; catch (...) { throw MyException("An unknown exception was thrown in python code"); } +///////////////////////////// +/// IPlugin Wrapper +bool IPluginWrapper::init(MOBase::IOrganizer *moInfo) +{ + try { + return this->get_override("init")(bpy::ptr(moInfo)); + } PYCATCH; +} + +QString IPluginWrapper::name() const +{ + try { + return this->get_override("name")().as(); + } PYCATCH; +} + +QString IPluginWrapper::author() const +{ + try { + return this->get_override("author")().as(); + } PYCATCH; +} + +QString IPluginWrapper::description() const +{ + try { + return this->get_override("description")().as(); + } PYCATCH; +} + +MOBase::VersionInfo IPluginWrapper::version() const +{ + try { + return this->get_override("version")().as(); + } PYCATCH; +} + +bool IPluginWrapper::isActive() const +{ + try { + return this->get_override("isActive")().as(); + } PYCATCH; +} + +QList IPluginWrapper::settings() const +{ + try { + return this->get_override("settings")().as>(); + } PYCATCH; +} +/// end IPlugin Wrapper ///////////////////////////// /// IPluginTool Wrapper diff --git a/src/runner/proxypluginwrappers.h b/src/runner/proxypluginwrappers.h index 089ce35..6131a24 100644 --- a/src/runner/proxypluginwrappers.h +++ b/src/runner/proxypluginwrappers.h @@ -11,8 +11,10 @@ #endif -class IPluginWrapper : public boost::python::wrapper +class IPluginWrapper : public MOBase::IPlugin, public boost::python::wrapper { + Q_INTERFACES(MOBase::IPlugin) + public: virtual bool init(MOBase::IOrganizer *moInfo); virtual QString name() const; diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 6f9d182..a27fe74 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -5,6 +5,9 @@ #include "iplugingame.h" #include +#include +#include +#include #include "uibasewrappers.h" #include "pythonpluginwrapper.h" #include "proxypluginwrappers.h" @@ -757,8 +760,7 @@ BOOST_PYTHON_MODULE(mobase) bpy::class_("IDownloadManager") .def("startDownloadURLs", bpy::pure_virtual(&IDownloadManager::startDownloadURLs)) - //not used? - //.def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile)) + .def("startDownloadNexusFile", bpy::pure_virtual(&IDownloadManager::startDownloadNexusFile)) .def("downloadPath", bpy::pure_virtual(&IDownloadManager::downloadPath)) ; @@ -800,9 +802,12 @@ BOOST_PYTHON_MODULE(mobase) .def("variants", &MOBase::GuessedValue::variants, bpy::return_value_policy()) ; - bpy::class_("IPluginTool") + bpy::class_("IPlugin"); + + bpy::class_, boost::noncopyable>("IPluginTool") .def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginTool::setParentWidget)) ; + bpy::class_("IPluginInstallerCustom") .def("setParentWidget", bpy::pure_virtual(&MOBase::IPluginInstallerCustom::setParentWidget)) ; @@ -846,7 +851,6 @@ BOOST_PYTHON_MODULE(mobase) .value("preferDefaults", MOBase::IPluginGame::PREFER_DEFAULTS) ; - bpy::class_("IPluginGame") .def("gameName", bpy::pure_virtual(&MOBase::IPluginGame::gameName)) .def("initializeProfile", bpy::pure_virtual(&MOBase::IPluginGame::initializeProfile)) @@ -1008,6 +1012,7 @@ QObject *PythonRunner::instantiate(const QString &pluginName) bpy::object pluginObj = m_PythonObjects[pluginName]; TRY_PLUGIN_TYPE(IPluginInstallerCustom, pluginObj); TRY_PLUGIN_TYPE(IPluginTool, pluginObj); + TRY_PLUGIN_TYPE(IPluginGame, pluginObj); } catch (const bpy::error_already_set&) { qWarning("failed to run python script \"%s\"", qPrintable(pluginName)); reportPythonError(); diff --git a/src/runner/uibasewrappers.h b/src/runner/uibasewrappers.h index 609bd7c..29d6e9b 100644 --- a/src/runner/uibasewrappers.h +++ b/src/runner/uibasewrappers.h @@ -241,9 +241,8 @@ struct IProfileWrapper: MOBase::IProfile, boost::python::wrapper { - virtual int startDownloadURLs(const QStringList &urls) { return this->get_override("downloadURLs")(urls); } - //not used - //virtual int startDownloadNexusFile(int modID, int fileID) { return this->get_override("downloadNexusFile")(modID, fileID); } + virtual int startDownloadURLs(const QStringList &urls) { return this->get_override("startDownloadURLs")(urls); } + virtual int startDownloadNexusFile(int modID, int fileID) { return this->get_override("startDownloadNexusFile")(modID, fileID); } virtual QString downloadPath(int id) { return this->get_override("downloadPath")(id); } };