Skip to content

Commit

Permalink
test node example
Browse files Browse the repository at this point in the history
  • Loading branch information
vorlac committed Jun 8, 2024
1 parent 3d4db87 commit dde8fa7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
7 changes: 6 additions & 1 deletion project/main.tscn
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 4 additions & 0 deletions project/scripts/test.gd
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions src/api/extension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -53,6 +54,7 @@ namespace rl
godot::ClassDB::register_class<rl::Enemy>();
godot::ClassDB::register_class<rl::Player>();

godot::ClassDB::register_class<rl::Test>();
godot::ClassDB::register_class<rl::Level>();
godot::ClassDB::register_class<rl::MainDialog>();
godot::ClassDB::register_class<rl::Main>();
Expand Down
38 changes: 38 additions & 0 deletions src/test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <godot_cpp/classes/node.hpp>

#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<Test, event::signal_example>::add<double>();
}

private:
double m_signal_timer{ 0.0 };
};
}

0 comments on commit dde8fa7

Please sign in to comment.