extends Node

const SAVE_PATH: String = "user://saves/"
const SAVE_FILENAME: String = "saved_game.dat"

func save_game() -> void:
	DirAccess.make_dir_recursive_absolute(SAVE_PATH)
	
	var file := FileAccess.open(str(SAVE_PATH, SAVE_FILENAME), FileAccess.WRITE)
	
	# Store the variables.
	file.store_var(GameGlobals.spawn_index)


func load_game() -> bool:
	if not save_exists():
		return false
	
	var file := FileAccess.open(str(SAVE_PATH, SAVE_FILENAME), FileAccess.READ)
	
	# Load the variables.
	GameGlobals.spawn_index = file.get_var()
	
	return true


func delete_save() -> void:
	DirAccess.remove_absolute(str(SAVE_PATH, SAVE_FILENAME))


func save_exists() -> bool:
	return FileAccess.file_exists(str(SAVE_PATH, SAVE_FILENAME))
