feat(editor): unify component registration pipeline
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
#include "Scene/Scene.h"
|
||||
#include "Components/ComponentFactoryRegistry.h"
|
||||
#include "Components/GameObject.h"
|
||||
#include "Components/TransformComponent.h"
|
||||
#include "Components/CameraComponent.h"
|
||||
#include "Components/LightComponent.h"
|
||||
#include "Components/AudioSourceComponent.h"
|
||||
#include "Components/AudioListenerComponent.h"
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
@@ -66,27 +63,6 @@ std::string UnescapeString(const std::string& value) {
|
||||
return unescaped;
|
||||
}
|
||||
|
||||
Component* CreateComponentByType(GameObject* gameObject, const std::string& type) {
|
||||
if (!gameObject) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (type == "Camera") {
|
||||
return gameObject->AddComponent<CameraComponent>();
|
||||
}
|
||||
if (type == "Light") {
|
||||
return gameObject->AddComponent<LightComponent>();
|
||||
}
|
||||
if (type == "AudioSource") {
|
||||
return gameObject->AddComponent<AudioSourceComponent>();
|
||||
}
|
||||
if (type == "AudioListener") {
|
||||
return gameObject->AddComponent<AudioListenerComponent>();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SerializeGameObjectRecursive(std::ostream& os, GameObject* gameObject) {
|
||||
if (!gameObject) {
|
||||
return;
|
||||
@@ -345,7 +321,7 @@ void Scene::DeserializeFromString(const std::string& data) {
|
||||
}
|
||||
|
||||
for (const PendingComponentData& componentData : pending.components) {
|
||||
if (Component* component = CreateComponentByType(go.get(), componentData.type)) {
|
||||
if (Component* component = ComponentFactoryRegistry::Get().CreateComponent(go.get(), componentData.type)) {
|
||||
if (!componentData.payload.empty()) {
|
||||
std::istringstream componentStream(componentData.payload);
|
||||
component->Deserialize(componentStream);
|
||||
|
||||
Reference in New Issue
Block a user