feat(editor): unify component registration pipeline
This commit is contained in:
45
editor/src/ComponentEditors/ComponentEditorRegistry.cpp
Normal file
45
editor/src/ComponentEditors/ComponentEditorRegistry.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "ComponentEditors/ComponentEditorRegistry.h"
|
||||
|
||||
#include "ComponentEditors/CameraComponentEditor.h"
|
||||
#include "ComponentEditors/LightComponentEditor.h"
|
||||
#include "ComponentEditors/TransformComponentEditor.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
ComponentEditorRegistry& ComponentEditorRegistry::Get() {
|
||||
static ComponentEditorRegistry registry;
|
||||
return registry;
|
||||
}
|
||||
|
||||
ComponentEditorRegistry::ComponentEditorRegistry() {
|
||||
RegisterEditor(std::make_unique<TransformComponentEditor>());
|
||||
RegisterEditor(std::make_unique<CameraComponentEditor>());
|
||||
RegisterEditor(std::make_unique<LightComponentEditor>());
|
||||
}
|
||||
|
||||
void ComponentEditorRegistry::RegisterEditor(std::unique_ptr<IComponentEditor> editor) {
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
IComponentEditor* editorPtr = editor.get();
|
||||
m_editorsByType[editor->GetComponentTypeName()] = editorPtr;
|
||||
m_editors.push_back(std::move(editor));
|
||||
}
|
||||
|
||||
IComponentEditor* ComponentEditorRegistry::FindEditor(::XCEngine::Components::Component* component) const {
|
||||
return component ? FindEditorByTypeName(component->GetName()) : nullptr;
|
||||
}
|
||||
|
||||
IComponentEditor* ComponentEditorRegistry::FindEditorByTypeName(const std::string& componentTypeName) const {
|
||||
const auto it = m_editorsByType.find(componentTypeName);
|
||||
return it != m_editorsByType.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<IComponentEditor>>& ComponentEditorRegistry::GetEditors() const {
|
||||
return m_editors;
|
||||
}
|
||||
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user