extends RefCounted ## Shared by production loading and isolated on-disk QA round trips. static func valid_flags(value: Variant, known: Dictionary) -> Dictionary: var flags: Dictionary = {} if value is Dictionary: for key in value: if key is String and known.has(key) and value[key] is bool and value[key]: flags[key] = true return flags static func read_profile(path: String, facts: Dictionary, outcomes: Dictionary) -> Dictionary: var cfg := ConfigFile.new() var status := cfg.load(path) var loops: Variant = cfg.get_value("save", "loops", 0) if status == OK else 0 return { "status": status, "facts": valid_flags(cfg.get_value("save", "facts", {}), facts) if status == OK else {}, "endings": valid_flags(cfg.get_value("save", "endings", {}), outcomes) if status == OK else {}, "loops": maxi(0, loops) if loops is int else 0, } static func write_profile(path: String, facts: Dictionary, endings: Dictionary, loops: int) -> Error: var status := DirAccess.make_dir_recursive_absolute(path.get_base_dir()) if status != OK: return status var cfg := ConfigFile.new() cfg.set_value("save", "facts", facts) cfg.set_value("save", "endings", endings) cfg.set_value("save", "loops", loops) var temporary := path + ".tmp" status = cfg.save(temporary) if status != OK: return status # Rename replaces the destination only after the complete new file was written. return DirAccess.rename_absolute(temporary, path)