Fixed a unit test that broke in my last commit.

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
monroegm-disable-blank-issue-2
santorac 4 years ago
parent a7bdb05d66
commit 466e388f60

@ -285,7 +285,8 @@ namespace AZ
//! Return false to terminate the traversal.
using EnumeratePropertyGroupsCallback = AZStd::function<bool(
const PropertyGroup*, // the next property group in the tree
const MaterialNameContext& // The PropertyGroup's name context, used to scope properties and shader connections (i.e. "levelA.levelB.")
const MaterialNameContext&, // The name context defined by the PropertyGroup, used to scope the contents of the property group
const MaterialNameContext& // The name context that the PropertyGroup is in, used to scope the property group name
)>;
//! Recursively traverses all of the property groups contained in the material type, executing a callback function for each.
@ -296,7 +297,7 @@ namespace AZ
//! Return false to terminate the traversal.
using EnumeratePropertiesCallback = AZStd::function<bool(
const PropertyDefinition*, // the property definition object
const MaterialNameContext& // The property's name context, used to scope properties and shader connections (i.e. "levelA.levelB.")
const MaterialNameContext& // The name context that the property is in, used to scope properties and shader connections (i.e. "levelA.levelB.")
)>;
//! Recursively traverses all of the properties contained in the material type, executing a callback function for each.
@ -318,8 +319,8 @@ namespace AZ
PropertyDefinition* FindProperty(AZStd::span<AZStd::string_view> parsedPropertyId, AZStd::span<AZStd::unique_ptr<PropertyGroup>> inPropertyGroupList);
// Function overloads for recursion, returns false to indicate that recursion should end.
bool EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const;
bool EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const;
bool EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext nameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const;
bool EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext nameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const;
static MaterialNameContext ExtendNameContext(MaterialNameContext nameContext, const MaterialTypeSourceData::PropertyGroup& propertyGroup);

