diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityHelpers.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityHelpers.h index 3ef03296f4..5454b19f7a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityHelpers.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/EditorEntityHelpers.h @@ -48,7 +48,7 @@ namespace AzToolsFramework AZStd::string GetEntityName(const AZ::EntityId& entityId, const AZStd::string_view& nameOverride = {}); EntityList EntityIdListToEntityList(const EntityIdList& inputEntityIds); - EntityList EntityIdSetToEntityList(const EntityIdSet & inputEntityIds); + EntityList EntityIdSetToEntityList(const EntityIdSet& inputEntityIds); template struct AddComponents @@ -206,6 +206,7 @@ namespace AzToolsFramework void SelectEntities(const AzToolsFramework::EntityIdList& entities); /// Return a set of entities, culling any that have an ancestor in the list. - EntityIdSet GetCulledEntityHierarchy(const EntityIdList & entities); + /// e.g. This is useful for getting a concise set of entities that need to be duplicated. + EntityIdSet GetCulledEntityHierarchy(const EntityIdList& entities); }; // namespace AzToolsFramework diff --git a/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntityHelpersTests.cpp b/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntityHelpersTests.cpp index 6bf6beb878..51feacfa2b 100644 --- a/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntityHelpersTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntityHelpersTests.cpp @@ -18,9 +18,6 @@ namespace UnitTest { - using namespace AZ; - using namespace AzToolsFramework; - class EditorEntityHelpersTest : public ToolsApplicationFixture { @@ -47,25 +44,14 @@ namespace UnitTest TEST_F(EditorEntityHelpersTest, EditorEntityHelpersTests_GetCulledEntityHierarchy) { - EntityIdList testEntityIds{ m_parent1, m_child1, m_child2, m_grandChild1, m_parent2 }; + AzToolsFramework::EntityIdList testEntityIds{ m_parent1, m_child1, m_child2, m_grandChild1, m_parent2 }; - EntityIdSet culledSet = GetCulledEntityHierarchy(testEntityIds); + AzToolsFramework::EntityIdSet culledSet = AzToolsFramework::GetCulledEntityHierarchy(testEntityIds); // There should only be two EntityIds returned (m_parent1, and m_parent2), // since all the others should be culled out since they have a common ancestor // in the list already - EXPECT_EQ(culledSet.size(), 2); - - EntityIdList foundEntityIds{ m_parent1, m_parent2 }; - for (auto& entityId : foundEntityIds) - { - EXPECT_TRUE(AZStd::find(culledSet.begin(), culledSet.end(), entityId) != culledSet.end()); - } - - EntityIdList culledEntityIds{ m_child1, m_child2, m_grandChild1 }; - for (auto& entityId : culledEntityIds) - { - EXPECT_FALSE(AZStd::find(culledSet.begin(), culledSet.end(), entityId) != culledSet.end()); - } + using ::testing::UnorderedElementsAre; + EXPECT_THAT(culledSet, UnorderedElementsAre(m_parent1, m_parent2)); } } diff --git a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp index 69040245f8..084a5bafaa 100644 --- a/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp +++ b/Code/Sandbox/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp @@ -1231,7 +1231,7 @@ void SandboxIntegrationManager::CloneSelection(bool& handled) AzToolsFramework::EntityIdSet duplicationSet = AzToolsFramework::GetCulledEntityHierarchy(entities); - if (duplicationSet.size() > 0) + if (!duplicationSet.empty()) { AZStd::unordered_set clonedEntities; handled = AzToolsFramework::CloneInstantiatedEntities(duplicationSet, clonedEntities);