From 3d9cda299055e518b94d5013586ef568a04fcae7 Mon Sep 17 00:00:00 2001 From: antopilo Date: Thu, 19 Sep 2024 21:36:44 -0400 Subject: [PATCH] Minor improvements with prefab deserialization --- .../PrefabEditor/PrefabEditorWindow.cpp | 2 +- Nuake/src/Resource/Prefab.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp index 605aaa82..fc667ad7 100644 --- a/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp +++ b/Editor/src/Windows/PrefabEditor/PrefabEditorWindow.cpp @@ -36,7 +36,7 @@ PrefabEditorWindow::PrefabEditorWindow(Ref inPrefab) : virtualScene->GetEnvironment()->CurrentSkyType = SkyType::ProceduralSky; virtualScene->GetEnvironment()->ProceduralSkybox->SunDirection = { 0.58f, 0.34f, -0.74f }; - prefab = Prefab::InstanceInScene(inPrefab->Path, virtualScene); + prefab = Prefab::InstanceInScene(inPrefab->Path, virtualScene.get()); prefab->Path = inPrefab->Path; Ref outputTexture = CreateRef(defaultSize, GL_RGB); diff --git a/Nuake/src/Resource/Prefab.cpp b/Nuake/src/Resource/Prefab.cpp index b4a7c13e..0e3ebf5b 100644 --- a/Nuake/src/Resource/Prefab.cpp +++ b/Nuake/src/Resource/Prefab.cpp @@ -85,6 +85,23 @@ namespace Nuake Entity newEntity = { entity.GetScene()->m_Registry.create(), entity.GetScene() }; newEntity.Deserialize(e); // Id gets overriden by serialized id. + if (newEntity.GetComponent().HasParent) + { + auto pId = newEntity.GetComponent().ParentID; + newEntity.GetComponent().ParentID = newIdsLut[pId]; + auto nc = entity.GetScene()->GetEntityByID(pId); + nc.GetComponent().RemoveChildren(newEntity); + newEntity.GetComponent().Parent = entity.GetScene()->GetEntityByID(newIdsLut[pId]); + entity.GetScene()->GetEntityByID(newIdsLut[pId]).AddChild(newEntity); + + + } + + if (newEntity.GetComponent().ParentID == j["Root"]) + { + entity.AddChild(newEntity); + } + auto& nameComponent = newEntity.GetComponent(); uint32_t oldId = nameComponent.ID; @@ -103,6 +120,7 @@ namespace Nuake auto& parentC = e.GetComponent(); auto parent = entity.GetScene()->GetEntityByID(newIdsLut[parentC.ParentID]); + Logger::Log(parent.GetComponent().Name); if (parentC.ParentID == j["Root"]) { entity.AddChild(e);