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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#ifndef MO2_GAME_FEATURES_H
#define MO2_GAME_FEATURES_H
#include <any>
#include <memory>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#include <QObject>
#include "game_feature.h"
#include "moddatachecker.h"
#include "moddatacontent.h"
namespace MOBase
{
class IPlugin;
class IPluginGame;
} // namespace MOBase
class OrganizerCore;
class PluginContainer;
/**
* Class managing game features, either registered or from the game plugin.
*/
class GameFeatures : public QObject
{
Q_OBJECT
public:
/**
*
*/
GameFeatures(OrganizerCore* core, PluginContainer* plugins);
~GameFeatures();
// register game features
//
bool registerGameFeature(MOBase::IPlugin* plugin, QStringList const& games,
std::shared_ptr<MOBase::GameFeature> feature, int priority);
// unregister game features
//
bool unregisterGameFeature(std::shared_ptr<MOBase::GameFeature> feature);
int unregisterGameFeatures(MOBase::IPlugin* plugin, std::type_info const& info);
// retrieve a game feature
//
template <class T>
std::shared_ptr<T> gameFeature() const
{
return std::dynamic_pointer_cast<T>(gameFeature(typeid(T)));
}
signals:
void modDataCheckerUpdated(const MOBase::ModDataChecker* check);
void modDataContentUpdated(const MOBase::ModDataContent* content);
private:
friend class GameFeaturesProxy;
class GameFeatureWithData
{
// feature
std::shared_ptr<MOBase::GameFeature> m_feature;
// plugin that registered the feature
MOBase::IPlugin* m_plugin;
// games this plugin applies to - empty list indicates all games
QStringList m_games;
// priority of the plugin
int m_priority;
public:
GameFeatureWithData(std::shared_ptr<MOBase::GameFeature> feature,
MOBase::IPlugin* plugin, QStringList games, int priority)
: m_feature(feature), m_plugin(plugin), m_games(games), m_priority(priority)
{}
const auto& feature() const { return m_feature; }
auto* const plugin() const { return m_plugin; }
const auto& games() const { return m_games; }
auto priority() const { return m_priority; }
};
// retrieve a game feature from info
//
std::shared_ptr<MOBase::GameFeature> gameFeature(std::type_info const& index) const;
// update current features by filtering
//
void updateCurrentFeatures(std::type_index const& index);
void updateCurrentFeatures();
// implementation details
class CombinedModDataChecker;
class CombinedModDataContent;
CombinedModDataChecker& modDataChecker() const;
CombinedModDataContent& modDataContent() const;
PluginContainer& m_pluginContainer;
std::unordered_map<std::type_index, std::vector<GameFeatureWithData>> m_allFeatures;
std::unordered_map<std::type_index, std::vector<std::shared_ptr<MOBase::GameFeature>>>
m_currentFeatures;
std::shared_ptr<CombinedModDataChecker> m_modDataChecker;
std::shared_ptr<CombinedModDataContent> m_modDataContent;
};
#endif
|