extends Node

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

var flags: Flags

func _ready():
	if '--reset' in OS.get_cmdline_args():
		flags = Flags.new()
		save_flags()

	load_flags()
	if flags == null:
		flags = Flags.new()
		flags.changed.connect(_flags_updated)
		save_flags()

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

func save_flags(path: String = "user://flags.tres"):
	print("save to ", path)
	if OK == ResourceSaver.save(flags, path):
		saved.emit()

func _flags_updated():
	changed.emit()
	save_flags()
