feat: base

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
2025-07-15 00:46:55 +02:00
commit bcfc8fbc81
20 changed files with 498 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
extends Node
signal money_changed(new_money)
var _save_dir := "user://saves"
var data := {
"money": 1000,
"day": 1
}
func list_saves():
var dir := DirAccess.open("user://saves")
var saves = dir.get_files()
var res: Array[Save] = []
for save in saves:
res.append(Save.new())
func add_money(amount):
data.money += amount
emit_signal("money_changed", data.money)
var save_path = "user://save.bin"
func save_save():
var file = FileAccess.open(save_path, FileAccess.WRITE)
file.store_buffer(JSONPacker.encode(data))
func load_save(path: String):
if FileAccess.file_exists(path):
var file = FileAccess.open(path, FileAccess.READ)
data = JSONPacker.decode(file.get_buffer(file.get_length()))
return true
return false
func _init() -> void:
load_state()
func _notification(what):
if what == NOTIFICATION_WM_CLOSE_REQUEST:
save_state()
get_tree().quit() # default behavior