From dde8fa731bf367dcde9323e127f4d80535e751ce Mon Sep 17 00:00:00 2001 From: sal Date: Sat, 8 Jun 2024 16:38:57 -0400 Subject: [PATCH] test node example --- project/main.tscn | 7 +++++- project/scripts/test.gd | 4 ++++ src/api/extension_interface.cpp | 2 ++ src/test.hpp | 38 +++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 project/scripts/test.gd create mode 100644 src/test.hpp diff --git a/project/main.tscn b/project/main.tscn index 8869254..5a1cf5a 100644 --- a/project/main.tscn +++ b/project/main.tscn @@ -1,8 +1,13 @@ -[gd_scene load_steps=2 format=3 uid="uid://be6f0odpenf2d"] +[gd_scene load_steps=3 format=3 uid="uid://be6f0odpenf2d"] [ext_resource type="Script" path="res://scripts/main.gd" id="1_c2d3a"] +[ext_resource type="Script" path="res://scripts/test.gd" id="2_ccrxe"] [node name="Main" type="Main"] script = ExtResource("1_c2d3a") +[node name="Test" type="Test" parent="."] +script = ExtResource("2_ccrxe") + [connection signal="custom_signal_example" from="." to="." method="_on_custom_signal_example"] +[connection signal="custom_signal_example" from="Test" to="Test" method="_on_test_custom_signal_example"] diff --git a/project/scripts/test.gd b/project/scripts/test.gd new file mode 100644 index 0000000..48e36f1 --- /dev/null +++ b/project/scripts/test.gd @@ -0,0 +1,4 @@ +extends Test + +func _on_test_custom_signal_example(delta_time): + print("DeltaTime value sent from C++ to TEST::GDScript: ", delta_time) diff --git a/src/api/extension_interface.cpp b/src/api/extension_interface.cpp index 3075fe2..a749b82 100644 --- a/src/api/extension_interface.cpp +++ b/src/api/extension_interface.cpp @@ -17,6 +17,7 @@ #include "entity/projectile/projectile_spawner.hpp" #include "main.hpp" #include "singletons/console.hpp" +#include "test.hpp" #include "ui/main_dialog.hpp" #include "util/engine.hpp" @@ -53,6 +54,7 @@ namespace rl godot::ClassDB::register_class(); godot::ClassDB::register_class(); + godot::ClassDB::register_class(); godot::ClassDB::register_class(); godot::ClassDB::register_class(); godot::ClassDB::register_class(); diff --git a/src/test.hpp b/src/test.hpp new file mode 100644 index 0000000..7a82584 --- /dev/null +++ b/src/test.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include "util/engine.hpp" + +namespace rl +{ + class Test : public godot::Node + { + GDCLASS(Test, godot::Node); + + public: + Test() = default; + + void _physics_process(double delta) override + { + if (engine::editor_active()) + return; + + m_signal_timer += delta; + if (m_signal_timer > 1.0) + { + this->emit_signal(event::signal_example, delta); + m_signal_timer -= 1.0; + } + } + + protected: + static void _bind_methods() + { + signal_binding::add(); + } + + private: + double m_signal_timer{ 0.0 }; + }; +}