From c1b676f3353d8ee9b166fa747be8cd8d8aea2469 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 2 Sep 2024 21:29:26 +0200 Subject: [PATCH] feat: animation/activate actions use scene unique names now --- src/rts_states.cpp | 17 +++++++++++++++-- src/rts_states.hpp | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/rts_states.cpp b/src/rts_states.cpp index 2987385..1ac95ce 100644 --- a/src/rts_states.cpp +++ b/src/rts_states.cpp @@ -72,13 +72,26 @@ double MoveTo::get_repath_interval() const { void Activate::_bind_methods() {} +void Activate::_ready() { + this->anim = this->get_parent()->get_node("%AnimationPlayer"); + if(!this->anim->has_animation(this->animation)) + this->end_state(); + else this->anim->play(this->animation); +} + +void Activate::_process(double) { + bool const animation_finished{!this->anim->is_playing() || this->anim->get_current_animation() != this->animation}; + if(this->is_action_done_interrupt() || animation_finished) + this->end_state(); +} + void Animate::_bind_methods() {} void Animate::_ready() { - this->anim = this->get_node("../AnimationPlayer"); - this->anim->play(this->animation); + this->anim = this->get_parent()->get_node("%AnimationPlayer"); if(!this->anim->has_animation(this->animation)) this->end_state(); + else this->anim->play(this->animation); } void Animate::_process(double) { diff --git a/src/rts_states.hpp b/src/rts_states.hpp index b1f444a..48049f6 100644 --- a/src/rts_states.hpp +++ b/src/rts_states.hpp @@ -34,8 +34,12 @@ class Activate : public goap::State { GDCLASS(Activate, goap::State); static void _bind_methods(); public: + virtual void _ready() override; + virtual void _process(double) override; gd::Node3D *target_node{nullptr}; gd::String animation{}; +private: + gd::AnimationPlayer *anim{nullptr}; }; class Animate : public goap::State {