diff --git a/SHADE_Engine/src/Animation/SHAnimationController.cpp b/SHADE_Engine/src/Animation/SHAnimationController.cpp index ef15f223..2347ca6e 100644 --- a/SHADE_Engine/src/Animation/SHAnimationController.cpp +++ b/SHADE_Engine/src/Animation/SHAnimationController.cpp @@ -192,6 +192,20 @@ namespace SHADE parameters.erase(name); } + void SHAnimationController::SetTrigger(InstanceData& instData, const std::string& paramName) + { + // Invalid param + if (!parameters.contains(paramName)) + return; + + // Not a trigger + if (parameters[paramName] != AnimParam::Type::Trigger) + return; + + // Set the flag + instData.Params[paramName].Value = true; + } + /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Animation/SHAnimationController.h b/SHADE_Engine/src/Animation/SHAnimationController.h index 7708d0c9..e593bc63 100644 --- a/SHADE_Engine/src/Animation/SHAnimationController.h +++ b/SHADE_Engine/src/Animation/SHAnimationController.h @@ -14,6 +14,7 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include #include +#include // Project Includes #include "SH_API.h" #include "Resource/SHHandle.h" @@ -191,7 +192,37 @@ namespace SHADE /// /// Name of the parameter. void RemoveParameter(const std::string& name); - void SetStartingNode(Handle node); + /// + /// Sets the parameter of the for the string. Does nothing if an invalid param name + /// is provided. Type of the parameter is not checked. + /// + /// + /// Type of parameter. Only bool, int, floats are supported. + /// + /// Data of the instance to update. + /// Name of the parameter. + /// Value to set the parameter to. + template + void SetParameter(InstanceData& instData, const std::string& paramName, T value); + /// + /// Gets the parameter of the for the string. Types are checked and will not return + /// a value if there is nothing. + /// + /// + /// Type of parameter. Only bool, int, floats are supported. + /// + /// Data of the instance to update. + /// Name of the parameter. + /// The value of the parameter or nothing if invalid. + template + std::optional GetParameter(InstanceData& instData, const std::string& paramName); + /// + /// Sets the flag for a trigger parameter. Does nothing if an invalid param name is + /// provided or if the param name refers to a parameter that is not a trigger. + /// + /// Data of the instance to update. + /// Name of the parameter. + void SetTrigger(InstanceData& instData, const std::string& paramName); /*---------------------------------------------------------------------------------*/ /* Getters */ diff --git a/SHADE_Engine/src/Animation/SHAnimationController.hpp b/SHADE_Engine/src/Animation/SHAnimationController.hpp index f040b8d4..98fa35e6 100644 --- a/SHADE_Engine/src/Animation/SHAnimationController.hpp +++ b/SHADE_Engine/src/Animation/SHAnimationController.hpp @@ -66,4 +66,55 @@ namespace SHADE // Neither of the existing cases return false; } + + template + void SHAnimationController::SetParameter(InstanceData& instData, const std::string& paramName, T value) + { + static_assert(std::is_same_v || std::is_same_v || std::is_same_v, "Only works with bool, float or ints."); + + // Invalid param + if (!parameters.contains(paramName)) + return; + + // Set the value + instData.Params[paramName].Value = value; + } + + template + std::optional SHAnimationController::GetParameter(InstanceData& instData, const std::string& paramName) + { + static_assert(std::is_same_v || std::is_same_v || std::is_same_v, "Only works with bool, float or ints."); + + // Invalid param + if (!parameters.contains(paramName)) + return {}; + + // Check if the type matches + const auto TYPE = parameters[paramName]; + if constexpr (std::is_same_v) + { + if (TYPE != AnimParam::Type::Bool && TYPE != AnimParam::Type::Trigger) + return {}; + } + else if constexpr (std::is_same_v) + { + if (parameters[paramName] != AnimParam::Type::Float) + return {}; + } + else if constexpr (std::is_same_v) + { + if (parameters[paramName] != AnimParam::Type::Int) + return {}; + } + + // Return the correct value + if (instData.Params.contains(paramName)) + { + return instData.Params[paramName]; + } + else + { + return T(); // Default constructed value + } + } } \ No newline at end of file diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp index 0059d721..71ae4e03 100644 --- a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp +++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp @@ -199,6 +199,14 @@ namespace SHADE } } + void SHAnimatorComponent::SetTrigger(const std::string& paramName) + { + if (!animController) + return; + + return animController->SetTrigger(animInstanceData, paramName); + } + /*-----------------------------------------------------------------------------------*/ /* Helper Functions - Loading */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.h b/SHADE_Engine/src/Animation/SHAnimatorComponent.h index d4af2c2b..8beef34c 100644 --- a/SHADE_Engine/src/Animation/SHAnimatorComponent.h +++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.h @@ -95,7 +95,42 @@ namespace SHADE /// /// Rig to use. void SetRig(Handle newRig); + /// + /// Sets the animation controller to use for this animator. + /// + /// Animation controller to use. void SetAnimationController(Handle ac); + /// + /// Sets the parameter of the for the string. Does nothing if an invalid param name + /// is provided. Type of the parameter is not checked. Also does nothing if no + /// animation controller is specified. + /// + /// + /// Type of parameter. Only bool, int, floats are supported. + /// + /// Name of the parameter. + /// Value to set the parameter to. + template + void SetParameter(const std::string& paramName, T value); + /// + /// Gets the parameter of the for the string. Types are checked and will not return + /// a value if there is nothing. Returns nothing if there is no animation controller + /// specified either. + /// + /// + /// Type of parameter. Only bool, int, floats are supported. + /// + /// Name of the parameter. + /// The value of the parameter or nothing if invalid. + template + std::optional GetParameter(const std::string& paramName); + /// + /// Sets the flag for a trigger parameter. Does nothing if an invalid param name is + /// provided or if the param name refers to a parameter that is not a trigger. + /// + /// Data of the instance to . + /// Name of the parameter. + void SetTrigger(const std::string& paramName); /*---------------------------------------------------------------------------------*/ /* Getter Functions */ diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp b/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp index e8c52073..ec64bc6e 100644 --- a/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp +++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.hpp @@ -22,6 +22,26 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { + /*-----------------------------------------------------------------------------------*/ + /* Setter Functions */ + /*-----------------------------------------------------------------------------------*/ + template + std::optional SHAnimatorComponent::GetParameter(const std::string& paramName) + { + if (!animController) + return; + + return animController->GetParameter(paramName); + } + template + void SHAnimatorComponent::SetParameter(const std::string& paramName, T value) + { + if (!animController) + return; + + return animController->SetParameter(paramName, value); + } + /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/