Skip to content

Commit 688e0fb

Browse files
Add instanceName and profiles methods to plugin API
1 parent 648db4d commit 688e0fb

3 files changed

Lines changed: 58 additions & 16 deletions

File tree

src/mobase/mobase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ PYBIND11_MODULE(mobase, m)
2626

2727
// bindings
2828
//
29-
mo2::python::add_basic_bindings(m);
3029
mo2::python::add_wrapper_bindings(m);
30+
mo2::python::add_basic_bindings(m);
3131

3232
// game features must be added before plugins
3333
mo2::python::add_game_feature_bindings(m);

src/mobase/wrappers/basic_classes.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../pybind11_all.h"
44

55
#include <format>
6+
#include <memory>
67

78
#include <uibase/executableinfo.h>
89
#include <uibase/filemapping.h>
@@ -536,6 +537,7 @@ namespace mo2::python {
536537
py::class_<IOrganizer>(m, "IOrganizer")
537538
.def("createNexusBridge", &IOrganizer::createNexusBridge,
538539
py::return_value_policy::reference)
540+
.def("instanceName", &IOrganizer::instanceName)
539541
.def("profileName", &IOrganizer::profileName)
540542
.def("profilePath", &IOrganizer::profilePath)
541543
.def("downloadsPath", &IOrganizer::downloadsPath)
@@ -626,6 +628,7 @@ namespace mo2::python {
626628
.def("gameFeatures", &IOrganizer::gameFeatures,
627629
py::return_value_policy::reference)
628630
.def("profile", &IOrganizer::profile, py::return_value_policy::reference)
631+
.def("profiles", &IOrganizer::profiles)
629632

630633
// custom implementation for startApplication and
631634
// waitForApplication because 1) HANDLE (= void*) is not properly
@@ -878,21 +881,6 @@ namespace mo2::python {
878881
m.createTarget);
879882
});
880883

881-
// must be done BEFORE imodlist because there is a default argument to a
882-
// IProfile* in the modlist class
883-
py::class_<IProfile>(m, "IProfile")
884-
.def("name", &IProfile::name)
885-
.def("absolutePath", &IProfile::absolutePath)
886-
.def("localSavesEnabled", &IProfile::localSavesEnabled)
887-
.def("localSettingsEnabled", &IProfile::localSettingsEnabled)
888-
.def("invalidationActive",
889-
[](const IProfile* p) {
890-
bool supported;
891-
bool active = p->invalidationActive(&supported);
892-
return std::make_tuple(active, supported);
893-
})
894-
.def("absoluteIniFilePath", &IProfile::absoluteIniFilePath, "inifile"_a);
895-
896884
add_ipluginlist_classes(m);
897885
add_imodlist_classes(m);
898886
add_idownload_manager_classes(m);

src/mobase/wrappers/wrappers.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// IOrganizer must be bring here to properly compile the Python bindings of
1212
// plugin requirements
1313
#include <uibase/imoinfo.h>
14+
#include <uibase/iprofile.h>
1415
#include <uibase/isavegame.h>
1516
#include <uibase/isavegameinfowidget.h>
1617
#include <uibase/pluginrequirements.h>
@@ -75,6 +76,41 @@ namespace mo2::python {
7576
~PySaveGameInfoWidget() { std::cout << "~PySaveGameInfoWidget()" << std::endl; }
7677
};
7778

79+
class PyProfile : public IProfile {
80+
public:
81+
QString name() const override
82+
{
83+
PYBIND11_OVERRIDE_PURE(QString, IProfile, name, );
84+
}
85+
86+
QString absolutePath() const override
87+
{
88+
PYBIND11_OVERRIDE_PURE(QString, IProfile, absolutePath, );
89+
}
90+
91+
bool localSavesEnabled() const override
92+
{
93+
PYBIND11_OVERRIDE_PURE(bool, IProfile, localSavesEnabled, );
94+
}
95+
96+
bool localSettingsEnabled() const override
97+
{
98+
PYBIND11_OVERRIDE_PURE(bool, IProfile, localSettingsEnabled, );
99+
}
100+
101+
bool invalidationActive(bool* supported) const override
102+
{
103+
PYBIND11_OVERRIDE_PURE(bool, IProfile, invalidationActive, supported);
104+
}
105+
106+
QString absoluteIniFilePath(QString iniFile) const override
107+
{
108+
PYBIND11_OVERRIDE_PURE(QString, IProfile, absoluteIniFilePath, iniFile);
109+
}
110+
111+
~PyProfile() { std::cout << "~PyProfile()" << std::endl; }
112+
};
113+
78114
void add_wrapper_bindings(pybind11::module_ m)
79115
{
80116
// ISaveGame - custom type_caster<> for shared_ptr<> to keep the Python object
@@ -115,6 +151,24 @@ namespace mo2::python {
115151
.def("longDescription", &IPluginRequirement::Problem::longDescription);
116152

117153
iPluginRequirementClass.def("check", &IPluginRequirement::check, "organizer"_a);
154+
155+
// IProfile - custom type_caster<> for shared_ptr<> to keep the Python object
156+
// alive when returned from Python (see shared_cpp_owner.h)
157+
158+
// must be done BEFORE imodlist because there is a default argument to a
159+
// IProfile* in the modlist class
160+
py::class_<IProfile, PyProfile, std::shared_ptr<IProfile>>(m, "IProfile")
161+
.def("name", &IProfile::name)
162+
.def("absolutePath", &IProfile::absolutePath)
163+
.def("localSavesEnabled", &IProfile::localSavesEnabled)
164+
.def("localSettingsEnabled", &IProfile::localSettingsEnabled)
165+
.def("invalidationActive",
166+
[](const IProfile* p) {
167+
bool supported;
168+
bool active = p->invalidationActive(&supported);
169+
return std::make_tuple(active, supported);
170+
})
171+
.def("absoluteIniFilePath", &IProfile::absoluteIniFilePath, "inifile"_a);
118172
}
119173

120174
} // namespace mo2::python

0 commit comments

Comments
 (0)