blob: f7efefd23cf1f4a0c88b03ef2b4e875167ef7149 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#include "basicgamesproxy.h"
#include "basicgameplugin.h"
#include "gamedefs.h"
#include <uibase/versioninfo.h>
BasicGamesProxy::BasicGamesProxy() {}
BasicGamesProxy::~BasicGamesProxy()
{
// Clean up all loaded plugins
for (auto& list : m_loaded) {
qDeleteAll(list);
}
m_loaded.clear();
}
bool BasicGamesProxy::init(MOBase::IOrganizer* organizer)
{
m_organizer = organizer;
return true;
}
QString BasicGamesProxy::name() const
{
return "Basic Games Native";
}
QString BasicGamesProxy::author() const
{
return "Fluorine Manager";
}
QString BasicGamesProxy::description() const
{
return "Native C++ implementation of basic game plugins";
}
MOBase::VersionInfo BasicGamesProxy::version() const
{
return MOBase::VersionInfo(1, 0, 0);
}
QList<MOBase::PluginSetting> BasicGamesProxy::settings() const
{
return {};
}
QStringList BasicGamesProxy::pluginList(const QDir&) const
{
QStringList list;
const auto& defs = allGameDefinitions();
for (size_t i = 0; i < defs.size(); ++i) {
list.append(QString("native_game_%1").arg(i));
}
return list;
}
QList<QObject*> BasicGamesProxy::load(const QString& identifier)
{
// Already loaded?
auto it = m_loaded.find(identifier);
if (it != m_loaded.end()) {
return it.value();
}
QList<QObject*> plugins;
// Parse the index from the identifier
if (!identifier.startsWith("native_game_"))
return plugins;
bool ok = false;
int index = identifier.mid(12).toInt(&ok);
if (!ok)
return plugins;
const auto& defs = allGameDefinitions();
if (index < 0 || index >= static_cast<int>(defs.size()))
return plugins;
auto* plugin = new BasicGamePlugin(defs[index]);
if (m_organizer) {
plugin->init(m_organizer);
}
plugins.append(plugin);
m_loaded.insert(identifier, plugins);
return plugins;
}
void BasicGamesProxy::unload(const QString& identifier)
{
auto it = m_loaded.find(identifier);
if (it != m_loaded.end()) {
qDeleteAll(it.value());
m_loaded.erase(it);
}
}
|