From 3e92ea6b3e10a7ce8f1d3cf33e8602a329acf872 Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Tue, 30 Nov 2021 18:58:40 +0000 Subject: [PATCH] review change Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- .../Code/Source/Editor/MainWindow.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp index c1eaa32bb6..e58ea77373 100644 --- a/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp +++ b/Gems/LandscapeCanvas/Code/Source/Editor/MainWindow.cpp @@ -203,20 +203,25 @@ namespace LandscapeCanvasEditor { using namespace AzToolsFramework; - // Check whether the first category has a preferred component and return that if it does. - const AZStd::unordered_map preferredComponentByCategory = { { "Shape", "Shape Reference" } }; + // A map of category names with preferred component names. + // There may be multiple component names for a category, as long as they provide different services. + const AZStd::map> preferredComponentsByCategory = { { "Shape", { "Shape Reference" } } }; - const AZStd::string firstCategoryName(componentDataTable.begin()->first.toUtf8()); - - const auto& preferredComponentPair = preferredComponentByCategory.find(firstCategoryName); - - if (preferredComponentPair != preferredComponentByCategory.end()) + // Scan through the preferred categories to see whether any exist in the componentDataTable. + for (const auto& preferredComponentPair : preferredComponentsByCategory) { - const auto& componentPair = componentDataTable.begin()->second.find(preferredComponentPair->second); - - if (componentPair != componentDataTable.begin()->second.end()) + auto candidateDataTablePair = componentDataTable.find(preferredComponentPair.first); + if (candidateDataTablePair != componentDataTable.end()) { - return componentPair->second->m_typeId; + // Now check all the preferred components for that category, and return the first one that exists in the candidate componentDataTable. + for (const auto& preferredComponentName : preferredComponentPair.second) + { + const auto& candidateComponent = candidateDataTablePair->second.find(preferredComponentName); + if (candidateComponent != candidateDataTablePair->second.end()) + { + return candidateComponent->second->m_typeId; + } + } } }