diff --git a/behaviours/cursor_detector.gd b/behaviours/cursor_detector.gd new file mode 100644 index 0000000..367acb4 --- /dev/null +++ b/behaviours/cursor_detector.gd @@ -0,0 +1,21 @@ +@icon("res://behaviours/cursor_detector.svg") +extends Area2D +class_name CursorDetector + + +signal cursor_entered(cursor: Cursor) +signal cursor_exited(cursor: Cursor) + + +var mouse_inside = false + + +func _on_body_entered(body: Node2D) -> void: + if body is Cursor: + mouse_inside = true + cursor_entered.emit(body) + +func _on_body_exited(body: Node2D) -> void: + if body is Cursor: + mouse_inside = true + cursor_exited.emit(body) diff --git a/behaviours/hover_detector.svg b/behaviours/cursor_detector.svg similarity index 100% rename from behaviours/hover_detector.svg rename to behaviours/cursor_detector.svg diff --git a/behaviours/hover_detector.svg.import b/behaviours/cursor_detector.svg.import similarity index 73% rename from behaviours/hover_detector.svg.import rename to behaviours/cursor_detector.svg.import index b27371a..5467a48 100644 --- a/behaviours/hover_detector.svg.import +++ b/behaviours/cursor_detector.svg.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://6wpumqhdov4r" -path="res://.godot/imported/hover_detector.svg-3bfd5bde28e59dd82344da683ff70f2d.ctex" +path="res://.godot/imported/cursor_detector.svg-15ede4c1c6083de1d2f8a8ceb4ab532a.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://behaviours/hover_detector.svg" -dest_files=["res://.godot/imported/hover_detector.svg-3bfd5bde28e59dd82344da683ff70f2d.ctex"] +source_file="res://behaviours/cursor_detector.svg" +dest_files=["res://.godot/imported/cursor_detector.svg-15ede4c1c6083de1d2f8a8ceb4ab532a.ctex"] [params] diff --git a/behaviours/cursor_detector.tscn b/behaviours/cursor_detector.tscn new file mode 100644 index 0000000..c4b4fec --- /dev/null +++ b/behaviours/cursor_detector.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=3 uid="uid://cbg5kgwxusvxf"] + +[ext_resource type="Script" path="res://behaviours/cursor_detector.gd" id="1_4hcxj"] + +[node name="CursorDetector" type="Area2D"] +collision_layer = 0 +collision_mask = 64 +monitorable = false +script = ExtResource("1_4hcxj") + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] +[connection signal="body_exited" from="." to="." method="_on_body_exited"] diff --git a/behaviours/hover_detector.gd b/behaviours/hover_detector.gd deleted file mode 100644 index 616e72a..0000000 --- a/behaviours/hover_detector.gd +++ /dev/null @@ -1,13 +0,0 @@ -@icon("res://behaviours/hover_detector.svg") -extends Area2D -class_name HoverDetector - - -var mouse_inside = false - - -func _on_mouse_entered() -> void: - mouse_inside = true - -func _on_mouse_exited() -> void: - mouse_inside = false diff --git a/behaviours/hover_detector.tscn b/behaviours/hover_detector.tscn deleted file mode 100644 index b6800b0..0000000 --- a/behaviours/hover_detector.tscn +++ /dev/null @@ -1,11 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://cbg5kgwxusvxf"] - -[ext_resource type="Script" path="res://behaviours/hover_detector.gd" id="1_51m5p"] - -[node name="HoverDetector" type="Area2D"] -collision_mask = 0 -monitorable = false -script = ExtResource("1_51m5p") - -[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] -[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]