implement import from json export

This commit is contained in:
nek0 2022-12-12 11:32:26 +01:00
parent 6f63176b91
commit 744070e0bd
5 changed files with 66 additions and 0 deletions

View file

@ -24,6 +24,13 @@ func save():
weight2 = $second_weight.value, weight2 = $second_weight.value,
postit = post_it.get_instance_id() 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"] [node name="Ingest Connection" type="VBoxContainer"]

View file

@ -15,6 +15,9 @@ func save():
text = $LineEdit.text text = $LineEdit.text
# TODO: Save audio # TODO: Save audio
} }
func digest(postit_dict:Dictionary):
$LineEdit.text = postit_dict.text
" "
[node name="Ingest Post-It" type="VBoxContainer"] [node name="Ingest Post-It" type="VBoxContainer"]

View file

@ -65,3 +65,17 @@ func _on_save_pressed():
connections = connections connections = connections
} }
save_stories.store_line(to_json(save_dict)) 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)

View file

@ -50,6 +50,29 @@ func save():
connections = connections_export connections = connections_export
# TODO: save audio # 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"] [node name="Ingest Card" type="VBoxContainer"]

View file

@ -35,6 +35,25 @@ func save():
cards = cards_export cards = cards_export
# TODO: save audio # 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"] [node name="Ingest Story" type="VBoxContainer"]