2#include "components/ErrorUtils.hpp"
7 static ComponentRegistry instance;
12 void ComponentRegistry::SetEditorIcon(
const std::string &name, ImTextureID icon)
14 m_editorIcons[name] = icon;
17 ImTextureID ComponentRegistry::GetEditorIcon(
const std::string &name)
19 return m_editorIcons[name];
22 ImTextureID GetEditorIcon_Internal(
const std::string &name)
24 return ComponentRegistry::getInstance().GetEditorIcon(name);
31 inspectors.erase(name);
35 auto it = std::remove(registeredNames.begin(), registeredNames.end(), name);
36 if (it != registeredNames.end()) {
37 registeredNames.erase(it, registeredNames.end());
40 log(
"Component '%s' unregistered", name.c_str());
44 if (dynamicComponents.empty())
return;
46 log(
"Hot Reload: Clearing %zu game components...", dynamicComponents.size());
48 for (
const auto& name : dynamicComponents) {
52 inspectors.erase(name);
56 auto it = std::remove(registeredNames.begin(), registeredNames.end(), name);
57 if (it != registeredNames.end()) {
58 registeredNames.erase(it, registeredNames.end());
62 dynamicComponents.clear();
66 auto it = loaders.find(type);
67 if (it != loaders.end()) {
68 it->second(obj, json);
71 log(
"Error: Component type '%s' not registered", type.c_str());
76 if (savers.find(type) != savers.end())
return savers[type](obj);
81 for (
auto& [name, inspector] : inspectors) {
87 std::vector<std::string> missing;
88 for (
const auto& name : registeredNames) {
89 if (checkers.find(name) != checkers.end() && !checkers[name](obj)) {
90 missing.push_back(name);
97 if (creators.find(name) != creators.end()) {
100 log(
"Error: Cannot create component '%s', not registered.", name.c_str());
109 return registeredNames;
Contains ComponentRegistry class used to have register of posible to create components....
Class registering GameComponents mainly used to load them in SceneManager.
nlohmann::json saveComponent(GameObject &obj, const std::string &type)
Serializes a component on a GameObject to JSON.
const std::unordered_map< std::string, ComponentInspector > & getInspectors() const
Get component inspectors.
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.
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::vector< std::string > & getRegisteredNames() const
Get registered component names.
void unregisterComponent(const std::string &name)
Unregisters a component type and removes all associated callbacks.
void drawInspectorForObject(GameObject &obj)
Draws the ImGui inspector for all components on the object.
Its base class for all game objects, eg. Player, Enemy, Weapon. Your Class needs to inherit from it.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.