extends Node

signal changed()
signal saved()
signal loaded()

var flags:Flags

func _ready():
	if '--reset' in OS.get_cmdline_args():#or true:
		flags = Flags.new()
		save_flags()
	
	load_flags()
	if flags == null:
		flags = Flags.new()
		flags.connect("changed", self, "_flags_updated")
		save_flags()

func load_flags(path:="user://flags.tres"):
	print("load from ",path)
	var newflags = ResourceLoader.load(path)
	if newflags != null:
		flags = newflags
		flags.connect("changed", self, "_flags_updated")
		emit_signal("loaded")
#		print("ok")

func save_flags(path:="user://flags.tres"):
	print("save to ",path)
	if OK == ResourceSaver.save(path, flags):
		emit_signal("saved")
#		print('ok')

func _flags_updated():
	emit_signal("changed")
	save_flags()
