fix: board dead code removed, cards can now be dragged again

This commit is contained in:
tiger tiger tiger 2026-01-16 14:09:07 +01:00
parent 7b327c47f6
commit ce845b7be6
4 changed files with 32 additions and 153 deletions

View File

@ -1,14 +1,6 @@
class_name CardBoard extends PanelContainer class_name CardBoard extends PanelContainer
enum {NAVIGATE, ASSIGN, DRAG} enum {NAVIGATE, ASSIGN, DRAG}
enum Error {
OK,
OUT_OF_BOUNDS,
ILLEGAL_STATE,
MISSING
}
const is_board := true
var focus_stickies:bool = true: var focus_stickies:bool = true:
set(stickies): set(stickies):
@ -26,25 +18,17 @@ var focus_stickies:bool = true:
current_dropzone_id = current_dropzone_id current_dropzone_id = current_dropzone_id
var focused := false: var focused := false:
set(focus): set(value):
if focused == value:
return
var was_focused := focused var was_focused := focused
if focus: focused = value
focused = true
get_tree().call_group("interactables", "collapse") if focused:
current_dropzone_id = 0 _on_board_focused()
current_sticky_note_id = 0
focus_stickies = true
else: else:
focused = false _on_board_unfocused()
if is_node_ready():
if focus:
process_mode = Node.PROCESS_MODE_INHERIT
else:
process_mode = Node.PROCESS_MODE_DISABLED
for sticky in dropzone.get_children():
if sticky is StickyNote:
sticky.is_dragged = false
visible = focused
# Emit closed signal when transitioning from focused to unfocused # Emit closed signal when transitioning from focused to unfocused
if was_focused and not focused: if was_focused and not focused:
closed.emit() closed.emit()
@ -56,18 +40,8 @@ var dropzone_size: Vector2
@onready var sticky_note_container := $HBoxContainer/ScrollContainer/VBoxContainer @onready var sticky_note_container := $HBoxContainer/ScrollContainer/VBoxContainer
@onready var current_context:int = NAVIGATE: @onready var current_context:int = NAVIGATE:
set(context): set(context):
#if current_context == ASSIGN and !context == ASSIGN:
# sticky_note_container.get_child(current_sticky_note_id).clear_if_empty()
#match context:
# NAVIGATE:
# _return_sticky_notes_to_panels()
# DRAG:
# pass
# ASSIGN:
# pass
current_context = context current_context = context
@onready var instructions := $instructions_panel/HBoxContainer/cards_remaining @onready var instructions := $instructions_panel/HBoxContainer/cards_remaining
@onready var timer := $Timer
var mementos_collected: int = 0: var mementos_collected: int = 0:
set(mementos): set(mementos):
@ -131,8 +105,7 @@ var mementos_collected: int = 0:
if sticky_note_container.get_child(i).get_child_count() == 1: if sticky_note_container.get_child(i).get_child_count() == 1:
currently_active_node = sticky_note_container.get_child(i).get_child(0) currently_active_node = sticky_note_container.get_child(i).get_child(0)
var last_save_dict: Dictionary
var text_recovery: Dictionary
signal board_completed signal board_completed
signal closed signal closed
@ -152,27 +125,35 @@ func _ready():
populate_board(["c_comic_heroes", 'c_teasing', "p_agent_q", "p_good_intended"]) populate_board(["c_comic_heroes", 'c_teasing', "p_agent_q", "p_good_intended"])
populate_board(["c_out_of_world", 'c_confusion', "p_outer_conflict", "p_unique"]) populate_board(["c_out_of_world", 'c_confusion', "p_outer_conflict", "p_unique"])
focused = focused
get_viewport().gui_focus_changed.connect(reclaim_lost_focus) get_viewport().gui_focus_changed.connect(reclaim_lost_focus)
#FIXME properly implement board recovery
#timer.timeout.connect(validate_board)
#timer.start()
#await get_tree().process_frame ## Called when board receives focus
#last_save_dict = get_save_dict() func _on_board_focused() -> void:
get_tree().call_group("interactables", "collapse")
current_dropzone_id = 0
current_sticky_note_id = 0
focus_stickies = true
visible = true
if is_node_ready():
process_mode = Node.PROCESS_MODE_INHERIT
## Called when board loses focus
func _on_board_unfocused() -> void:
visible = false
if is_node_ready():
process_mode = Node.PROCESS_MODE_DISABLED
# Stop any active dragging
for sticky in dropzone.get_children():
if sticky is StickyNote:
sticky.is_dragged = false
func reclaim_lost_focus(_thief): func reclaim_lost_focus(_thief):
if focused: if focused:
grab_focus() grab_focus()
#func _process(delta):
# # drops dragged area when Mouse is no longer pressed.
# if focused and !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and current_context == DRAG:
# currently_active_node.is_dragged = false
## Will be used later to spawn Cards and Post-Its and remember them in the dictionary ## Will be used later to spawn Cards and Post-Its and remember them in the dictionary
func populate_board(card_names: Array[StringName]): func populate_board(card_names: Array[StringName]):
mementos_collected += 1 mementos_collected += 1
@ -189,7 +170,6 @@ func populate_board(card_names: Array[StringName]):
# marking the first sticky as random picks # marking the first sticky as random picks
new_sticky_note.picked_random = new_sticky_note.name == card_names[3] new_sticky_note.picked_random = new_sticky_note.name == card_names[3]
#currently_active_node = area_dict["dropzone_content"][0] # set first Card as currently selected node by default
currently_active_node = dropzone.get_child(0) currently_active_node = dropzone.get_child(0)
func add_card(card: Card, re_parent:bool = true): func add_card(card: Card, re_parent:bool = true):
@ -371,13 +351,6 @@ func give_lore_feedback():
$AnimationPlayer.play("complete") $AnimationPlayer.play("complete")
complete = true complete = true
func is_board_lore() -> bool:
for card in dropzone.get_children():
if card is Card:
if card.has_sticky_note_attached():
if not card.current_sticky_note.sticky_id.contains(card.card_id): return false
return true
# Mark area that was hovered over as currently selected # Mark area that was hovered over as currently selected
func handle_hover(to_handle: Area2D) -> void: func handle_hover(to_handle: Area2D) -> void:
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT): return if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT): return
@ -524,63 +497,8 @@ func _input(event) -> void:
current_context = ASSIGN current_context = ASSIGN
focus_stickies = true focus_stickies = true
current_sticky_note_id = current_sticky_note_id current_sticky_note_id = current_sticky_note_id
#
# else:
# if current_context == ASSIGN:
# if not dropzone.get_child(current_dropzone_id) is Card: return
# var card:Card = dropzone.get_child(current_dropzone_id)
#
# if dropzone.get_child(current_dropzone_id) is Card:
# var card:Card = dropzone.get_child(current_dropzone_id)
# if current_context == ASSIGN: # to assign it to a card
# if card.has_sticky_note_attached():
# currently_active_node = card.exchange_sticky_note_with(currently_active_node)
# if not try_select_nearest_empty_card(currently_active_node.global_position):
# current_dropzone_id = find_first_free_card()
# else:
# card.attach_sticky_note(sticky_note_container.get_child(current_sticky_note_id).attached_sticky_note)
# current_context = NAVIGATE
# for panel: StickyNotePanel in sticky_note_container.get_children():
# panel.clear_if_empty()
# focus_stickies = not focus_stickies
# if not try_select_nearest_empty_card(currently_active_node.global_position):
# current_dropzone_id = find_first_free_card()
# check_board_comnpletion()
# return
# else:
# if !focus_stickies and card.has_sticky_note_attached():
# pass
# else:
# if not try_select_nearest_empty_card(currently_active_node.global_position):
# current_dropzone_id = find_first_free_card()
#
# current_context = ASSIGN
# focus_stickies = !focus_stickies
# if focus_stickies:
# current_sticky_note_id = current_sticky_note_id
# else:
# current_dropzone_id = current_dropzone_id
# elif dropzone.get_child(current_dropzone_id) is StickyNote:
# if currently_active_node is StickyNote:
# currently_active_node = dropzone.get_child(current_dropzone_id)
# focus_stickies = false
# current_context = ASSIGN
# current_dropzone_id += 1
# currently_active_node.is_dragable = false
# currently_active_node.z_index = 1
get_viewport().set_input_as_handled() get_viewport().set_input_as_handled()
# move the note it so it floats next to the card where it should be attached
func _select_card_for_assigning(sticky_note: Area2D, card: Area2D):
sticky_note.tween_transform_to(card.get_child(3).global_position)
func on_scene_skipped(i: int):
mementos_collected += i # FIXME: sometimes -1 is passed here, why?
func claim_focus():
focused = true
## Awaitable function to show the board and wait until user closes it ## Awaitable function to show the board and wait until user closes it
func play() -> void: func play() -> void:
@ -633,23 +551,10 @@ func save_to_resource(savegame: SaveGame) -> void:
# Save all collected Stickies that are not on board # Save all collected Stickies that are not on board
savegame.board_stickies[child.attached_sticky_note.name] = -1 savegame.board_stickies[child.attached_sticky_note.name] = -1
## Legacy method for backwards compatibility
func get_save_dict() -> Dictionary:
return {
"cards": {},
"stickies": {},
"randoms": []
}
func initialise_from_save(savegame: SaveGame) -> void: func initialise_from_save(savegame: SaveGame) -> void:
# Early return if no board data
if savegame.board_cards.is_empty() and savegame.board_stickies.is_empty():
return
rebuild_from_save(savegame)
func rebuild_from_save(savegame: SaveGame) -> void:
# Early return if nothing to load # Early return if nothing to load
if savegame.board_cards.is_empty() and savegame.board_stickies.is_empty(): if savegame.board_cards.is_empty() and savegame.board_stickies.is_empty():
return return
@ -670,11 +575,9 @@ func rebuild_from_save(savegame: SaveGame) -> void:
add_card(card, false) add_card(card, false)
card.transform.origin = savegame.board_cards[card.name] card.transform.origin = savegame.board_cards[card.name]
cards_by_name[card.name] = card cards_by_name[card.name] = card
text_recovery[card.name] = card.text
card.picked_random = savegame.board_randoms.has(card.card_id) card.picked_random = savegame.board_randoms.has(card.card_id)
for sticky: StickyNote in card_pile["sticky_notes"]: for sticky: StickyNote in card_pile["sticky_notes"]:
text_recovery[sticky.name] = sticky.text
var sticky_data = savegame.board_stickies[sticky.name] var sticky_data = savegame.board_stickies[sticky.name]
if sticky_data is int: if sticky_data is int:
@ -691,30 +594,6 @@ func rebuild_from_save(savegame: SaveGame) -> void:
sticky.picked_random = savegame.board_randoms.has(sticky.sticky_id) sticky.picked_random = savegame.board_randoms.has(sticky.sticky_id)
func validate_sticky(note: StickyNote) -> CardBoard.Error:
if not get_viewport_rect().has_point(note.get_global_transform().origin):
return Error.OUT_OF_BOUNDS
if note.attached_to is StickyNotePanel:
if note.position != note.attached_to.ancor_position:
return Error.OUT_OF_BOUNDS
if (note.on_board and not is_in_dropzone(note)):
return Error.ILLEGAL_STATE
if not ((note.attached_to == self and dropzone.get_children().has(note)) or note.attached_to == note.get_parent()) or note.shift_tween != null:
return Error.ILLEGAL_STATE
return Error.OK
func validate_card(card: Card) -> CardBoard.Error:
if not is_in_dropzone(card):
return Error.OUT_OF_BOUNDS
if card.get_attached_sticky_note() != card.current_sticky_note:
#push_error("Card %s claims to have %s as current sticky note but has %s attached." % [card.name, card.current_sticky_note, card.get_attached_sticky_note()])
return Error.ILLEGAL_STATE
if not card.owner == self:
return Error.ILLEGAL_STATE
return CardBoard.Error.OK
func try_select_nearest_card(from: Vector2, towards: Vector2, include_stickies: bool = false) -> bool: func try_select_nearest_card(from: Vector2, towards: Vector2, include_stickies: bool = false) -> bool:
var selection_transform := Transform2D(0, from).looking_at(from+towards) var selection_transform := Transform2D(0, from).looking_at(from+towards)

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://chwf61qpn2sqw"] [gd_scene load_steps=2 format=3 uid="uid://chwf61qpn2sqw"]
[ext_resource type="Script" uid="uid://c8gsxyymrldcd" path="res://logic-scenes/board/empty_sticky_note_panel.gd" id="1_1dtc4"] [ext_resource type="Script" uid="uid://c8gsxyymrldcd" path="res://logic-scenes/board/sticky_note_panel.gd" id="1_1dtc4"]
[node name="Panel" type="Panel"] [node name="Panel" type="Panel"]
self_modulate = Color(1, 1, 1, 0) self_modulate = Color(1, 1, 1, 0)