From 4ab34a242be2a7fc60a13f27cd9a2aa01619454c Mon Sep 17 00:00:00 2001 From: SuhwanKim Date: Sun, 28 Jan 2024 10:05:59 -0800 Subject: [PATCH 1/2] added basic save system Added basic save system that has data to xml file. --- Phase2/Godot_Toolset/Main/project.godot | 1 + .../character_creation_wizard.gd | 72 ++++++++++--------- .../character_creation_wizard.tscn | 3 + 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/Phase2/Godot_Toolset/Main/project.godot b/Phase2/Godot_Toolset/Main/project.godot index 4420a7c..6f2a138 100644 --- a/Phase2/Godot_Toolset/Main/project.godot +++ b/Phase2/Godot_Toolset/Main/project.godot @@ -11,6 +11,7 @@ config_version=4 [application] config/name="bcirpg_toolset" +run/main_scene="res://screens/wizards/character_creation/character_creation_wizard.tscn" config/icon="res://icon.png" [global] diff --git a/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd b/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd index 37f0e06..f43a4a0 100644 --- a/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd +++ b/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd @@ -86,12 +86,12 @@ onready var special8 = $"RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/V onready var special9 = $"RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer/SBOptionButton9" - # Save the data to a CSV file. -var rowData = [CharacterName, Profession, Demeanor, Species, Culture, Faction, Description, HeightAndWeight, - Backstory, Gender, Equipment, Charisma, Dialog, Constitution, Agility, SelfDisipline, Memory, Reasoning, - Strength, Quickness, Presence, Intuition, Empathy, Appearence, skill1, skill2, skill3, skill4, skill5, - skill6, skill7, skill8, skill9, skill10, special1, special2, special3, special4, special5, special6, - special7, special8, special9] + # 12/10/23 save the data to a xml file. + + # comments for future skill sets to use + # ,skill1, skill2, skill3, skill4, skill5, + # skill6, skill7, skill8, skill9, skill10, special1, special2, special3, special4, special5, special6, + # special7, special8, special9 var headerData = ["CharacterName", "Profession", "Demeanor", "Species", "Culture", "Faction", "Description", "HeightAndWeight", "Backstory", "Gender", "Equipment", "Charisma", "Dialog", "Constitution", "Agility", "SelfDisipline", "Memory", @@ -103,37 +103,43 @@ var headerData = ["CharacterName", "Profession", "Demeanor", "Species", "Culture func _ready(): pass # Replace with function body. -func save_data_to_csv(data: Array, file_path: String): + +var file_path = "user://data.xml" # Use 'user://' to save in the user data directory + +func save_data_to_xml(data: Array, path: String) -> void: + + #save_user_data() + + var file = File.new() - if file.open(file_path, File.WRITE) == OK: - for row in data: - file.store_string(format_row(row)) + + if file.open("user://data.xml", File.WRITE) == OK: + file.store_line("") + file.store_line("") + + for line_edit in data: + var line_edit_text = line_edit.text + file.store_line(line_edit_text) + #file.store_line("\n") + + + file.store_line("") file.close() - print("Data saved to", file_path) + print("Data saved to XML file:", path) else: - print("Failed to open", file_path, "for writing.") + print("Error opening file for writing:", path) -func format_row(row_data: Array) -> String: - # Convert the array of data to a comma-separated string - var formatted_row = "" - for i in range(row_data.size()): - formatted_row += str(row_data[i]) - if i < row_data.size() - 1: - formatted_row += "," - formatted_row += "\n" - return formatted_row - -# Example usage: -var data_to_save = [ - ["Name", "Age", "Score"], - ["John", 25, 85], - ["Alice", 30, 92], - ["Bob", 28, 78], -] - -var file_path = "user://data.csv" # Use 'user://' to save in the user data directory +func create_array_to_save() -> Array: + var userData = [CharacterName, Profession, Demeanor, Species, Culture, Faction, Description, HeightAndWeight, + Backstory, Gender, Equipment, Charisma, Dialog, Constitution, Agility, SelfDisipline, Memory, Reasoning, + Strength, Quickness, Presence, Intuition, Empathy, Appearence] + + return userData func _on_Button_pressed(): - var fileName = "character_data.csv" - save_data_to_csv(data_to_save, file_path) + save_data_to_xml(create_array_to_save(), file_path) + + + + diff --git a/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.tscn b/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.tscn index 370b684..606acce 100644 --- a/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.tscn +++ b/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.tscn @@ -12,6 +12,8 @@ script = ExtResource( 3 ) [node name="ColorRect" type="ColorRect" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 +margin_top = -6.0 +margin_bottom = -6.0 color = Color( 0.537255, 0.537255, 0.537255, 1 ) [node name="RootVBoxContainer" type="VBoxContainer" parent="."] @@ -684,3 +686,4 @@ margin_bottom = 368.0 text = "Export Character To Module" [connection signal="pressed" from="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/Button" to="." method="_on_Button_pressed"] +[connection signal="tree_entered" from="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/Button" to="." method="_on_Button_tree_entered"] From c9d3f7d26cd47f14454951dcd40ad80e629b7b96 Mon Sep 17 00:00:00 2001 From: SuhwanKim Date: Sun, 18 Feb 2024 09:56:43 -0800 Subject: [PATCH 2/2] Update Save system updated save system using xml files and made it more readable ex) CharacterName: James Profession : programmer --- .../character_creation_wizard.gd | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd b/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd index f43a4a0..c3b233e 100644 --- a/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd +++ b/Phase2/Godot_Toolset/Main/screens/wizards/character_creation/character_creation_wizard.gd @@ -93,11 +93,7 @@ onready var special9 = $"RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/V # skill6, skill7, skill8, skill9, skill10, special1, special2, special3, special4, special5, special6, # special7, special8, special9 -var headerData = ["CharacterName", "Profession", "Demeanor", "Species", "Culture", "Faction", "Description", "HeightAndWeight", - "Backstory", "Gender", "Equipment", "Charisma", "Dialog", "Constitution", "Agility", "SelfDisipline", "Memory", - "Reasoning","Strength", "Quickness", "Presence", "Intuition", "Empathy", "Appearance", "skill1", "skill2", "skill3", "skill4", - "skill5", "skill6", "skill7", "skill8", "skill9", "skill10", "special1", "special2", "special3", "special4", "special5", "special6", - "special7", "special8", "special9"] + # Called when the node enters the scene tree for the first time. func _ready(): @@ -106,28 +102,45 @@ func _ready(): var file_path = "user://data.xml" # Use 'user://' to save in the user data directory -func save_data_to_xml(data: Array, path: String) -> void: - - #save_user_data() - +func save_data_to_xml(data: Array, header: Array, path: String) -> void: var file = File.new() if file.open("user://data.xml", File.WRITE) == OK: - file.store_line("") - file.store_line("") + var xml = "\n" + var index = 0 + for line_edit in data: + var line_edit_text = line_edit.text + xml += header[index] + ": " + line_edit_text + "\n" + index += 1 - for line_edit in data: - var line_edit_text = line_edit.text - file.store_line(line_edit_text) - #file.store_line("\n") - - - file.store_line("") - file.close() - print("Data saved to XML file:", path) + xml += "" + + + file.store_line(xml) + file.close() + print("Data saved to XML file: ", path) else: - print("Error opening file for writing:", path) + print("Error opening file for writing: ", path) + #save_user_data() + + +# var file = File.new() + +# if file.open("user://data.xml", File.WRITE) == OK: +# file.store_line("") +# file.store_line("") +# +# for line_edit in data: +# var line_edit_text = line_edit.text +# file.store_line(line_edit_text + "\n") +# +# +# file.store_line("") +# file.close() +# print("Data saved to XML file:", path) +# else: +# print("Error opening file for writing:", path) func create_array_to_save() -> Array: @@ -136,10 +149,23 @@ func create_array_to_save() -> Array: Strength, Quickness, Presence, Intuition, Empathy, Appearence] return userData + + +func create_header() -> Array: + + var headerData = ["CharacterName", "Profession", "Demeanor", "Species", "Culture", "Faction", "Description", "HeightAndWeight", + "Backstory", "Gender", "Equipment", "Charisma", "Dialog", "Constitution", "Agility", "SelfDisipline", "Memory", + "Reasoning","Strength", "Quickness", "Presence", "Intuition", "Empathy", "Appearance", "skill1", "skill2", "skill3", "skill4", + "skill5", "skill6", "skill7", "skill8", "skill9", "skill10", "special1", "special2", "special3", "special4", "special5", "special6", + "special7", "special8", "special9"] + + return headerData func _on_Button_pressed(): - save_data_to_xml(create_array_to_save(), file_path) + save_data_to_xml(create_array_to_save(), create_header(), file_path) +func _on_Button_tree_entered(): + pass