Dragged threads snap to an input dot within 24 screen px and highlight it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
tachyonwolf 2026-11-21 08:57:42 -06:00
parent f87aa00795
commit 54eb5d1af2
3 changed files with 19 additions and 3 deletions

View file

@ -198,6 +198,8 @@ func start_link(tid: String, eid: String) -> void:
editing.start_link(tid, eid) editing.start_link(tid, eid)
func update_link() -> void: func update_link() -> void:
editing.update_link() editing.update_link()
func link_snap_point() -> Variant:
return editing.link_snap_point()
func finish_link() -> void: func finish_link() -> void:
editing.finish_link() editing.finish_link()
func is_selected(tid: String) -> bool: func is_selected(tid: String) -> bool:

View file

@ -30,7 +30,7 @@ const ADD_KINDS := [
const MENU_FROM_TEMPLATE := 100 const MENU_FROM_TEMPLATE := 100
const MENU_GROUP := 101 const MENU_GROUP := 101
## How close (screen pixels) a dragged thread must be to a card's input dot to drop on it. ## How close (screen pixels) a dragged thread must be to a card's input dot to drop on it.
const LINK_DROP_RADIUS := 10.0 const LINK_DROP_RADIUS := 24.0
const MENU_SAVE_SELECTION := 102 const MENU_SAVE_SELECTION := 102
@ -258,6 +258,16 @@ func update_link() -> void:
_drop_card.set_drop_target(true) _drop_card.set_drop_target(true)
## The input dot a dragged thread would land on if dropped now, or null when
## the mouse is not within LINK_DROP_RADIUS of one (the preview snaps to it).
func link_snap_point() -> Variant:
var card := _card_under_mouse()
if card == null or card.table.kind == RollTable.KIND_VARIABLE:
return null
var mouse := m.board.world.get_local_mouse_position()
return card.inlet_point() if card.inlet_point().distance_to(mouse) <= LINK_DROP_RADIUS / m.board.zoom else null
func finish_link() -> void: func finish_link() -> void:
var over := _card_under_mouse() var over := _card_under_mouse()
if is_instance_valid(_drop_card): if is_instance_valid(_drop_card):

View file

@ -79,7 +79,10 @@ func _draw() -> void:
var below := card.get_index() var below := card.get_index()
# Variable cards are never rolled, so nothing pipes into them. # Variable cards are never rolled, so nothing pipes into them.
if t.kind != RollTable.KIND_VARIABLE and not _covered(card.inlet_point(), below): if t.kind != RollTable.KIND_VARIABLE and not _covered(card.inlet_point(), below):
_port(card.inlet_point(), Style.THREAD, Style.THREAD_DARK, 1.0) if _linking and _ghost_to == card.inlet_point():
_port(card.inlet_point(), Style.ACCENT, Style.ACCENT_DARK, 1.4) # the drop will land here
else:
_port(card.inlet_point(), Style.THREAD, Style.THREAD_DARK, 1.0)
for e in t.entries: for e in t.entries:
if not card.rows.has(e.id): if not card.rows.has(e.id):
continue continue
@ -204,6 +207,7 @@ func _gui_input(ev: InputEvent) -> void:
return return
var mm := ev as InputEventMouseMotion var mm := ev as InputEventMouseMotion
if mm and _linking: if mm and _linking:
_ghost_to = mm.position
main.update_link() main.update_link()
var snap: Variant = main.link_snap_point()
_ghost_to = snap if snap != null else mm.position
accept_event() accept_event()