yagvm/Classes/GroupsInstallsManager.gd

32 lines
789 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
# values: String = UUID
var groups: Dictionary = {}
func _ready() -> void:
DirAccess.make_dir_absolute(GROUPS_BASE_FOLDER)
func create_group_folder(gm: GroupMetadata) -> void:
if gm in groups.values():
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 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)