41 lines
993 B
GDScript
41 lines
993 B
GDScript
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)
|
|
|
|
|
|
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)
|