diff --git a/src/register_types.cpp b/src/register_types.cpp index 21eaa9e..bafef4b 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -12,6 +12,7 @@ #include "camera_effects.hpp" #include "camera_effect_source.hpp" #include "artillery_target.hpp" +#include "section_activator.hpp" using namespace godot; @@ -28,6 +29,7 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level) GDREGISTER_CLASS(CameraEffects); GDREGISTER_RUNTIME_CLASS(CameraEffectSource); GDREGISTER_RUNTIME_CLASS(ArtilleryTarget); + GDREGISTER_RUNTIME_CLASS(SectionActivator); } extern "C" diff --git a/src/section_activator.cpp b/src/section_activator.cpp new file mode 100644 index 0000000..eb9325f --- /dev/null +++ b/src/section_activator.cpp @@ -0,0 +1,26 @@ +#include "section_activator.hpp" +#include "player.hpp" + +void SectionActivator::_bind_methods() { +} + +void SectionActivator::_enter_tree() { + this->connect("body_entered", callable_mp(this, &SectionActivator::_on_body_entered)); + this->connect("body_exited", callable_mp(this, &SectionActivator::_on_body_exited)); + this->set_visible(false); + this->set_process(false); +} + +void SectionActivator::_on_body_entered(gd::Node *node) { + if(gd::Object::cast_to(node)) { + this->set_visible(true); + this->set_process(false); + } +} + +void SectionActivator::_on_body_exited(gd::Node *node) { + if(gd::Object::cast_to(node)) { + this->set_visible(false); + this->set_process(false); + } +} diff --git a/src/section_activator.hpp b/src/section_activator.hpp new file mode 100644 index 0000000..9536f82 --- /dev/null +++ b/src/section_activator.hpp @@ -0,0 +1,16 @@ +#ifndef SECTION_ACTIVATOR_HPP +#define SECTION_ACTIVATOR_HPP + +#include +namespace gd = godot; + +class SectionActivator : public gd::Area3D { + GDCLASS(SectionActivator, gd::Area3D); + static void _bind_methods(); +public: + virtual void _enter_tree() override; + void _on_body_entered(gd::Node *node); + void _on_body_exited(gd::Node *node); +}; + +#endif // !SECTION_ACTIVATOR_HPP