From 744070e0bd41d2da926c2487fea495ef957405be Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 12 Dec 2022 11:32:26 +0100 Subject: [PATCH] implement import from json export --- src/dev-util/ingest connection.tscn | 7 +++++++ src/dev-util/ingest post-it.tscn | 3 +++ src/dev-util/ingest_board.gd | 14 ++++++++++++++ src/dev-util/ingest_card.tscn | 23 +++++++++++++++++++++++ src/dev-util/ingest_story.tscn | 19 +++++++++++++++++++ 5 files changed, 66 insertions(+) diff --git a/src/dev-util/ingest connection.tscn b/src/dev-util/ingest connection.tscn index 92f682e..343dbf2 100644 --- a/src/dev-util/ingest connection.tscn +++ b/src/dev-util/ingest connection.tscn @@ -24,6 +24,13 @@ func save(): weight2 = $second_weight.value, postit = post_it.get_instance_id() } + +func digest(connection_dict:Dictionary, postit_array:Array): + $first_weight.value = connection_dict.weight1 + $second_weight.value = connection_dict.weight2 + for postit_dict in postit_array: + if postit_dict.old_id == connection_dict.postit: + post_it = postit_dict.new_item " [node name="Ingest Connection" type="VBoxContainer"] diff --git a/src/dev-util/ingest post-it.tscn b/src/dev-util/ingest post-it.tscn index 6319922..1fa0aaa 100644 --- a/src/dev-util/ingest post-it.tscn +++ b/src/dev-util/ingest post-it.tscn @@ -15,6 +15,9 @@ func save(): text = $LineEdit.text # TODO: Save audio } + +func digest(postit_dict:Dictionary): + $LineEdit.text = postit_dict.text " [node name="Ingest Post-It" type="VBoxContainer"] diff --git a/src/dev-util/ingest_board.gd b/src/dev-util/ingest_board.gd index 813b562..ec379e8 100644 --- a/src/dev-util/ingest_board.gd +++ b/src/dev-util/ingest_board.gd @@ -65,3 +65,17 @@ func _on_save_pressed(): connections = connections } save_stories.store_line(to_json(save_dict)) + save_stories.close() + +func import_from_file(fileName:String): + var import_source = File.new() + import_source.open(fileName, File.READ) + var import_dict = parse_json(import_source.get_as_text()) + import_source.close() + for story in import_dict.stories: + var new_story = story_template.duplicate() + var new_items = new_story.digest(story, import_dict.cards, import_dict.postits, import_dict.connections) + new_story.show() + story_list.add_child(new_story) + all_cards.append_array(new_items.new_cards) + all_post_its.append_array(new_items.new_postits) diff --git a/src/dev-util/ingest_card.tscn b/src/dev-util/ingest_card.tscn index df623d0..c1e6975 100644 --- a/src/dev-util/ingest_card.tscn +++ b/src/dev-util/ingest_card.tscn @@ -50,6 +50,29 @@ func save(): connections = connections_export # TODO: save audio } + +func digest(card_dict:Dictionary, postit_array:Array, connection_array:Array): + $LineEdit.text = card_dict.text + var tmp_post_its = [] + for postit_id in card_dict.postits: + for postit in postit_array: + if postit.id == postit_id: + var new_postit = { + old_id = postit_id, + new_item = post_its_template.duplicate().digest(postit) + } + tmp_post_its.append(new_postit) + for connection_id in card_dict.connections: + for connection in connection_array: + if connection.id == connection_id: + var new_connection = connection_template.duplicate().digest(connection, tmp_post_its) + connections.append(new_connection) + for postit_dict in tmp_post_its: + post_its.append(postit_dict.new_item) + return { + new_postits = post_its, + new_connections = connections + } " [node name="Ingest Card" type="VBoxContainer"] diff --git a/src/dev-util/ingest_story.tscn b/src/dev-util/ingest_story.tscn index bdd135d..6be1735 100644 --- a/src/dev-util/ingest_story.tscn +++ b/src/dev-util/ingest_story.tscn @@ -35,6 +35,25 @@ func save(): cards = cards_export # TODO: save audio } + +func digest(story_dict:Dictionary, card_array:Array, postit_array:Array, connection_array:Array): + $LineEdit.text = story_dict.name + $TextEdit.text = story_dict.story + var new_postits = [] + var new_connections = [] + for card_id in story_dict.cards: + for card in card_array: + if card_id == card.id: + var new_card = card_template.duplicate() + var postconns = new_card.digest(card, postit_array, connection_array) + cards.append(new_card) + new_postits.append_array(postconns.new_postits) + new_connections.append_array(postconns.new_connections) + return { + new_cards = cards, + new_postits = new_postits, + new_connections = new_connections + } " [node name="Ingest Story" type="VBoxContainer"]