From 88c386d74d7d94ec16d4d84ed674eb51e31647ac Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Sun, 9 Jun 2024 12:18:17 +0200 Subject: Refactoring of game features for better management. (#2043) --- src/game_features.h | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/game_features.h (limited to 'src/game_features.h') diff --git a/src/game_features.h b/src/game_features.h new file mode 100644 index 00000000..55f35e37 --- /dev/null +++ b/src/game_features.h @@ -0,0 +1,117 @@ +#ifndef MO2_GAME_FEATURES_H +#define MO2_GAME_FEATURES_H + +#include +#include +#include +#include +#include + +#include + +#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 feature, int priority); + + // unregister game features + // + bool unregisterGameFeature(std::shared_ptr feature); + int unregisterGameFeatures(MOBase::IPlugin* plugin, std::type_info const& info); + + // retrieve a game feature + // + template + std::shared_ptr gameFeature() const + { + return std::dynamic_pointer_cast(gameFeature(typeid(T))); + } + +signals: + void modDataCheckerUpdated(const MOBase::ModDataChecker* check); + void modDataContentUpdated(const MOBase::ModDataContent* check); + +private: + friend class GameFeaturesProxy; + + class GameFeatureWithData + { + // feature + std::shared_ptr 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 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 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> m_allFeatures; + std::unordered_map>> + m_currentFeatures; + + std::shared_ptr m_modDataChecker; + std::shared_ptr m_modDataContent; +}; + +#endif -- cgit v1.3.1