Class registering GameComponents mainly used to load them in SceneManager. More...
#include <ComponentFactory.hpp>
Public Types | |
| using | ComponentLoader = std::function<void(GameObject&, const nlohmann::json&)> |
| using | ComponentSaver = std::function<nlohmann::json(GameObject&)> |
| using | ComponentInspector = std::function<void(GameObject&)> |
| using | ComponentChecker = std::function<bool(const GameObject&)> |
| using | ComponentCreator = std::function<void(GameObject&)> |
Public Member Functions | |
| template<typename T> | |
| void | registerComponent (const std::string &name, bool isDynamic=false) |
| Template function to register a component type with the system. | |
| void | unregisterComponent (const std::string &name) |
| Unregisters a component type and removes all associated callbacks. | |
| void | clearDynamicComponents () |
| Clears all components registered as dynamic. | |
| bool | loadComponent (GameObject &obj, const std::string &type, const nlohmann::json &json) |
| Loads data into a component on a GameObject from JSON. | |
| nlohmann::json | saveComponent (GameObject &obj, const std::string &type) |
| Serializes a component on a GameObject to JSON. | |
| void | drawInspectorForObject (GameObject &obj) |
| Draws the ImGui inspector for all components on the object. | |
| void | createComponent (GameObject &obj, const std::string &name) |
| Creates and attaches a specific component to a game object. | |
| std::vector< std::string > | getMissingComponents (const GameObject &obj) |
| Get missing components for a game object. | |
| const std::unordered_map< std::string, ComponentInspector > & | getInspectors () const |
| Get component inspectors. | |
| const std::vector< std::string > & | getRegisteredNames () const |
| Get registered component names. | |
Static Public Member Functions | |
| static ComponentRegistry & | getInstance () |
Private Attributes | |
| std::vector< std::string > | registeredNames |
| std::vector< std::string > | dynamicComponents |
| std::unordered_map< std::string, ComponentLoader > | loaders |
| std::unordered_map< std::string, ComponentSaver > | savers |
| std::unordered_map< std::string, ComponentInspector > | inspectors |
| std::unordered_map< std::string, ComponentChecker > | checkers |
| std::unordered_map< std::string, ComponentCreator > | creators |
Class registering GameComponents mainly used to load them in SceneManager.
Definition at line 298 of file ComponentFactory.hpp.
| using vex::ComponentRegistry::ComponentChecker = std::function<bool(const GameObject&)> |
Definition at line 303 of file ComponentFactory.hpp.
| using vex::ComponentRegistry::ComponentCreator = std::function<void(GameObject&)> |
Definition at line 304 of file ComponentFactory.hpp.
| using vex::ComponentRegistry::ComponentInspector = std::function<void(GameObject&)> |
Definition at line 302 of file ComponentFactory.hpp.
| using vex::ComponentRegistry::ComponentLoader = std::function<void(GameObject&, const nlohmann::json&)> |
Definition at line 300 of file ComponentFactory.hpp.
| using vex::ComponentRegistry::ComponentSaver = std::function<nlohmann::json(GameObject&)> |
Definition at line 301 of file ComponentFactory.hpp.
| void vex::ComponentRegistry::clearDynamicComponents | ( | ) |
Clears all components registered as dynamic.
Used for hot-reloading. Iterates dynamicComponents and manually unregisters each one to clean up function pointers from unloaded DLLs.
Definition at line 43 of file ComponentFactory.cpp.
| void vex::ComponentRegistry::createComponent | ( | GameObject & | obj, |
| const std::string & | name ) |
Creates and attaches a specific component to a game object.
Uses the registered creator lambda to default-construct and add the component.
| GameObject& | obj - The target object. |
| const | std::string& name - The component type name. |
Definition at line 96 of file ComponentFactory.cpp.
| void vex::ComponentRegistry::drawInspectorForObject | ( | GameObject & | obj | ) |
Draws the ImGui inspector for all components on the object.
Iterates through all registered inspectors and calls them on the object.
| GameObject& | obj - The object to inspect. |
Definition at line 80 of file ComponentFactory.cpp.
| const std::unordered_map< std::string, ComponentRegistry::ComponentInspector > & vex::ComponentRegistry::getInspectors | ( | ) | const |
Get component inspectors.
Definition at line 104 of file ComponentFactory.cpp.
|
static |
Definition at line 6 of file ComponentFactory.cpp.
| std::vector< std::string > vex::ComponentRegistry::getMissingComponents | ( | const GameObject & | obj | ) |
Get missing components for a game object.
Definition at line 86 of file ComponentFactory.cpp.
| const std::vector< std::string > & vex::ComponentRegistry::getRegisteredNames | ( | ) | const |
Get registered component names.
Definition at line 108 of file ComponentFactory.cpp.
| bool vex::ComponentRegistry::loadComponent | ( | GameObject & | obj, |
| const std::string & | type, | ||
| const nlohmann::json & | json ) |
Loads data into a component on a GameObject from JSON.
Finds the registered loader for type and executes it. Logs an error if the type is not registered.
| GameObject& | obj - The target object. |
| const | std::string& type - The component type name. |
| const | nlohmann::json& json - The JSON data to load. |
Definition at line 65 of file ComponentFactory.cpp.
|
inline |
Template function to register a component type with the system.
Generates and stores lambdas for:
| const | std::string& name - The name of the component class. |
| bool | isDynamic - Whether this component is part of a hot-reloadable module. |
Definition at line 318 of file ComponentFactory.hpp.
| nlohmann::json vex::ComponentRegistry::saveComponent | ( | GameObject & | obj, |
| const std::string & | type ) |
Serializes a component on a GameObject to JSON.
| GameObject& | obj - The source object. |
| const | std::string& type - The component type name. |
Definition at line 75 of file ComponentFactory.cpp.
| void vex::ComponentRegistry::unregisterComponent | ( | const std::string & | name | ) |
Unregisters a component type and removes all associated callbacks.
Erases entries from loaders, savers, inspectors, checkers, and creators maps, and removes the name from registeredNames.
| const | std::string& name - The name of the component to unregister. |
Definition at line 28 of file ComponentFactory.cpp.
|
private |
Definition at line 416 of file ComponentFactory.hpp.
|
private |
Definition at line 417 of file ComponentFactory.hpp.
|
private |
Definition at line 412 of file ComponentFactory.hpp.
|
private |
Definition at line 415 of file ComponentFactory.hpp.
|
private |
Definition at line 413 of file ComponentFactory.hpp.
|
private |
Definition at line 411 of file ComponentFactory.hpp.
|
private |
Definition at line 414 of file ComponentFactory.hpp.