/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include namespace EMotionFX { TEST_F(AnimGraphFixture, AnimGraphParameterCondition_UndoRemoveParameterTest) { AZStd::string result; AZStd::string commandString; CommandSystem::CommandManager commandManager; AnimGraphStateMachine* node1 = aznew AnimGraphStateMachine(); m_animGraph->GetRootStateMachine()->AddChildNode(node1); m_animGraph->GetRootStateMachine()->SetEntryState(node1); AnimGraphStateMachine* node2 = aznew AnimGraphStateMachine(); m_animGraph->GetRootStateMachine()->AddChildNode(node2); AnimGraphStateTransition* transition = AddTransition(node1, node2, 1.0f); AnimGraphParameterCondition* condition = aznew AnimGraphParameterCondition(); transition->AddCondition(condition); m_animGraph->InitAfterLoading(); // Add parameter to the anim graph and the instance. const AZStd::string parameterName = "Parameter1"; { AZStd::unique_ptr newParameter(EMotionFX::ParameterFactory::Create(azrtti_typeid())); newParameter->SetName(parameterName); CommandSystem::ConstructCreateParameterCommand(commandString, m_animGraph.get(), newParameter.get(), MCORE_INVALIDINDEX32); EXPECT_TRUE(commandManager.ExecuteCommand(commandString, result)) << result.c_str(); } condition->SetParameterName(parameterName); // 1. Remove the parameter including unlinking it from the parameter condition. MCore::CommandGroup commandGroup; CommandSystem::BuildRemoveParametersCommandGroup(m_animGraph.get(), /*parameterNamesToBeRemoved=*/{ parameterName }, &commandGroup); EXPECT_TRUE(commandManager.ExecuteCommandGroup(commandGroup, result)) << result.c_str(); EXPECT_EQ(m_animGraph->GetNumParameters(), 0) << "The parameter should not be present anymore."; EXPECT_EQ(condition->GetParameterName(), "") << "The condition should not be linked to the removed parameter anymore."; // 2. Undo. EXPECT_TRUE(commandManager.Undo(result)) << result.c_str(); EXPECT_EQ(m_animGraph->GetNumParameters(), 1) << "The parameter should be back again."; condition = azdynamic_cast(transition->GetCondition(0)); EXPECT_EQ(condition->GetParameterName(), parameterName) << "The condition should be linked to the parameter again."; // 3. Redo. EXPECT_TRUE(commandManager.Redo(result)) << result.c_str(); condition = azdynamic_cast(transition->GetCondition(0)); EXPECT_EQ(m_animGraph->GetNumParameters(), 0) << "The parameter should not be present anymore."; EXPECT_EQ(condition->GetParameterName(), "") << "The condition should not be linked to the removed parameter anymore."; } } // namespace EMotionFX