SleepyClock/Data.gd

69 lines
1.4 KiB
GDScript3
Raw Normal View History

2026-05-31 20:56:40 +10:00
extends Node
@export var save : SleepyclockSave
@export var path : String = "user://sleepyclockSave.tres"
2026-06-01 12:21:11 +10:00
enum Position {
Bottom,
Right,
Top,
Left,
}
2026-06-01 17:10:16 +10:00
enum Styles {
Filling,
Filling_Reversed,
Emptying,
Emptying_Reversed,
}
2026-05-31 20:56:40 +10:00
# 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()
2026-06-01 12:21:11 +10:00
var screen_size : Vector2i = DisplayServer.screen_get_size() # get current screen size
if screen_size.x > 2560 or screen_size.y > 1440:
save.size = 20
if OS.has_feature("macos"):
save.position = Data.Position.Right
2026-05-31 20:56:40 +10:00
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:
2026-06-01 12:21:11 +10:00
save = ResourceLoader.load(path,"",ResourceLoader.CACHE_MODE_IGNORE)
2026-05-31 20:56:40 +10:00
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