mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Using serializer for the scene copy
This commit is contained in:
@@ -11,10 +11,22 @@ namespace Nuake {
|
||||
unsigned int mModule = 0;
|
||||
Ref<WrenScript> mWrenScript;
|
||||
|
||||
void LoadScript(const std::string& path)
|
||||
{
|
||||
Ref<Nuake::File> nuakeFile = Nuake::FileSystem::GetFile(Script);
|
||||
mWrenScript = CreateRef<Nuake::WrenScript>(nuakeFile, true);
|
||||
auto modules = mWrenScript->GetModules();
|
||||
if (modules.size() > 0)
|
||||
{
|
||||
mModule = 0;
|
||||
}
|
||||
}
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(Script);
|
||||
SERIALIZE_VAL(mModule)
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
@@ -22,8 +34,15 @@ namespace Nuake {
|
||||
{
|
||||
BEGIN_DESERIALIZE();
|
||||
if (j.contains("Script"))
|
||||
{
|
||||
Script = j["Script"];
|
||||
LoadScript(Script);
|
||||
}
|
||||
|
||||
if (j.contains("mModule"))
|
||||
{
|
||||
mModule = j["mModule"];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,18 +36,20 @@ namespace Nuake
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void RemoveComponent() {
|
||||
void RemoveComponent()
|
||||
{
|
||||
m_Scene->m_Registry.remove<T>(m_EntityHandle);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& GetComponent() {
|
||||
T& GetComponent()
|
||||
{
|
||||
T& component = m_Scene->m_Registry.get<T>(m_EntityHandle);
|
||||
return component;
|
||||
}
|
||||
|
||||
void Destroy() {
|
||||
Logger::Log("Deleted eneity :" + std::to_string((int)m_EntityHandle));
|
||||
void Destroy()
|
||||
{
|
||||
m_Scene->m_Registry.destroy(m_EntityHandle);
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,9 @@ namespace Nuake {
|
||||
ParentComponent& parentC = entity.GetComponent<ParentComponent>();
|
||||
std::vector<Entity> copyChildrens = parentC.Children;
|
||||
|
||||
if (parentC.HasParent) { // Remove self from parents children lists.
|
||||
if (parentC.HasParent)
|
||||
{
|
||||
// Remove self from parents children lists.
|
||||
ParentComponent& parent = parentC.Parent.GetComponent<ParentComponent>();
|
||||
parent.RemoveChildren(entity);
|
||||
}
|
||||
@@ -306,47 +308,10 @@ namespace Nuake {
|
||||
Ref<Scene> Scene::Copy()
|
||||
{
|
||||
Ref<Scene> sceneCopy = CreateRef<Scene>();
|
||||
sceneCopy->Path = this->Path;
|
||||
sceneCopy->Name = this->Name;
|
||||
|
||||
sceneCopy->m_EditorCamera = this->m_EditorCamera->Copy();
|
||||
|
||||
sceneCopy->SetEnvironment(this->GetEnvironment()->Copy());
|
||||
|
||||
auto& srcRegistry = this->m_Registry;
|
||||
auto& dstRegistry = sceneCopy->m_Registry;
|
||||
auto idView = srcRegistry.view<NameComponent>();
|
||||
for (auto e : idView)
|
||||
{
|
||||
NameComponent& nameComponent = srcRegistry.get<NameComponent>(e);
|
||||
int id = nameComponent.ID;
|
||||
std::string& name = nameComponent.Name;
|
||||
sceneCopy->CreateEntity(name, id);
|
||||
}
|
||||
json serializedScene = Serialize();
|
||||
|
||||
CopyComponent<ParentComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
|
||||
/*auto parentView = m_Registry.view<ParentComponent, NameComponent>();
|
||||
for (auto e : parentView)
|
||||
{
|
||||
auto& [parentComponent, nameComponent] = m_Registry.get<ParentComponent, NameComponent>(e);
|
||||
|
||||
if (parentComponent.HasParent)
|
||||
{
|
||||
int id = parentComponent.ParentID;
|
||||
|
||||
auto newEnt = sceneCopy->GetEntityByID(nameComponent.ID);
|
||||
sceneCopy->GetEntityByID(id).AddChild(newEnt);
|
||||
}
|
||||
}*/
|
||||
|
||||
CopyComponent<VisibilityComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<TransformComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<LightComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<ModelComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<CameraComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<WrenScriptComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
CopyComponent<QuakeMapComponent>(sceneCopy->m_Registry, this->m_Registry);
|
||||
sceneCopy->Deserialize(serializedScene.dump());
|
||||
return sceneCopy;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,6 @@ namespace Nuake {
|
||||
globalScale *= transformComponent.GetLocalScale();
|
||||
|
||||
NameComponent& nameComponent = parentComponent.Parent.GetComponent<NameComponent>();
|
||||
//std::cout << "Name:" << nameComponent.Name << std::endl;
|
||||
|
||||
parentComponent = parentComponent.Parent.GetComponent<ParentComponent>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user