mirror of
https://github.com/RPG-Research/bcirpg.git
synced 2024-04-16 14:23:01 +00:00
added basic save system
Added basic save system that has data to xml file.
This commit is contained in:
parent
8647c53da7
commit
4ab34a242b
@ -11,6 +11,7 @@ config_version=4
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="bcirpg_toolset"
|
config/name="bcirpg_toolset"
|
||||||
|
run/main_scene="res://screens/wizards/character_creation/character_creation_wizard.tscn"
|
||||||
config/icon="res://icon.png"
|
config/icon="res://icon.png"
|
||||||
|
|
||||||
[global]
|
[global]
|
||||||
|
@ -86,12 +86,12 @@ onready var special8 = $"RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/V
|
|||||||
|
|
||||||
onready var special9 = $"RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer/SBOptionButton9"
|
onready var special9 = $"RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/HBoxContainer/SpecialAbilitiesVBoxContainer/CenterContainer/GridContainer/SBOptionButton9"
|
||||||
|
|
||||||
# Save the data to a CSV file.
|
# 12/10/23 save the data to a xml file.
|
||||||
var rowData = [CharacterName, Profession, Demeanor, Species, Culture, Faction, Description, HeightAndWeight,
|
|
||||||
Backstory, Gender, Equipment, Charisma, Dialog, Constitution, Agility, SelfDisipline, Memory, Reasoning,
|
# comments for future skill sets to use
|
||||||
Strength, Quickness, Presence, Intuition, Empathy, Appearence, skill1, skill2, skill3, skill4, skill5,
|
# ,skill1, skill2, skill3, skill4, skill5,
|
||||||
skill6, skill7, skill8, skill9, skill10, special1, special2, special3, special4, special5, special6,
|
# skill6, skill7, skill8, skill9, skill10, special1, special2, special3, special4, special5, special6,
|
||||||
special7, special8, special9]
|
# special7, special8, special9
|
||||||
|
|
||||||
var headerData = ["CharacterName", "Profession", "Demeanor", "Species", "Culture", "Faction", "Description", "HeightAndWeight",
|
var headerData = ["CharacterName", "Profession", "Demeanor", "Species", "Culture", "Faction", "Description", "HeightAndWeight",
|
||||||
"Backstory", "Gender", "Equipment", "Charisma", "Dialog", "Constitution", "Agility", "SelfDisipline", "Memory",
|
"Backstory", "Gender", "Equipment", "Charisma", "Dialog", "Constitution", "Agility", "SelfDisipline", "Memory",
|
||||||
@ -103,37 +103,43 @@ var headerData = ["CharacterName", "Profession", "Demeanor", "Species", "Culture
|
|||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
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()
|
var file = File.new()
|
||||||
if file.open(file_path, File.WRITE) == OK:
|
|
||||||
for row in data:
|
if file.open("user://data.xml", File.WRITE) == OK:
|
||||||
file.store_string(format_row(row))
|
file.store_line("<?xml version=\"1.0\" encoding=\"utf-8\"?>")
|
||||||
|
file.store_line("<root>")
|
||||||
|
|
||||||
|
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("</root>")
|
||||||
file.close()
|
file.close()
|
||||||
print("Data saved to", file_path)
|
print("Data saved to XML file:", path)
|
||||||
else:
|
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:
|
func create_array_to_save() -> Array:
|
||||||
var data_to_save = [
|
var userData = [CharacterName, Profession, Demeanor, Species, Culture, Faction, Description, HeightAndWeight,
|
||||||
["Name", "Age", "Score"],
|
Backstory, Gender, Equipment, Charisma, Dialog, Constitution, Agility, SelfDisipline, Memory, Reasoning,
|
||||||
["John", 25, 85],
|
Strength, Quickness, Presence, Intuition, Empathy, Appearence]
|
||||||
["Alice", 30, 92],
|
|
||||||
["Bob", 28, 78],
|
|
||||||
]
|
|
||||||
|
|
||||||
var file_path = "user://data.csv" # Use 'user://' to save in the user data directory
|
|
||||||
|
|
||||||
|
return userData
|
||||||
|
|
||||||
func _on_Button_pressed():
|
func _on_Button_pressed():
|
||||||
var fileName = "character_data.csv"
|
save_data_to_xml(create_array_to_save(), file_path)
|
||||||
save_data_to_csv(data_to_save, file_path)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ script = ExtResource( 3 )
|
|||||||
[node name="ColorRect" type="ColorRect" parent="."]
|
[node name="ColorRect" type="ColorRect" parent="."]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
|
margin_top = -6.0
|
||||||
|
margin_bottom = -6.0
|
||||||
color = Color( 0.537255, 0.537255, 0.537255, 1 )
|
color = Color( 0.537255, 0.537255, 0.537255, 1 )
|
||||||
|
|
||||||
[node name="RootVBoxContainer" type="VBoxContainer" parent="."]
|
[node name="RootVBoxContainer" type="VBoxContainer" parent="."]
|
||||||
@ -684,3 +686,4 @@ margin_bottom = 368.0
|
|||||||
text = "Export Character To Module"
|
text = "Export Character To Module"
|
||||||
|
|
||||||
[connection signal="pressed" from="RootVBoxContainer/TopHBoxContainer/RightVBoxContainer/VBoxContainer/Button" to="." method="_on_Button_pressed"]
|
[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"]
|
||||||
|
Loading…
Reference in New Issue
Block a user