feat(editor): unify component registration pipeline
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
#include "SceneManager.h"
|
||||
#include "Core/EventBus.h"
|
||||
#include "Core/EditorEvents.h"
|
||||
#include <XCEngine/Components/ComponentFactoryRegistry.h>
|
||||
#include <XCEngine/Components/CameraComponent.h>
|
||||
#include <XCEngine/Components/LightComponent.h>
|
||||
#include <XCEngine/Components/AudioSourceComponent.h>
|
||||
#include <XCEngine/Components/AudioListenerComponent.h>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -21,29 +20,6 @@ std::pair<std::string, std::string> SerializeComponent(const ::XCEngine::Compone
|
||||
return { component->GetName(), payload.str() };
|
||||
}
|
||||
|
||||
::XCEngine::Components::Component* CreateComponentByName(
|
||||
::XCEngine::Components::GameObject* gameObject,
|
||||
const std::string& componentName) {
|
||||
if (!gameObject) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (componentName == "Camera") {
|
||||
return gameObject->AddComponent<::XCEngine::Components::CameraComponent>();
|
||||
}
|
||||
if (componentName == "Light") {
|
||||
return gameObject->AddComponent<::XCEngine::Components::LightComponent>();
|
||||
}
|
||||
if (componentName == "AudioSource") {
|
||||
return gameObject->AddComponent<::XCEngine::Components::AudioSourceComponent>();
|
||||
}
|
||||
if (componentName == "AudioListener") {
|
||||
return gameObject->AddComponent<::XCEngine::Components::AudioListenerComponent>();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
SceneManager::SceneManager(EventBus* eventBus)
|
||||
@@ -152,7 +128,7 @@ void SceneManager::CopyEntity(::XCEngine::Components::GameObject::ID id) {
|
||||
}
|
||||
|
||||
for (const auto& componentData : data.components) {
|
||||
if (auto* component = CreateComponentByName(newEntity, componentData.first)) {
|
||||
if (auto* component = ::XCEngine::Components::ComponentFactoryRegistry::Get().CreateComponent(newEntity, componentData.first)) {
|
||||
if (!componentData.second.empty()) {
|
||||
std::istringstream payloadStream(componentData.second);
|
||||
component->Deserialize(payloadStream);
|
||||
|
||||
Reference in New Issue
Block a user