mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-25 01:24:23 +00:00
Refactor HoverDetector
into CursorDetector
This commit is contained in:
parent
446083dd73
commit
e2f4ad461e
6 changed files with 36 additions and 27 deletions
21
behaviours/cursor_detector.gd
Normal file
21
behaviours/cursor_detector.gd
Normal file
|
@ -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)
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
@ -3,15 +3,15 @@
|
||||||
importer="texture"
|
importer="texture"
|
||||||
type="CompressedTexture2D"
|
type="CompressedTexture2D"
|
||||||
uid="uid://6wpumqhdov4r"
|
uid="uid://6wpumqhdov4r"
|
||||||
path="res://.godot/imported/hover_detector.svg-3bfd5bde28e59dd82344da683ff70f2d.ctex"
|
path="res://.godot/imported/cursor_detector.svg-15ede4c1c6083de1d2f8a8ceb4ab532a.ctex"
|
||||||
metadata={
|
metadata={
|
||||||
"vram_texture": false
|
"vram_texture": false
|
||||||
}
|
}
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
source_file="res://behaviours/hover_detector.svg"
|
source_file="res://behaviours/cursor_detector.svg"
|
||||||
dest_files=["res://.godot/imported/hover_detector.svg-3bfd5bde28e59dd82344da683ff70f2d.ctex"]
|
dest_files=["res://.godot/imported/cursor_detector.svg-15ede4c1c6083de1d2f8a8ceb4ab532a.ctex"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
12
behaviours/cursor_detector.tscn
Normal file
12
behaviours/cursor_detector.tscn
Normal file
|
@ -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"]
|
|
@ -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
|
|
|
@ -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"]
|
|
Loading…
Reference in a new issue