2023-07-23 18:55:33 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
2023-08-06 17:37:50 +00:00
|
|
|
const SAVEGAME = "user://Savegame.json"
|
2023-07-23 18:55:33 +00:00
|
|
|
|
|
|
|
var save_data = {}
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
save_data = get_data()
|
2023-08-06 17:37:50 +00:00
|
|
|
|
2023-07-23 18:55:33 +00:00
|
|
|
func get_data():
|
|
|
|
var file = File.new()
|
|
|
|
|
2023-08-06 17:37:50 +00:00
|
|
|
if not file.file_exists(SAVEGAME):
|
|
|
|
save_data = {"Player_name": "Unnamed"}
|
2023-07-23 18:55:33 +00:00
|
|
|
save_game()
|
2023-08-06 17:37:50 +00:00
|
|
|
file.open(SAVEGAME, File.READ)
|
2023-07-23 18:55:33 +00:00
|
|
|
var content = file.get_as_text()
|
|
|
|
var data = parse_json(content)
|
|
|
|
save_data = data
|
|
|
|
file.close()
|
|
|
|
return(data)
|
|
|
|
|
|
|
|
func save_game():
|
|
|
|
var save_game = File.new()
|
2023-08-06 17:37:50 +00:00
|
|
|
save_game.open(SAVEGAME, File.WRITE)
|
2023-07-23 18:55:33 +00:00
|
|
|
save_game.store_line(to_json(save_data))
|
2023-08-06 17:37:50 +00:00
|
|
|
|