12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- extends Node
- const SAVE_PATH = "res://save.json"
- var _settings = {}
- #var nodes_to_save = []
- func _ready():
- # Called when the node is added to the scene for the first time.
- # Initialization here
- pass
- #fixme: better use node_path
- func save_node_data(node):
-
- var save_dict = {}
-
- if !node.is_queued_for_deletion( ):
- save_dict[node.get_path()] = node.save()
-
- var save_file = File.new()
- var path = "res://Saves/" + str(node.name) + ".json"
- save_file.open(path, File.WRITE)
-
- save_file.store_line(to_json(save_dict))
- save_file.close()
-
- func save_node_data_by_name(node, node_name):
-
- var save_dict = {}
-
- if !node.is_queued_for_deletion( ):
- save_dict[node.get_path()] = node.save()
-
- var save_file = File.new()
- var path = "res://Saves/" + node_name + ".json"
- save_file.open(path, File.WRITE)
-
- save_file.store_line(to_json(save_dict))
- save_file.close()
-
- func get_node_data_by_name(node_name):
-
- #print ("trying to find node data!!!")
-
- var save_file = File.new()
- var path = "res://Saves/" + node_name + ".json"
- if not save_file.file_exists(path):
- #print ("save path not found: " + str(path))
- return
-
-
- save_file.open(path, File.READ)
- var result_json = JSON.parse(save_file.get_as_text())
-
- if result_json.error == OK: # If parse OK
- var data = result_json.result
- #print(data)
- return data
- else: # If parse has errors
- print("Error: ", result_json.error)
- print("Error Line: ", result_json.error_line)
- print("Error String: ", result_json.error_string)
- return
-
|