From 3d9233f01fff211fb67668b10c3e1873ee57682f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 20 Apr 2024 02:17:40 +0200 Subject: [PATCH] Add a `get_via_group` method to `Cursor` --- scenes/game/cursor.gd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scenes/game/cursor.gd b/scenes/game/cursor.gd index 8fec76f..7a8909f 100644 --- a/scenes/game/cursor.gd +++ b/scenes/game/cursor.gd @@ -7,5 +7,12 @@ class_name Cursor @onready var game := MainGame.get_via_group(self) +static func get_via_group(node: Node) -> MainGame: + var result = node.get_tree().get_nodes_in_group("cursor") + if result.is_empty(): + return null + return result[0] + + func _physics_process(_delta: float) -> void: move_and_collide(game.camera.get_global_mouse_position() - global_position)