SleepyClock/Data.gd
2026-05-31 20:56:40 +10:00

47 lines
1.1 KiB
GDScript

extends Node
@export var save : SleepyclockSave
@export var path : String = "user://sleepyclockSave.tres"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print("looking for save...")
if not load_data():
print ("no save detected... creating new save")
new_data()
else:
print("found it! loading now...")
load_data()
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
# returns true if new data created and saved
func new_data() -> bool:
save = SleepyclockSave.new()
var error = ResourceSaver.save(save,path)
if error != OK:
print(error)
return false
return true
# returns true if data successfully loaded into save
func load_data() -> bool:
if not FileAccess.file_exists(path):
return false
else:
save = ResourceLoader.load(path)
return true
# returns true if data successfully saved
func save_data() -> bool:
var error = ResourceSaver.save(save,path)
if error != OK:
print(error)
return false
return true