goodnight_jellybean/godot/CursorInteractArea.gd

36 lines
904 B
GDScript3
Raw Normal View History

2022-12-31 01:19:40 -07:00
extends Area
export var on_interact_func = ""
export var on_enter_func = ""
export var on_leave_func = ""
2023-01-01 02:23:56 -07:00
export var call_string = ""
2022-12-31 01:19:40 -07:00
var cursor_is_touching = false
func _ready():
var _err = GlobalCursorState.connect("cursor_interact", self, "check_interact")
2023-01-01 02:23:56 -07:00
func call_with_value(func_name: String):
if call_string:
GlobalCursorState.call(func_name, call_string)
else:
GlobalCursorState.call(func_name)
2022-12-31 01:19:40 -07:00
func check_interact():
if cursor_is_touching and on_interact_func:
2023-01-01 02:23:56 -07:00
call_with_value(on_interact_func)
2022-12-31 01:19:40 -07:00
func _on_CursorInteractArea_body_entered(body):
if not GlobalCursorState.is_cursor_collision(body):
return
cursor_is_touching = true
if on_enter_func:
2023-01-01 02:23:56 -07:00
call_with_value(on_enter_func)
2022-12-31 01:19:40 -07:00
func _on_CursorInteractArea_body_exited(body):
if not GlobalCursorState.is_cursor_collision(body):
return
cursor_is_touching = false
if on_leave_func:
2023-01-01 02:23:56 -07:00
call_with_value(on_leave_func)