From aa75c3b18e04a70bafd1e45eaf735a79aaea7db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Wed, 13 May 2020 17:35:33 +0200 Subject: [PATCH] Add .feature() method to the Python interface of IPluginGame. --- src/runner/pythonrunner.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index aab292f..f3c2e72 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -678,6 +678,36 @@ BOOST_PYTHON_MODULE(mobase) }); return dict; }) + + .def("feature", +[](MOBase::IPluginGame* p, bpy::object clsObj) { + bpy::object feature; + mp11::mp_for_each< + mp11::mp_transform< + // Must user pointers because mp_for_each construct object: + std::add_pointer_t, + mp11::mp_list< + BSAInvalidation, + DataArchives, + GamePlugins, + LocalSavegames, + SaveGameInfo, + ScriptExtender, + UnmanagedMods + > + > + >([&](auto* pt) { + using T = std::remove_pointer_t; + typename bpy::reference_existing_object::apply::type converter; + + // Retrieve the python class object: + const bpy::converter::registration* registration = bpy::converter::registry::query(bpy::type_id()); + + if (clsObj.ptr() == (PyObject*) registration->get_class_object()) { + feature = bpy::object(bpy::handle<>(converter(p->feature()))); + } + }); + return feature; + }) ; bpy::enum_("InstallResult")