load groups meta
This commit is contained in:
parent
ee5f270bbe
commit
34dbb91570
@ -6,5 +6,6 @@ class_name GroupMetadata
|
||||
@export var description: String
|
||||
@export var installs: Array[InstallMetadata]
|
||||
@export var settings_overrides: Dictionary
|
||||
@export var index: int
|
||||
|
||||
signal save_request
|
||||
|
@ -11,6 +11,15 @@ 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:
|
||||
@ -38,3 +47,13 @@ func group_metadata_should_save(gm: GroupMetadata) -> void:
|
||||
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
|
||||
|
@ -116,7 +116,8 @@ func set_children_visible(p_visible: bool) -> void:
|
||||
add_install_button_container.visible = p_visible
|
||||
inner_separator.visible = p_visible
|
||||
description_label.visible = p_visible && !description_label.text.is_empty()
|
||||
group_metadata.set_meta("collapsed", p_visible)
|
||||
group_metadata.set_meta("collapsed", !p_visible)
|
||||
group_metadata.save_request.emit()
|
||||
|
||||
|
||||
func add_custom(control: Control) -> void:
|
||||
@ -156,6 +157,8 @@ func setup_from_metadata(p_group_metadata: GroupMetadata) -> void:
|
||||
group_metadata = p_group_metadata
|
||||
set_text(p_group_metadata.name)
|
||||
set_description(group_metadata.description)
|
||||
set_children_visible(!group_metadata.get_meta("collapsed", false))
|
||||
group_metadata.index = get_index()
|
||||
# TODO: add installs
|
||||
# TODO: add icon
|
||||
|
||||
|
@ -16,6 +16,9 @@ func _ready() -> void:
|
||||
|
||||
group_edit_dialog.canceled.connect(group_edit_dialog.clear_ok_button_connections)
|
||||
|
||||
for gm in GroupsInstallsManager.get_all_group_metadatas():
|
||||
add_group_from_metadata(gm)
|
||||
|
||||
|
||||
func add_new_group() -> void:
|
||||
group_edit_dialog.clear()
|
||||
@ -51,3 +54,11 @@ func edit_group(group_menu: GroupMenu) -> void:
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
group_edit_dialog.show()
|
||||
|
||||
|
||||
func add_group_from_metadata(gm: GroupMetadata) -> void:
|
||||
var group_menu: GroupMenu = GROUP_MENU_SCENE.instantiate()
|
||||
group_menus_container.add_child(group_menu)
|
||||
group_menu.setup_from_metadata(gm)
|
||||
|
||||
group_menu.edit_group_button_pressed.connect(edit_group.bind(group_menu))
|
||||
|
Loading…
Reference in New Issue
Block a user