Skip to content

Commit

Permalink
Traktor: Fixed generating new id of all pasted or cloned entities in …
Browse files Browse the repository at this point in the history
…scene editor.
  • Loading branch information
apistol78 committed Jan 27, 2024
1 parent 3894e47 commit 7dee13b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion code/Scene/Editor/SceneEditorContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Scene/Editor/SceneAsset.h"
#include "Scene/Editor/SceneEditorContext.h"
#include "Scene/Editor/Traverser.h"
#include "Scene/Editor/Utilities.h"
#include "Scene/Editor/Events/CameraMovedEvent.h"
#include "Scene/Editor/Events/MeasurementEvent.h"
#include "Scene/Editor/Events/ModifierChangedEvent.h"
Expand Down Expand Up @@ -764,7 +765,7 @@ void SceneEditorContext::cloneSelected()
Ref< world::EntityData > clonedEntityData = DeepClone(selectedEntityAdapter->getEntityData()).create< world::EntityData >();
T_ASSERT(clonedEntityData);

clonedEntityData->setId(Guid::create());
generateEntityIds(clonedEntityData);

Ref< EntityAdapter > clonedEntityAdapter = new EntityAdapter(this);
clonedEntityAdapter->prepare(clonedEntityData, 0, 0);
Expand Down
3 changes: 2 additions & 1 deletion code/Scene/Editor/SceneEditorPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "Scene/Editor/SceneEditorContext.h"
#include "Scene/Editor/SceneEditorPage.h"
#include "Scene/Editor/ScenePreviewControl.h"
#include "Scene/Editor/Utilities.h"
#include "Scene/Editor/Events/CameraMovedEvent.h"
#include "Scene/Editor/Events/MeasurementEvent.h"
#include "Scene/Editor/Events/PostBuildEvent.h"
Expand Down Expand Up @@ -724,7 +725,7 @@ bool SceneEditorPage::handleCommand(const ui::Command& command)
// Create new instances and adapters for each entity found in clipboard.
for (auto entityData : entityDatas)
{
entityData->setId(Guid::create());
generateEntityIds(entityData);

Ref< EntityAdapter > entityAdapter = new EntityAdapter(m_context);
entityAdapter->prepare(entityData, nullptr, 0);
Expand Down
26 changes: 26 additions & 0 deletions code/Scene/Editor/Utilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* TRAKTOR
* Copyright (c) 2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Scene/Editor/Traverser.h"
#include "Scene/Editor/Utilities.h"
#include "World/EntityData.h"

namespace traktor::scene
{

void generateEntityIds(world::EntityData* entityData)
{
entityData->setId(Guid::create());
Traverser::visit(entityData, [](world::EntityData* ed) -> Traverser::Result
{
ed->setId(Guid::create());
return Traverser::Result::Continue;
});
}

}
29 changes: 29 additions & 0 deletions code/Scene/Editor/Utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* TRAKTOR
* Copyright (c) 2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

namespace traktor::world
{

class EntityData;

}

namespace traktor::scene
{

/*! Recursively generate entity IDs.
* \ingroup Scene
*
* Using traversal to ensure all referenced entities
* get ID properly generated.
*/
void generateEntityIds(world::EntityData* entityData);

}

0 comments on commit 7dee13b

Please sign in to comment.