load groups meta

This commit is contained in:
Lera Elvoé 2023-05-27 06:35:16 +03:00
parent ee5f270bbe
commit 34dbb91570
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
4 changed files with 35 additions and 1 deletions

View File

@ -6,5 +6,6 @@ class_name GroupMetadata
@export var description: String @export var description: String
@export var installs: Array[InstallMetadata] @export var installs: Array[InstallMetadata]
@export var settings_overrides: Dictionary @export var settings_overrides: Dictionary
@export var index: int
signal save_request signal save_request

View File

@ -11,6 +11,15 @@ var groups: Dictionary = {}
func _ready() -> void: func _ready() -> void:
DirAccess.make_dir_absolute(GROUPS_BASE_FOLDER) 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: func create_group_folder(gm: GroupMetadata) -> void:
if gm in groups: if gm in groups:
@ -38,3 +47,13 @@ func group_metadata_should_save(gm: GroupMetadata) -> void:
var save_err := ResourceSaver.save(gm, path) var save_err := ResourceSaver.save(gm, path)
if save_err != OK: if save_err != OK:
print("couldn't save resource, error ", save_err) 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

View File

@ -116,7 +116,8 @@ func set_children_visible(p_visible: bool) -> void:
add_install_button_container.visible = p_visible add_install_button_container.visible = p_visible
inner_separator.visible = p_visible inner_separator.visible = p_visible
description_label.visible = p_visible && !description_label.text.is_empty() 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: func add_custom(control: Control) -> void:
@ -156,6 +157,8 @@ func setup_from_metadata(p_group_metadata: GroupMetadata) -> void:
group_metadata = p_group_metadata group_metadata = p_group_metadata
set_text(p_group_metadata.name) set_text(p_group_metadata.name)
set_description(group_metadata.description) set_description(group_metadata.description)
set_children_visible(!group_metadata.get_meta("collapsed", false))
group_metadata.index = get_index()
# TODO: add installs # TODO: add installs
# TODO: add icon # TODO: add icon

View File

@ -16,6 +16,9 @@ func _ready() -> void:
group_edit_dialog.canceled.connect(group_edit_dialog.clear_ok_button_connections) 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: func add_new_group() -> void:
group_edit_dialog.clear() group_edit_dialog.clear()
@ -51,3 +54,11 @@ func edit_group(group_menu: GroupMenu) -> void:
, CONNECT_ONE_SHOT) , CONNECT_ONE_SHOT)
group_edit_dialog.show() 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))