yagvm/Classes/GroupsInstallsManager.gd

41 lines
993 B
GDScript3
Raw Normal View History

2023-05-27 02:54:11 +00:00
extends Node
const GROUPS_BASE_FOLDER := "user://groups"
const METADATA_FILENAME := "meta.tres"
# key: GroupMetadata
2023-05-27 03:08:36 +00:00
# value: String = UUID
2023-05-27 02:54:11 +00:00
var groups: Dictionary = {}
func _ready() -> void:
DirAccess.make_dir_absolute(GROUPS_BASE_FOLDER)
func create_group_folder(gm: GroupMetadata) -> void:
2023-05-27 03:08:36 +00:00
if gm in groups:
2023-05-27 02:54:11 +00:00
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))
2023-05-27 03:08:36 +00:00
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)
2023-05-27 02:54:11 +00:00
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)