fix: initialization caused some cards to be hard to hover

This commit is contained in:
tiger tiger tiger 2026-01-16 20:51:07 +01:00
parent de44d4aea7
commit 6e94ccc134
1 changed files with 34 additions and 0 deletions

View File

@ -407,6 +407,36 @@ func insert_area(parent: Control, node: Area2D):
node.attached_to = self
node.is_dragable = true
## Sorts all children in dropzone by their Y position
## Call this after bulk loading to fix child order / z-index issues
func _sort_dropzone_children() -> void:
var children = dropzone.get_children()
if children.size() <= 1:
return
# Sort by global Y position
children.sort_custom(func(a, b): return a.global_position.y < b.global_position.y)
# Reorder children in the scene tree
for i in range(children.size()):
dropzone.move_child(children[i], i)
print_debug("CardBoard: Re-sorted %d dropzone children by Y position" % children.size())
# Force collision shape updates on next physics frame
# This ensures Area2D hover detection works correctly after repositioning
_update_collision_shapes.call_deferred()
## Forces collision shape updates for all cards/stickies in dropzone
func _update_collision_shapes() -> void:
await get_tree().process_frame
for child in dropzone.get_children():
if child is Area2D:
# Force collision shape update by toggling monitoring
var was_monitoring = child.monitoring
child.monitoring = false
child.monitoring = was_monitoring
# === DROP TARGET PATTERN IMPLEMENTATION ===
## Checks if this board can accept the given draggable (always true for board)
@ -741,6 +771,10 @@ func initialise_from_save(savegame: SaveGame) -> void:
print_debug("CardBoard: Load complete!")
# Re-sort dropzone children now that all positions are set correctly
# This fixes hover detection issues caused by incorrect z-order during load
_sort_dropzone_children()
# Note: Lore feedback will be triggered when board is presented (in play())