@ -377,18 +377,18 @@ namespace AZ
return parts;
}
bool MaterialTypeSourceData::EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const
bool MaterialTypeSourceData::EnumeratePropertyGroups(const EnumeratePropertyGroupsCallback& callback, MaterialNameContext nameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const
{
for (auto& propertyGroup : inPropertyGroupList)
{
MaterialNameContext materialNameContext2 = ExtendNameContext(materialNameContext, *propertyGroup);
MaterialNameContext groupNameContext = ExtendNameContext(nameContext, *propertyGroup);
if (!callback(propertyGroup.get(), materialNameContext2))
if (!callback(propertyGroup.get(), groupNameContext, nameContext))
{
return false; // Stop processing
return false; // Stop processing
}
if (!EnumeratePropertyGroups(callback, materialNameContext2, propertyGroup->m_propertyGroups))
if (!EnumeratePropertyGroups(callback, groupNameContext, propertyGroup->m_propertyGroups))
{
return false; // Stop processing
}
@ -407,21 +407,21 @@ namespace AZ
return EnumeratePropertyGroups(callback, {}, m_propertyLayout.m_propertyGroups);
}
bool MaterialTypeSourceData::EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext materialNameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const
bool MaterialTypeSourceData::EnumerateProperties(const EnumeratePropertiesCallback& callback, MaterialNameContext nameContext, const AZStd::vector<AZStd::unique_ptr<PropertyGroup>>& inPropertyGroupList) const
{
for (auto& propertyGroup : inPropertyGroupList)
{
MaterialNameContext materialNameContext2 = ExtendNameContext(materialNameContext, *propertyGroup);
MaterialNameContext groupNameContext = ExtendNameContext(nameContext, *propertyGroup);
for (auto& property : propertyGroup->m_properties)
{
if (!callback(property.get(), materialNameContext2))
if (!callback(property.get(), groupNameContext))
{
return false; // Stop processing
}
}
if (!EnumerateProperties(callback, materialNameContext2, propertyGroup->m_propertyGroups))
if (!EnumerateProperties(callback, groupNameContext, propertyGroup->m_propertyGroups))
{
return false; // Stop processing
}

@ -487,24 +487,30 @@ namespace UnitTest
struct EnumeratePropertyGroupsResult
{
const MaterialTypeSourceData::PropertyGroup* m_propertyGroup;
MaterialNameContext m_materialNameContext;
MaterialNameContext m_groupNameContext;
MaterialNameContext m_parentNameContext;
void Check(AZStd::string expectedIdContext, const MaterialTypeSourceData::PropertyGroup* expectedPropertyGroup)
{
Name groupFullId{m_propertyGroup->GetName()};
m_materialNameContext.ContextualizeProperty(groupFullId);
m_parentNameContext.ContextualizeProperty(groupFullId);
AZStd::string expectedPropertyId = expectedIdContext + expectedPropertyGroup->GetName();
EXPECT_EQ(expectedPropertyId, groupFullId.GetStringView());
EXPECT_EQ(expectedPropertyGroup, m_propertyGroup);
Name imaginaryPropertyName{"someChildProperty"};
m_groupNameContext.ContextualizeProperty(imaginaryPropertyName);
EXPECT_EQ(AZStd::string(groupFullId.GetStringView()) + ".someChildProperty", imaginaryPropertyName.GetStringView());
}
};
AZStd::vector<EnumeratePropertyGroupsResult> enumeratePropertyGroupsResults;
sourceData.EnumeratePropertyGroups([&enumeratePropertyGroupsResults](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& nameContext)
sourceData.EnumeratePropertyGroups([&enumeratePropertyGroupsResults](
const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& groupNameContext, const MaterialNameContext& parentNameContext)
{
enumeratePropertyGroupsResults.push_back(EnumeratePropertyGroupsResult{propertyGroup, nameContext});
enumeratePropertyGroupsResults.push_back(EnumeratePropertyGroupsResult{propertyGroup, groupNameContext, parentNameContext});
return true;
});

@ -783,7 +783,8 @@ namespace MaterialEditor
// Populate the property map from a combination of source data and assets
// Assets must still be used for now because they contain the final accumulated value after all other materials
// in the hierarchy are applied
m_materialTypeSourceData.EnumeratePropertyGroups([this, &parentPropertyValues](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& nameContext)
m_materialTypeSourceData.EnumeratePropertyGroups([this, &parentPropertyValues](
const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& groupNameContext, const MaterialNameContext& /*parentNameContext*/)
{
AtomToolsFramework::DynamicPropertyConfig propertyConfig;
@ -791,7 +792,7 @@ namespace MaterialEditor
{
// Assign id before conversion so it can be used in dynamic description
propertyConfig.m_id = propertyDefinition->GetName();
nameContext.ContextualizeProperty(propertyConfig.m_id);
groupNameContext.ContextualizeProperty(propertyConfig.m_id);
const auto& propertyIndex = m_materialAsset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyConfig.m_id);
const bool propertyIndexInBounds = propertyIndex.IsValid() && propertyIndex.GetIndex() < m_materialAsset->GetPropertyValues().size();
@ -905,10 +906,10 @@ namespace MaterialEditor
// Add any material functors that are located inside each property group.
bool enumerateResult = m_materialTypeSourceData.EnumeratePropertyGroups(
[this](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& nameContext)
[this](const MaterialTypeSourceData::PropertyGroup* propertyGroup, const MaterialNameContext& groupNameContext, const MaterialNameContext& /*parentNameContext*/)
{
const MaterialFunctorSourceData::EditorContext editorContext = MaterialFunctorSourceData::EditorContext(
m_materialSourceData.m_materialType, m_materialAsset->GetMaterialPropertiesLayout(), &nameContext);
m_materialSourceData.m_materialType, m_materialAsset->GetMaterialPropertiesLayout(), &groupNameContext);
for (Ptr<MaterialFunctorSourceDataHolder> functorData : propertyGroup->GetFunctors())
{

Loading…
Cancel
Save