extends Node

@warning_ignore("unused_signal")
signal on_game_paused
@warning_ignore("unused_signal")
signal on_game_resumed
@warning_ignore("unused_signal")
signal on_photo_highlighted(teture: Texture)

const SAVE_PATH: String = "user://savegame.json"

var save_data: SaveGameData = SaveGameData.new()
var is_loaded: bool = false

func _ready() -> void:
	load_game()

func save_game() -> void:
	var save_file = FileAccess.open(SAVE_PATH, FileAccess.WRITE)
	var json_string = JSON.stringify(save_data.to_dictionary())
	save_file.store_line(json_string)

func load_game() -> void:
	if not FileAccess.file_exists(SAVE_PATH):
		save_data = SaveGameData.new()
		is_loaded = true
		return
		
	var file = FileAccess.open(SAVE_PATH, FileAccess.READ)
	var json_string = file.get_as_text()
	
	var json = JSON.new()
	var parse_result = json.parse(json_string)
	
	save_data = SaveGameData.new()
	if parse_result == OK and json.data is Dictionary:
		save_data = SaveGameData.from_dictionary(json.data)
	
	is_loaded = true

func pause_game() -> void:
	get_tree().paused = true

func resume_game() -> void:
	get_tree().paused = false

func quit_game() -> void:
	get_tree().quit()
