/* * 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 #include namespace EMotionFX { TEST_F(AnimGraphFixture, AnimGraphVector2Condition_MoveParameterTest) { 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); AnimGraphVector2Condition* condition = aznew AnimGraphVector2Condition(); transition->AddCondition(condition); m_animGraph->InitAfterLoading(); // Add float slider parameter. { AZStd::unique_ptr newParameter(EMotionFX::ParameterFactory::Create(azrtti_typeid())); newParameter->SetName("Float Slider Parameter"); CommandSystem::ConstructCreateParameterCommand(commandString, m_animGraph.get(), newParameter.get(), MCORE_INVALIDINDEX32); EXPECT_TRUE(commandManager.ExecuteCommand(commandString, result)) << result.c_str(); } // Add Vector2 parameter. const AZStd::string parameterName = "Vector2 Parameter"; { 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); condition->Reinit(); AZ::Outcome parameterIndex = m_animGraph->FindValueParameterIndexByName(parameterName); EXPECT_TRUE(parameterIndex.IsSuccess() && parameterIndex.GetValue() == 1) << "The Vector2 parameter should be at the 2nd position."; // 1. Move the Vector2 parameter from the 2nd place to the 1st place. commandString = AZStd::string::format("AnimGraphMoveParameter -animGraphID %d -name \"%s\" -index %d ", m_animGraph->GetID(), parameterName.c_str(), 0); EXPECT_TRUE(commandManager.ExecuteCommand(commandString, result)) << result.c_str(); parameterIndex = m_animGraph->FindValueParameterIndexByName(parameterName); EXPECT_TRUE(parameterIndex.IsSuccess() && parameterIndex.GetValue() == 0) << "The Vector2 parameter should now be at the 1st position."; EXPECT_EQ(parameterIndex.GetValue(), condition->GetParameterIndex().GetValue()) << "The Vector2 condition should now refer to the 1st parameter in the anim graph."; // 2. Undo. EXPECT_TRUE(commandManager.Undo(result)) << result.c_str(); parameterIndex = m_animGraph->FindValueParameterIndexByName(parameterName); EXPECT_TRUE(parameterIndex.IsSuccess() && parameterIndex.GetValue() == 1) << "The Vector2 parameter should now be back at the 2nd position."; EXPECT_EQ(parameterIndex.GetValue(), condition->GetParameterIndex().GetValue()) << "The Vector2 condition should now refer to the 2nd parameter in the anim graph."; // 3. Redo. EXPECT_TRUE(commandManager.Redo(result)) << result.c_str(); parameterIndex = m_animGraph->FindValueParameterIndexByName(parameterName); EXPECT_TRUE(parameterIndex.IsSuccess() && parameterIndex.GetValue() == 0) << "The Vector2 parameter should now be back at the 1st position."; EXPECT_EQ(parameterIndex.GetValue(), condition->GetParameterIndex().GetValue()) << "The Vector2 condition should now refer to the 1st parameter in the anim graph."; } } // namespace EMotionFX