R-Type
PrefabManager.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** R-type
4 ** File description:
5 ** PrefabManager
6 */
7 
8 #ifndef PREFABMANAGER_HPP_
9 #define PREFABMANAGER_HPP_
10 
11 #include <string>
12 #include <unordered_map>
13 #include <typeindex>
14 #include <functional>
15 #include <nlohmann/json.hpp>
16 #include "Entity.hpp"
17 #include "Registry.hpp"
18 #include "AssetManager.hpp"
19 
21 
22 namespace GameEngine
23 {
26  {
27  public:
30  PrefabManager(AssetManager &assetManager);
32  ~PrefabManager() = default;
35  void loadPrefabFromFile(const std::string &filename);
41  const std::string &prefabName, Registry &registry, bool loadTexture = true, bool loadFont = true);
47  Entity createEntityFromPrefab(const std::string &prefabName, Registry &registry, size_t id,
48  bool loadTexture = true, bool loadFont = true);
52  bool isPrefabLoaded(const std::string &prefabName) const;
53 
54  protected:
55  private:
56  std::reference_wrapper<AssetManager> _assetManager;
57  std::unordered_map<std::string, std::unordered_map<std::type_index, std::any>> _prefabs;
58  std::unordered_map<std::string, std::function<std::pair<std::type_index, std::any>(json)>> _componentConverters;
59  std::unordered_map<std::type_index, std::function<void(Registry &registry, const std::any &, Entity)>>
60  _componentAdders;
61  };
62 } // namespace GameEngine
63 
64 #endif /* !PREFABMANAGER_HPP_ */
nlohmann::json json
Definition: PrefabManager.hpp:20
Class to manage assets.
Definition: AssetManager.hpp:18
Entity class for the game engine.
Definition: Entity.hpp:18
Class to manage prefabs.
Definition: PrefabManager.hpp:26
~PrefabManager()=default
Destructor.
void loadPrefabFromFile(const std::string &filename)
Load a prefab.
Definition: PrefabManager.cpp:79
bool isPrefabLoaded(const std::string &prefabName) const
Check if prefab is loaded.
Definition: PrefabManager.cpp:147
Entity createEntityFromPrefab(const std::string &prefabName, Registry &registry, bool loadTexture=true, bool loadFont=true)
Create an entity from a prefab.
Definition: PrefabManager.cpp:102
PrefabManager(AssetManager &assetManager)
Contructor.
Definition: PrefabManager.cpp:17
Entity component system, handling entities, components and systems.
Definition: Registry.hpp:31
Definition: AssetManager.hpp:15