diff --git a/SHADE_Engine/src/Animation/SHAnimationController.cpp b/SHADE_Engine/src/Animation/SHAnimationController.cpp index b3105e64..3a1f581e 100644 --- a/SHADE_Engine/src/Animation/SHAnimationController.cpp +++ b/SHADE_Engine/src/Animation/SHAnimationController.cpp @@ -154,6 +154,56 @@ namespace SHADE node.Free(); } + void SHAnimationController::AddTransition(Handle source, const Transition& transition) + { + if (!source) + { + SHLOG_ERROR("[SHAnimationController] Attempted to add transition from an invalid node."); + return; + } + + if (!transition.Target) + { + SHLOG_ERROR("[SHAnimationController] Attempted to add transition to an invalid node."); + return; + } + + if (transition.Condition != Transition::ConditionType::None && !parameters.contains(transition.ParamName)) + { + SHLOG_ERROR("[SHAnimationController] Attempted to add a conditional transition for an invalid parameter."); + return; + } + + source->Transitions.emplace_back(transition); + } + void SHAnimationController::AddParameter(const std::string& name, AnimParam::Type type) + { + if (name.empty()) + { + SHLOG_ERROR("[SHAnimationController] Attempted to add a parameter with no name."); + return; + } + + if (parameters.contains(name)) + { + SHLOG_ERROR("[SHAnimationController] Attempted to add a parameter with the same name."); + return; + } + + // Insert + parameters.emplace(name, type); + } + void SHAnimationController::RemoveParameter(const std::string& name) + { + if (!parameters.contains(name)) + { + SHLOG_ERROR("[SHAnimationController] Attempted to reemove a parameter that does not exist."); + return; + } + + parameters.erase(name); + } + /*-----------------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Animation/SHAnimationController.h b/SHADE_Engine/src/Animation/SHAnimationController.h index 2aa46f3c..90162422 100644 --- a/SHADE_Engine/src/Animation/SHAnimationController.h +++ b/SHADE_Engine/src/Animation/SHAnimationController.h @@ -167,8 +167,24 @@ namespace SHADE /// /// Node to destroy. void DestroyNode(Handle node); + /// + /// Links two nodes together with a Transition. This performs some additional + /// checking to ensure parameters are valid. + /// + /// Source node to transition from. + /// Describes the transition to add. void AddTransition(Handle source, const Transition& transition); + /// + /// Registers a parameter to the animation controller. + /// + /// Name of the parameter. + /// Type of the parameter. void AddParameter(const std::string& name, AnimParam::Type type); + /// + /// Removes a parameter from the animation controller. + /// + /// Name of the parameter. + void RemoveParameter(const std::string& name); /*---------------------------------------------------------------------------------*/ /* Getters */