|
|
|
|
@ -142,7 +142,6 @@ func _on_board_focused() -> void:
|
|
|
|
|
## Called when board loses focus
|
|
|
|
|
func _on_board_unfocused() -> void:
|
|
|
|
|
visible = false
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
|
if is_node_ready():
|
|
|
|
|
process_mode = Node.PROCESS_MODE_DISABLED
|
|
|
|
|
# Stop any active dragging
|
|
|
|
|
@ -173,19 +172,12 @@ func populate_board(card_names: Array[StringName]):
|
|
|
|
|
|
|
|
|
|
currently_active_node = dropzone.get_child(0)
|
|
|
|
|
|
|
|
|
|
## Generates a random position within the dropzone bounds
|
|
|
|
|
func _generate_random_position() -> Vector2:
|
|
|
|
|
return Vector2(
|
|
|
|
|
randi_range(dropzone_padding, int(dropzone_size.x)),
|
|
|
|
|
randi_range(dropzone_padding, int(dropzone_size.y))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func add_card(card: Card, re_parent:bool = true):
|
|
|
|
|
if re_parent:
|
|
|
|
|
card.reparent(self)
|
|
|
|
|
else:
|
|
|
|
|
add_child(card)
|
|
|
|
|
card.position = _generate_random_position()
|
|
|
|
|
card.position = Vector2(randi_range(dropzone_padding, int(dropzone_size.x)), randi_range(dropzone_padding, int(dropzone_size.y)))
|
|
|
|
|
insert_area(dropzone, card)
|
|
|
|
|
card.set_owner(self)
|
|
|
|
|
card.is_dragable = true
|
|
|
|
|
@ -532,166 +524,75 @@ func on_sticky_panel_cleared(at_id: int):
|
|
|
|
|
|
|
|
|
|
## Saves board state directly to SaveGame resource
|
|
|
|
|
func save_to_resource(savegame: SaveGame) -> void:
|
|
|
|
|
savegame.board_positions.clear()
|
|
|
|
|
savegame.board_attachments.clear()
|
|
|
|
|
savegame.board_in_panel.clear()
|
|
|
|
|
savegame.board_cards.clear()
|
|
|
|
|
savegame.board_stickies.clear()
|
|
|
|
|
savegame.board_randoms.clear()
|
|
|
|
|
|
|
|
|
|
print_debug("CardBoard: Saving board state...")
|
|
|
|
|
|
|
|
|
|
for child in dropzone.get_children():
|
|
|
|
|
if child is Card:
|
|
|
|
|
# Save card position (local to dropzone)
|
|
|
|
|
savegame.board_positions[child.name] = child.position
|
|
|
|
|
print_debug(" Card '%s' at %s" % [child.name, child.position])
|
|
|
|
|
# Save position of Card
|
|
|
|
|
savegame.board_cards[child.name] = child.transform.origin
|
|
|
|
|
if child.picked_random:
|
|
|
|
|
savegame.board_randoms.append(child.name)
|
|
|
|
|
|
|
|
|
|
var note: StickyNote = child.get_attached_sticky_note()
|
|
|
|
|
if note:
|
|
|
|
|
# Save sticky attachment to card
|
|
|
|
|
savegame.board_attachments[note.name] = child.name
|
|
|
|
|
# Don't save position for attached stickies - it's determined by the card
|
|
|
|
|
print_debug(" Sticky '%s' attached to card '%s'" % [note.name, child.name])
|
|
|
|
|
if note.picked_random:
|
|
|
|
|
savegame.board_randoms.append(note.name)
|
|
|
|
|
# Save Card Name as position of its children
|
|
|
|
|
savegame.board_stickies[child.get_attached_sticky_note().name] = child.name
|
|
|
|
|
if child.get_attached_sticky_note().picked_random:
|
|
|
|
|
savegame.board_randoms.append(child.get_attached_sticky_note().name)
|
|
|
|
|
|
|
|
|
|
elif child is StickyNote:
|
|
|
|
|
# Save position of loose sticky on board (local to dropzone)
|
|
|
|
|
savegame.board_positions[child.name] = child.position
|
|
|
|
|
print_debug(" Loose sticky '%s' at %s" % [child.name, child.position])
|
|
|
|
|
if child.picked_random:
|
|
|
|
|
savegame.board_randoms.append(child.name)
|
|
|
|
|
# Save position of StickyNote
|
|
|
|
|
savegame.board_cards[child.name] = child.transform.origin
|
|
|
|
|
|
|
|
|
|
for child in sticky_note_container.get_children():
|
|
|
|
|
if child is StickyNotePanel and child.attached_sticky_note:
|
|
|
|
|
# Save sticky in panel state
|
|
|
|
|
savegame.board_in_panel.append(child.attached_sticky_note.name)
|
|
|
|
|
print_debug(" Sticky '%s' in panel" % child.attached_sticky_note.name)
|
|
|
|
|
if child.attached_sticky_note.picked_random:
|
|
|
|
|
savegame.board_randoms.append(child.attached_sticky_note.name)
|
|
|
|
|
|
|
|
|
|
print_debug("CardBoard: Saved %d positions, %d attachments, %d in panel" % [
|
|
|
|
|
savegame.board_positions.size(),
|
|
|
|
|
savegame.board_attachments.size(),
|
|
|
|
|
savegame.board_in_panel.size()
|
|
|
|
|
])
|
|
|
|
|
if child is StickyNotePanel:
|
|
|
|
|
# Save all collected Stickies that are not on board
|
|
|
|
|
savegame.board_stickies[child.attached_sticky_note.name] = -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func initialise_from_save(savegame: SaveGame) -> void:
|
|
|
|
|
# Early return if nothing to load
|
|
|
|
|
if savegame.board_positions.is_empty():
|
|
|
|
|
print_debug("CardBoard: No board state to load (save is empty or legacy format)")
|
|
|
|
|
if savegame.board_cards.is_empty() and savegame.board_stickies.is_empty():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
print_debug("CardBoard: Loading board state from save...")
|
|
|
|
|
print_debug(" Positions: %d, Attachments: %d, In panel: %d" % [
|
|
|
|
|
savegame.board_positions.size(),
|
|
|
|
|
savegame.board_attachments.size(),
|
|
|
|
|
savegame.board_in_panel.size()
|
|
|
|
|
])
|
|
|
|
|
# Collect all card names
|
|
|
|
|
var all_cards: Array[StringName]
|
|
|
|
|
for card_name: StringName in savegame.board_cards.keys():
|
|
|
|
|
all_cards.append(card_name)
|
|
|
|
|
for card_name: StringName in savegame.board_stickies.keys():
|
|
|
|
|
all_cards.append(card_name)
|
|
|
|
|
|
|
|
|
|
# Collect all card/sticky names from all relevant dictionaries
|
|
|
|
|
var all_names: Array[StringName]
|
|
|
|
|
|
|
|
|
|
# Names from positions (cards and loose stickies)
|
|
|
|
|
for item_name: StringName in savegame.board_positions.keys():
|
|
|
|
|
if not all_names.has(item_name):
|
|
|
|
|
all_names.append(item_name)
|
|
|
|
|
|
|
|
|
|
# Sticky names from attachments
|
|
|
|
|
for sticky_name: StringName in savegame.board_attachments.keys():
|
|
|
|
|
if not all_names.has(sticky_name):
|
|
|
|
|
all_names.append(sticky_name)
|
|
|
|
|
|
|
|
|
|
# Card names from attachments (the values)
|
|
|
|
|
for card_name: StringName in savegame.board_attachments.values():
|
|
|
|
|
if not all_names.has(card_name):
|
|
|
|
|
all_names.append(card_name)
|
|
|
|
|
|
|
|
|
|
# Sticky names from panel
|
|
|
|
|
for item_name: StringName in savegame.board_in_panel:
|
|
|
|
|
if not all_names.has(item_name):
|
|
|
|
|
all_names.append(item_name)
|
|
|
|
|
|
|
|
|
|
print_debug(" Collected %d unique card/sticky names to load" % all_names.size())
|
|
|
|
|
|
|
|
|
|
var card_pile: Dictionary[String, Array] = HardCards.get_cards_by_name_array(all_names)
|
|
|
|
|
var card_pile : Dictionary[String, Array] = HardCards.get_cards_by_name_array(all_cards)
|
|
|
|
|
|
|
|
|
|
# Track cards by name for sticky note attachment
|
|
|
|
|
var cards_by_name: Dictionary = {}
|
|
|
|
|
|
|
|
|
|
# Calculate mementos collected (each memento gives 2 cards)
|
|
|
|
|
mementos_collected = int(card_pile["cards"].size() / 2.0)
|
|
|
|
|
print_debug(" Calculated mementos_collected: %d (from %d cards)" % [mementos_collected, card_pile["cards"].size()])
|
|
|
|
|
|
|
|
|
|
# Add all cards
|
|
|
|
|
print_debug(" Loading %d cards..." % card_pile["cards"].size())
|
|
|
|
|
for card: Card in card_pile["cards"]:
|
|
|
|
|
add_child(card)
|
|
|
|
|
|
|
|
|
|
# Set position from save, or generate random if missing
|
|
|
|
|
if savegame.board_positions.has(card.name):
|
|
|
|
|
card.position = savegame.board_positions[card.name]
|
|
|
|
|
print_debug(" Card '%s' at %s" % [card.name, card.position])
|
|
|
|
|
else:
|
|
|
|
|
card.position = _generate_random_position()
|
|
|
|
|
print_debug(" Card '%s' - generated random position: %s" % [card.name, card.position])
|
|
|
|
|
|
|
|
|
|
insert_area(dropzone, card)
|
|
|
|
|
card.set_owner(self)
|
|
|
|
|
card.is_dragable = true
|
|
|
|
|
add_card(card, false)
|
|
|
|
|
card.transform.origin = savegame.board_cards[card.name]
|
|
|
|
|
cards_by_name[card.name] = card
|
|
|
|
|
card.picked_random = savegame.board_randoms.has(card.card_id)
|
|
|
|
|
|
|
|
|
|
# Add all sticky notes
|
|
|
|
|
print_debug(" Loading %d stickies..." % card_pile["sticky_notes"].size())
|
|
|
|
|
for sticky: StickyNote in card_pile["sticky_notes"]:
|
|
|
|
|
# Check if sticky is in panel
|
|
|
|
|
if savegame.board_in_panel.has(sticky.name):
|
|
|
|
|
add_sticky_note(sticky, false)
|
|
|
|
|
print_debug(" Sticky '%s' added to panel" % sticky.name)
|
|
|
|
|
var sticky_data = savegame.board_stickies[sticky.name]
|
|
|
|
|
|
|
|
|
|
# Check if sticky is attached to a card
|
|
|
|
|
elif savegame.board_attachments.has(sticky.name):
|
|
|
|
|
var card_name = savegame.board_attachments[sticky.name]
|
|
|
|
|
if cards_by_name.has(card_name):
|
|
|
|
|
# Must add sticky to scene tree BEFORE attach_sticky_note() can reparent it
|
|
|
|
|
add_child(sticky)
|
|
|
|
|
sticky.set_owner(self)
|
|
|
|
|
sticky.current_handle = self # Required for input handling
|
|
|
|
|
cards_by_name[card_name].attach_sticky_note(sticky)
|
|
|
|
|
print_debug(" Sticky '%s' attached to card '%s'" % [sticky.name, card_name])
|
|
|
|
|
else:
|
|
|
|
|
push_warning("CardBoard: Sticky '%s' attached to non-existent card '%s', adding to panel" % [sticky.name, card_name])
|
|
|
|
|
if sticky_data is int:
|
|
|
|
|
if sticky_data == -1:
|
|
|
|
|
add_sticky_note(sticky, false)
|
|
|
|
|
|
|
|
|
|
# Sticky is loose on board
|
|
|
|
|
elif sticky_data is String:
|
|
|
|
|
# Attached to a card
|
|
|
|
|
cards_by_name[sticky_data].attach_sticky_note(sticky)
|
|
|
|
|
else:
|
|
|
|
|
add_child(sticky)
|
|
|
|
|
|
|
|
|
|
# Set position from save, or generate random if missing
|
|
|
|
|
if savegame.board_positions.has(sticky.name):
|
|
|
|
|
sticky.position = savegame.board_positions[sticky.name]
|
|
|
|
|
print_debug(" Loose sticky '%s' at %s" % [sticky.name, sticky.position])
|
|
|
|
|
else:
|
|
|
|
|
sticky.position = _generate_random_position()
|
|
|
|
|
print_debug(" Loose sticky '%s' - generated random position: %s" % [sticky.name, sticky.position])
|
|
|
|
|
|
|
|
|
|
# Loose on board at position
|
|
|
|
|
insert_area(dropzone, sticky)
|
|
|
|
|
sticky.set_owner(self)
|
|
|
|
|
sticky.current_handle = self # Required for input handling
|
|
|
|
|
sticky.on_board = true
|
|
|
|
|
sticky.attached_to = self
|
|
|
|
|
sticky.is_dragable = true
|
|
|
|
|
sticky.transform.origin = sticky_data
|
|
|
|
|
|
|
|
|
|
sticky.picked_random = savegame.board_randoms.has(sticky.sticky_id)
|
|
|
|
|
|
|
|
|
|
print_debug("CardBoard: Load complete!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func try_select_nearest_card(from: Vector2, towards: Vector2, include_stickies: bool = false) -> bool:
|
|
|
|
|
var selection_transform := Transform2D(0, from).looking_at(from+towards)
|
|
|
|
|
|