extends Node

# Use user://save.json to automatically use user app config folders
# Leaving as res to avoid storing json files for test games
const SAVE_DATA_PATH = "res://save.json"

var default_save_data = {
	"hi_score": 0
}

func store_save_data(data):
	var save_file = File.new()
	save_file.open(SAVE_DATA_PATH, File.WRITE)
	save_file.store_line(to_json(data))
	save_file.close()

func load_save_data():
	var save_file = File.new()
	
	if not save_file.file_exists(SAVE_DATA_PATH):
		store_save_data(default_save_data)
		return default_save_data

	save_file.open(SAVE_DATA_PATH, File.READ)
	var save_data = parse_json(save_file.get_as_text())
	save_file.close()

	return save_data
