Resolve PR comments. Add unit tests.
Signed-off-by: Robin <rbarrand@amazon.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <Atom/RPI.Reflect/Material/MaterialVersionUpdate.h>
|
||||
#include <Atom/RPI.Reflect/Material/MaterialAsset.h>
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
|
||||
namespace AZ
|
||||
@@ -40,16 +41,59 @@ namespace AZ
|
||||
{
|
||||
}
|
||||
|
||||
MaterialVersionUpdate::Action::Action(const AZStd::string& operation, const AZStd::initializer_list<AZStd::pair<AZStd::string, AZStd::string>>& args)
|
||||
uint32_t MaterialVersionUpdate::GetVersion() const
|
||||
{
|
||||
return m_toVersion;
|
||||
}
|
||||
|
||||
void MaterialVersionUpdate::SetVersion(uint32_t toVersion)
|
||||
{
|
||||
m_toVersion = toVersion;
|
||||
}
|
||||
|
||||
void MaterialVersionUpdate::ApplyVersionUpdates(MaterialAsset& materialAsset) const
|
||||
{
|
||||
// collect all renames within this version update
|
||||
AZStd::unordered_map<AZ::Name, AZ::Name> renameToFrom;
|
||||
for (const auto& action : m_actions)
|
||||
{
|
||||
const AZ::Name from = action.m_argsMap.find(AZ::Name{ "from" })->second;
|
||||
const AZ::Name to = action.m_argsMap.find(AZ::Name{ "to" })->second;
|
||||
|
||||
renameToFrom[from] = to;
|
||||
}
|
||||
|
||||
// apply rename actions
|
||||
for (auto& propertyName : materialAsset.m_propertyNames)
|
||||
{
|
||||
const auto toFromIterator = renameToFrom.find(propertyName);
|
||||
if (toFromIterator != renameToFrom.end())
|
||||
{
|
||||
propertyName = AZ::Name{ toFromIterator->second };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const AZ::RPI::MaterialVersionUpdate::Actions& MaterialVersionUpdate::GetActions() const
|
||||
{
|
||||
return m_actions;
|
||||
}
|
||||
|
||||
void MaterialVersionUpdate::AddAction(const Action& action)
|
||||
{
|
||||
m_actions.push_back(action);
|
||||
}
|
||||
|
||||
MaterialVersionUpdate::Action::Action(const AZ::Name& operation, const AZStd::initializer_list<AZStd::pair<AZ::Name, AZ::Name>>& args)
|
||||
: m_operation(operation)
|
||||
{
|
||||
for (const auto& arg : args)
|
||||
{
|
||||
AddArgs(arg.first, arg.second);
|
||||
AddArg(arg.first, arg.second);
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialVersionUpdate::Action::AddArgs(const AZStd::string& key, const AZStd::string& argument)
|
||||
void MaterialVersionUpdate::Action::AddArg(const AZ::Name& key, const AZ::Name& argument)
|
||||
{
|
||||
m_argsMap[key] = argument;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user