@tool
class_name Save
extends Resource


enum Difficulty {EASY, NORMAL, HARD}
enum Projectile {BLAST, FIRE, ICE, LASER}


@export var slot: int = 1
@export var playtime: int = 0
@export var difficulty: Difficulty = Difficulty.NORMAL
@export var max_health: int = 100
@export var xp: int = 0
@export var room: String = "labs"

@export var atk: int = 1
@export var def: int = 1
@export var con: int = 1
@export var chg: int = 1

@export var projectile: Projectile = Projectile.BLAST;

@export var fire: bool = false
@export var ice: bool = false
@export var laser: bool = false
@export var roll: bool = false
@export var wall: bool = false
@export var pound: bool = false
@export var slice: bool = false

@export var lock_1: bool = false
@export var lock_2: bool = false
@export var lock_3: bool = false


func _init(save_slot: int):
	self.slot = save_slot


func save_to_disk() -> Error:
	return ResourceSaver.save(self, "user://slot_%s.res" % self.slot)


static func exists(save_slot: int) -> bool:
	return ResourceLoader.exists("user://slot_%s.res" % save_slot)


static func load(save_slot: int) -> Save:
	if exists(save_slot):
		var save_data = ResourceLoader.load("user://slot_%s.res" % save_slot)
		if save_data is Save:
			return save_data
	return null
