1
Fork 0
mirror of https://github.com/Steffo99/hella-farm.git synced 2024-11-25 09:34:24 +00:00
hella-farm/behaviours/draggable.gd

44 lines
807 B
GDScript3
Raw Permalink Normal View History

extends Area2D
class_name Draggable
signal move(movement: Vector2)
signal dragged
signal dropped
2024-04-15 23:00:49 +00:00
@export var state_holder: StateHolder
@onready var mover: Node2D = $"MatchMousePosition"
2024-04-15 23:00:49 +00:00
var is_being_dragged: bool:
get:
2024-04-15 23:00:49 +00:00
return state_holder.state == 'dragged'
func drag():
2024-04-15 23:00:49 +00:00
if not state_holder.propose_state('dragged', 100, _on_dropped):
return false
_update_mover_process()
dragged.emit()
func drop():
2024-04-15 23:00:49 +00:00
state_holder.remove_state('dragged')
func _on_dropped():
dropped.emit()
2024-04-15 23:00:49 +00:00
func _update_mover_process():
var value = is_being_dragged
mover.set_process(value)
mover.set_physics_process(value)
func _ready():
2024-04-15 23:00:49 +00:00
if state_holder == null:
state_holder = StateHolder.get_default(self)
_update_mover_process()
func _on_move(movement: Vector2):
2024-04-15 23:00:49 +00:00
if is_being_dragged:
move.emit(movement)