From e86ce445835fade05aeebdd27db2a1a39fb06fa4 Mon Sep 17 00:00:00 2001 From: Tiger Jove Date: Sat, 17 Jan 2026 00:34:28 +0100 Subject: [PATCH] fix: card hover transform --- src/logic-scenes/board/card.gd | 33 +++++++++++++++------------ src/logic-scenes/board/sticky-note.gd | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/logic-scenes/board/card.gd b/src/logic-scenes/board/card.gd index 5a6208b..4058922 100644 --- a/src/logic-scenes/board/card.gd +++ b/src/logic-scenes/board/card.gd @@ -217,9 +217,9 @@ func _on_mouse_entered() -> void: var sticky = get_attached_sticky_note() if sticky and sticky.highlighted: return - var parent = get_parent() - if parent and parent.has_method("handle_hover"): - parent.handle_hover(self) + var board = _get_board() + if board: + board.handle_hover(self) func _on_mouse_exited(): highlighted = false @@ -228,10 +228,10 @@ func _on_mouse_exited(): func _on_input_event(_viewport, event, _shape_idx): if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: - var parent = get_parent() - if parent and parent.has_method("handle_mouse_button") and highlighted: + var board = _get_board() + if board and highlighted: mouse_offset = get_viewport().get_mouse_position() - position - parent.handle_mouse_button(event, self) + board.handle_mouse_button(event, self) func _move_card(): if is_dragged: @@ -341,11 +341,16 @@ func get_last_exchanged_sticky() -> StickyNote: ## Cards always drop back to board dropzone func find_drop_target() -> Node: - var parent = get_parent() - # Walk up tree to find CardBoard - while parent: - if parent is CardBoard: - return parent - parent = parent.get_parent() - # Fallback to immediate parent - return get_parent() + return _get_board() + + +# === HELPER FUNCTIONS === + +## Walks up the scene tree to find the CardBoard +func _get_board() -> CardBoard: + var node = get_parent() + while node: + if node is CardBoard: + return node + node = node.get_parent() + return null diff --git a/src/logic-scenes/board/sticky-note.gd b/src/logic-scenes/board/sticky-note.gd index d694295..8d95905 100644 --- a/src/logic-scenes/board/sticky-note.gd +++ b/src/logic-scenes/board/sticky-note.gd @@ -111,7 +111,7 @@ func _process(delta: float) -> void: _move_sticky_note() func _on_mouse_entered(): - if not Input.is_action_pressed("mouse_left") and "handle_hover" in current_handle: + if not Input.is_action_pressed("mouse_left") and current_handle and current_handle.has_method("handle_hover"): current_handle.handle_hover(self) func _on_mouse_exited(): @@ -137,7 +137,7 @@ func _on_area_exit(area: Area2D): panel.collapse_gap() func _on_input_event(_viewport, event, _shape_idx): - if event is InputEventMouseButton and "handle_mouse_button" in current_handle: + if event is InputEventMouseButton and current_handle and current_handle.has_method("handle_mouse_button"): if (event.button_index == MOUSE_BUTTON_LEFT and event.pressed) or event.button_index == MOUSE_BUTTON_RIGHT: mouse_offset = get_viewport().get_mouse_position() - global_position current_handle.handle_mouse_button(event, self)