add support to initialise and save board state to savegame

This commit is contained in:
betalars 2024-10-03 01:12:24 +02:00
parent efcc3bf694
commit 0692f76d0b
2 changed files with 43 additions and 0 deletions

View File

@ -349,3 +349,43 @@ func find_first_free_card() -> int:
func on_sticky_panel_cleared(): func on_sticky_panel_cleared():
if current_sticky_note_id == sticky_note_container.get_child_count() - 1: if current_sticky_note_id == sticky_note_container.get_child_count() - 1:
current_sticky_note_id -= 1 current_sticky_note_id -= 1
func get_save_dict() -> Dictionary:
var cards: Dictionary = {}
var stickies: Dictionary = {}
for child in dropzone.get_children():
if child is Card:
if child.has_sticky_note_attached():
stickies[child.get_attached_sticky_note().name] = child.name
cards[child.name] = child.transform.origin
elif child is StickyNote:
cards[child.name] = child.transform.origin
for child in sticky_note_container.get_children():
if child is PostItPanel:
stickies[child.attached_sticky_note.name] = -1
return {
"cards": cards,
"stickies": stickies
}
func initialise_from_save(savegame: SaveGame):
var cards: Dictionary = savegame.board_state["cards"]
var stickies: Dictionary = savegame.board_state["stickies"]
var card_pile = board_of_devs.get_cards_by_name_array(cards.keys() + (stickies.keys()))
for card:Card in card_pile["cards"]:
add_card(card)
card.transform.origin = cards[card.name]
cards[card.name] = card
for sticky:StickyNote in card_pile["sticky_notes"]:
if stickies[sticky.name] == -1:
add_sticky_note(sticky)
if stickies[sticky.name] is String:
cards[stickies[sticky.name]].attach_sticky_note(sticky)
else:
insert_area(dropzone, sticky)
sticky.transform.origin = stickies[sticky.name]

View File

@ -171,6 +171,9 @@ func _move_card():
func has_sticky_note_attached() -> bool: func has_sticky_note_attached() -> bool:
return get_child(-1) is StickyNote return get_child(-1) is StickyNote
func get_attached_sticky_note() -> StickyNote:
return null if not has_sticky_note_attached() else get_child(-1)
func preview_sticky_note(sticky_note: StickyNote): func preview_sticky_note(sticky_note: StickyNote):
sticky_note.reparent(self.get_parent()) sticky_note.reparent(self.get_parent())
sticky_note.owner = owner sticky_note.owner = owner