mirror of
https://github.com/Steffo99/hella-farm.git
synced 2024-11-24 17:14:23 +00:00
Import things from CursorMagnet
into Cursor
This commit is contained in:
parent
6d30d123d6
commit
466a263c41
1 changed files with 27 additions and 0 deletions
|
@ -10,6 +10,8 @@ signal dropped(node: Draggable)
|
||||||
|
|
||||||
@onready var game := MainGame.get_via_group(self)
|
@onready var game := MainGame.get_via_group(self)
|
||||||
|
|
||||||
|
var dragging: Draggable = null
|
||||||
|
|
||||||
|
|
||||||
static func get_via_group(node: Node) -> MainGame:
|
static func get_via_group(node: Node) -> MainGame:
|
||||||
var result = node.get_tree().get_nodes_in_group("cursor")
|
var result = node.get_tree().get_nodes_in_group("cursor")
|
||||||
|
@ -30,6 +32,31 @@ func find_closest_target() -> Draggable:
|
||||||
to_drag = target
|
to_drag = target
|
||||||
return to_drag
|
return to_drag
|
||||||
|
|
||||||
|
func drag():
|
||||||
|
var target = find_closest_target()
|
||||||
|
if target and not dragging:
|
||||||
|
dragging = target
|
||||||
|
target.drag()
|
||||||
|
dragged.emit(target)
|
||||||
|
|
||||||
|
func drop():
|
||||||
|
if dragging:
|
||||||
|
var target = dragging
|
||||||
|
dragging = null
|
||||||
|
target.drop()
|
||||||
|
dropped.emit(target)
|
||||||
|
|
||||||
|
func log_dragging() -> void:
|
||||||
|
Log.p(self, "Dragging: %s" % dragging)
|
||||||
|
|
||||||
|
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
|
if event.pressed:
|
||||||
|
drag()
|
||||||
|
else:
|
||||||
|
drop()
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
func _physics_process(_delta: float) -> void:
|
||||||
position += (game.camera.get_global_mouse_position() - global_position)
|
position += (game.camera.get_global_mouse_position() - global_position)
|
||||||
|
|
Loading…
Reference in a new issue