feat(editor): unify component registration pipeline
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Components {
|
||||
|
||||
class Component;
|
||||
class GameObject;
|
||||
|
||||
class ComponentFactoryRegistry {
|
||||
public:
|
||||
using CreateComponentFn = Component* (*)(GameObject* gameObject);
|
||||
|
||||
static ComponentFactoryRegistry& Get();
|
||||
|
||||
void RegisterFactory(const std::string& typeName, CreateComponentFn createFn);
|
||||
Component* CreateComponent(GameObject* gameObject, const std::string& typeName) const;
|
||||
bool IsRegistered(const std::string& typeName) const;
|
||||
const std::vector<std::string>& GetRegisteredTypes() const;
|
||||
|
||||
private:
|
||||
ComponentFactoryRegistry();
|
||||
|
||||
std::unordered_map<std::string, CreateComponentFn> m_factories;
|
||||
std::vector<std::string> m_registrationOrder;
|
||||
};
|
||||
|
||||
} // namespace Components
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user