extends Node const GROUPS_BASE_FOLDER := "user://groups" const METADATA_FILENAME := "meta.tres" # key: GroupMetadata # value: String = UUID var groups: Dictionary = {} func _ready() -> void: DirAccess.make_dir_absolute(GROUPS_BASE_FOLDER) var d := DirAccess.open(GROUPS_BASE_FOLDER) d.list_dir_begin() var current_folder := d.get_next() while current_folder != "": var res_path := GROUPS_BASE_FOLDER.path_join(current_folder).path_join(METADATA_FILENAME) var gm: GroupMetadata = ResourceLoader.load(res_path, "GroupMetadata") groups[gm] = current_folder current_folder = d.get_next() func create_group_folder(gm: GroupMetadata) -> void: if gm in groups: return var folder_name := UUID.v4() var d := DirAccess.open(GROUPS_BASE_FOLDER) d.make_dir(folder_name) groups[gm] = folder_name gm.save_request.connect(group_metadata_should_save.bind(gm)) func delete_group_folder(gm: GroupMetadata) -> void: if !groups.has(gm): return var path := ProjectSettings.globalize_path(GROUPS_BASE_FOLDER.path_join(groups[gm])) OS.move_to_trash(path) groups.erase(gm) func group_metadata_should_save(gm: GroupMetadata) -> void: var path := GROUPS_BASE_FOLDER.path_join(groups[gm]).path_join(METADATA_FILENAME) var save_err := ResourceSaver.save(gm, path) if save_err != OK: print("couldn't save resource, error ", save_err) func get_all_group_metadatas() -> Array[GroupMetadata]: var res: Array[GroupMetadata] res.assign(groups.keys()) res.sort_custom( func(a: GroupMetadata, b: GroupMetadata): return a.index < b.index ) return res