fix some error and add a remove function

master
Can202 2021-05-31 19:53:55 -04:00
parent 7adc42a3aa
commit d5aa46e3be
3 changed files with 36 additions and 9 deletions

View File

@ -64,22 +64,23 @@ func save_data(var data : Dictionary, var profile : String = "save", var typefil
thefile.close()
if print_in_terminal:
print("Saved:")
print(str(data))
print("Saved: " + str(data))
func edit_data(var profile : String = "save", var typefile : String = ".sav"):
create_folder(res_user, folder_name)
var thefile = File.new()
var data = {}
if profile == "":
profile = "save"
if (!thefile.file_exists(res_user + folder_name + "/" + profile + typefile)):
var path = str(res_user + folder_name + "/" + profile + typefile)
if (!thefile.file_exists(path)):
if print_in_terminal:
print("the file doesn't exist yet, return empty dictionary")
else:
thefile.open(res_user + folder_name + "/" + profile + typefile, File.READ)
thefile.open(path, File.READ)
if !thefile.eof_reached():
var almost_data = parse_json(thefile.get_line())
if almost_data != null:
@ -99,8 +100,7 @@ func save_data_in_folder(var data : Dictionary, var resuser : String, var folder
thefile.close()
if print_in_terminal:
print("Saved:")
print(str(data))
print("Saved: " + str(data))
func edit_data_in_folder(var resuser : String, var folder : String, var profile : String = "save", var typefile : String = ".sav"):
@ -110,18 +110,30 @@ func edit_data_in_folder(var resuser : String, var folder : String, var profile
var data = {}
if profile == "":
profile = "save"
if (!thefile.file_exists(res_user + folder_name + "/" + profile + typefile)):
var path = str(resuser + folder + "/" + profile + typefile)
if (!thefile.file_exists(path)):
if print_in_terminal:
print("the file doesn't exist yet, return empty dictionary")
else:
thefile.open(resuser + folder + "/" + profile + typefile, File.READ)
thefile.open(path, File.READ)
if !thefile.eof_reached():
var almost_data = parse_json(thefile.get_line())
if almost_data != null:
data = almost_data
return data
func remove_data(var profile : String = "save", var typefile : String = ".sav"):
var dir = Directory.new()
var path = str(res_user + folder_name + "/" + profile + typefile)
dir.remove(path)
if print_in_terminal:
print(path + " removed")
func remove_data_in_folder(var resuser : String, var folder : String, var profile : String = "save", var typefile : String = ".sav"):
var dir = Directory.new()
var path = str(resuser + folder + "/" + profile + typefile)
dir.remove(path)
if print_in_terminal:
print(path + " removed")
#This is modified by me (Can202), but the author is fractilegames
#GitHub: https://github.com/fractilegames/godot-screenshot-queue

View File

@ -37,3 +37,7 @@ func _load():
func _on_save_pressed():
_save()
func _on_Button_pressed():
Addonsave.remove_data_in_folder("res://", "settings", "quality", ".txt")

View File

@ -37,4 +37,15 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" type="Button" parent="Node2D"]
margin_left = 204.0
margin_top = 268.0
margin_right = 339.0
margin_bottom = 288.0
text = "reset configuration"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="Node2D/save" to="." method="_on_save_pressed"]
[connection signal="pressed" from="Node2D/Button" to="." method="_on_Button_pressed"]