save and load installs
This commit is contained in:
parent
34dbb91570
commit
f942c91cf6
@ -4,7 +4,7 @@ class_name GroupMetadata
|
||||
@export var name: String
|
||||
@export var icon_path: String
|
||||
@export var description: String
|
||||
@export var installs: Array[InstallMetadata]
|
||||
@export var installs: Array[Dictionary]
|
||||
@export var settings_overrides: Dictionary
|
||||
@export var index: int
|
||||
|
||||
|
@ -1,7 +1,30 @@
|
||||
extends Resource
|
||||
class_name InstallMetadata
|
||||
|
||||
@export var name: String
|
||||
@export var icon_path: String
|
||||
@export var binary_path: String
|
||||
@export var local_overrides: Dictionary
|
||||
var name: String
|
||||
var icon_path: String
|
||||
var binary_path: String
|
||||
var local_overrides: Dictionary
|
||||
var pids: Array[int] = []
|
||||
var index: int = 0
|
||||
|
||||
|
||||
func to_d() -> Dictionary:
|
||||
return {
|
||||
"name": name,
|
||||
"icon_path": icon_path,
|
||||
"binary_path": binary_path,
|
||||
"local_overrides": local_overrides,
|
||||
"pids": pids,
|
||||
"index": index,
|
||||
}
|
||||
|
||||
|
||||
static func from_d(d: Dictionary) -> InstallMetadata:
|
||||
var res := InstallMetadata.new()
|
||||
res.name = d.get("name", "")
|
||||
res.icon_path = d.get("icon_path", "")
|
||||
res.binary_path = d.get("binary_path", "")
|
||||
res.local_overrides = d.get("local_overrides", {})
|
||||
res.pids = d.get("pids", [])
|
||||
res.index = d.get("index", 0)
|
||||
return res
|
||||
|
@ -54,13 +54,23 @@ func add_new_install() -> void:
|
||||
child_container.add_child(install_item)
|
||||
install_item.setup_from_metadata(im)
|
||||
install_item.edit_item_button_pressed.connect(edit_install.bind(install_item))
|
||||
group_metadata.installs.append(im)
|
||||
im.index = group_metadata.installs.size()
|
||||
group_metadata.installs.append(im.to_d())
|
||||
group_metadata.save_request.emit()
|
||||
install_item.about_to_delete.connect(_on_install_item_about_to_delete)
|
||||
, CONNECT_ONE_SHOT)
|
||||
|
||||
install_edit_dialog.show()
|
||||
|
||||
|
||||
func add_install_from_metadata(im: InstallMetadata) -> void:
|
||||
var install_item: InstallItem = ITEM_SCENE.instantiate()
|
||||
child_container.add_child(install_item)
|
||||
install_item.setup_from_metadata(im)
|
||||
install_item.about_to_delete.connect(_on_install_item_about_to_delete)
|
||||
install_item.edit_item_button_pressed.connect(edit_install.bind(install_item))
|
||||
|
||||
|
||||
func edit_install(install_item: InstallItem) -> void:
|
||||
install_edit_dialog.clear()
|
||||
install_edit_dialog.ok_button_text = "OK"
|
||||
@ -159,7 +169,11 @@ func setup_from_metadata(p_group_metadata: GroupMetadata) -> void:
|
||||
set_description(group_metadata.description)
|
||||
set_children_visible(!group_metadata.get_meta("collapsed", false))
|
||||
group_metadata.index = get_index()
|
||||
# TODO: add installs
|
||||
|
||||
# add installs
|
||||
for i in group_metadata.installs:
|
||||
add_install_from_metadata(InstallMetadata.from_d(i))
|
||||
|
||||
# TODO: add icon
|
||||
|
||||
|
||||
@ -174,3 +188,12 @@ func _on_header_text_label_gui_input(event: InputEvent) -> void:
|
||||
func _on_delete_button_pressed() -> void:
|
||||
GroupsInstallsManager.delete_group_folder(group_metadata)
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_install_item_about_to_delete(im: InstallMetadata) -> void:
|
||||
group_metadata.installs.remove_at(im.index)
|
||||
for i in group_metadata.installs.size():
|
||||
group_metadata.installs[i]["index"] = i
|
||||
(child_container.get_child(i) as InstallItem).install_metadata.index = i
|
||||
|
||||
group_metadata.save_request.emit()
|
||||
|
@ -10,15 +10,15 @@ class_name InstallItem
|
||||
var install_metadata: InstallMetadata
|
||||
|
||||
signal edit_item_button_pressed
|
||||
signal delete_item_button_pressed
|
||||
signal launch_item_button_pressed
|
||||
signal about_to_delete(install_metadata: InstallMetadata)
|
||||
|
||||
signal name_changed(new_name: String)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
edit_item_button.pressed.connect(func(): edit_item_button_pressed.emit())
|
||||
delete_item_button.pressed.connect(func(): delete_item_button_pressed.emit())
|
||||
delete_item_button.pressed.connect(_on_delete_button_pressed)
|
||||
|
||||
name_label.gui_input.connect(_on_name_label_gui_input)
|
||||
|
||||
@ -71,3 +71,8 @@ func setup_from_metadata(p_metadata: InstallMetadata) -> void:
|
||||
install_metadata = p_metadata
|
||||
set_text(install_metadata.name)
|
||||
# TODO: add icon
|
||||
|
||||
|
||||
func _on_delete_button_pressed() -> void:
|
||||
about_to_delete.emit(install_metadata)
|
||||
queue_free()
|
||||
|
Loading…
Reference in New Issue
Block a user