import and export seems to work properly now

This commit is contained in:
nek0 2022-12-16 13:26:44 +01:00
parent 744070e0bd
commit 5d2ffd39b8
5 changed files with 67 additions and 30 deletions

View file

@ -18,18 +18,28 @@ func _on_card_paster_pressed():
select(tmp)
func save():
return {
id = self.get_instance_id(),
weight1 = $first_weight.value,
weight2 = $second_weight.value,
postit = post_it.get_instance_id()
}
var postit_export = false
if is_instance_valid(post_it):
postit_export = true
if postit_export:
return {
id = self.get_instance_id(),
weight1 = $first_weight.value,
weight2 = $second_weight.value,
postit = post_it.get_instance_id()
}
else:
return {
id = self.get_instance_id(),
weight1 = $first_weight.value,
weight2 = $second_weight.value
}
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:
if connection_dict.has(\"postit\") and postit_dict.old_id == connection_dict.postit:
post_it = postit_dict.new_item
"

View file

@ -45,7 +45,7 @@ func paste():
func _on_save_pressed():
var save_stories = File.new()
save_stories.open("res://dev-util/export.save", File.WRITE)
save_stories.open("res://dev-util/export.json", File.WRITE)
var stories = []
for story in story_list.get_children():
stories.append(story.save())
@ -64,18 +64,40 @@ func _on_save_pressed():
postits = postits,
connections = connections
}
save_stories.store_line(to_json(save_dict))
save_stories.store_string(JSON.print(save_dict, "\t", false))
save_stories.close()
func import_from_file(fileName:String):
clear_data()
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)
new_story.digest(story, import_dict.cards, import_dict.postits, import_dict.connections)
func _on_load_pressed():
import_from_file("res://dev-util/export.json")
func clear_data():
for i in story_list.get_children():
story_list.remove_child(i)
for i in card_list.get_children():
card_list.remove_child(i)
for i in post_it_list.get_children():
post_it_list.remove_child(i)
for i in connections_list.get_children():
connections_list.remove_child(i)
for i in final_list.get_children():
final_list.remove_child(i)
all_cards = []
all_post_its = []

View file

@ -73,5 +73,13 @@ margin_right = 1874.0
margin_bottom = 46.0
text = "Save"
[node name="load" type="Button" parent="."]
margin_left = 1833.0
margin_top = 54.0
margin_right = 1875.0
margin_bottom = 74.0
text = "Load"
[connection signal="pressed" from="add story" to="." method="_on_add_story_pressed"]
[connection signal="pressed" from="save" to="." method="_on_save_pressed"]
[connection signal="pressed" from="load" to="." method="_on_load_pressed"]

View file

@ -57,22 +57,25 @@ func digest(card_dict:Dictionary, postit_array:Array, connection_array:Array):
for postit_id in card_dict.postits:
for postit in postit_array:
if postit.id == postit_id:
var new_from_template = post_its_template.duplicate()
post_board.add_child(new_from_template)
new_from_template.digest(postit)
post_board.remove_child(new_from_template)
post_its.append(new_from_template)
get_tree().root.get_child(0).all_post_its.append(post_its[post_its.size()-1])
var new_postit = {
old_id = postit_id,
new_item = post_its_template.duplicate().digest(postit)
new_item = new_from_template
}
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)
var new_connection = connection_template.duplicate()
connection_board.add_child(new_connection)
new_connection.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
}
connection_board.remove_child(new_connection)
"
[node name="Ingest Card" type="VBoxContainer"]

View file

@ -39,21 +39,15 @@ func save():
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
}
next_board.add_child(new_card)
get_tree().root.get_child(0).all_cards.append(cards[cards.size()-1])
new_card.digest(card, postit_array, connection_array)
next_board.remove_child(new_card)
"
[node name="Ingest Story" type="VBoxContainer"]