save groups meta

This commit is contained in:
Lera Elvoé 2023-05-27 05:54:11 +03:00
parent 14b56cf5ed
commit 97b1aad886
Signed by: yagich
SSH Key Fingerprint: SHA256:6xjGb6uA7lAVcULa7byPEN//rQ0wPoG+UzYVMfZnbvc
7 changed files with 46 additions and 4 deletions

View File

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

View File

@ -0,0 +1,31 @@
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)

View File

@ -22,9 +22,11 @@
# Note: The code might not be as pretty it could be, since it's written
# in a way that maximizes performance. Methods are inlined and loops are avoided.
class_name UUID
const BYTE_MASK: int = 0b11111111
static func uuidbin():
static func uuidbin() -> Array:
randomize()
# 16 random bytes with the bytes on index 6 and 8 modified
return [
@ -34,7 +36,7 @@ static func uuidbin():
randi() & BYTE_MASK, randi() & BYTE_MASK, randi() & BYTE_MASK, randi() & BYTE_MASK,
]
static func uuidbinrng(rng: RandomNumberGenerator):
static func uuidbinrng(rng: RandomNumberGenerator) -> Array:
rng.randomize()
return [
rng.randi() & BYTE_MASK, rng.randi() & BYTE_MASK, rng.randi() & BYTE_MASK, rng.randi() & BYTE_MASK,
@ -43,7 +45,7 @@ static func uuidbinrng(rng: RandomNumberGenerator):
rng.randi() & BYTE_MASK, rng.randi() & BYTE_MASK, rng.randi() & BYTE_MASK, rng.randi() & BYTE_MASK,
]
static func v4():
static func v4() -> String:
# 16 random bytes with the bytes on index 6 and 8 modified
var b = uuidbin()
@ -64,7 +66,7 @@ static func v4():
b[10], b[11], b[12], b[13], b[14], b[15]
]
static func v4_rng(rng: RandomNumberGenerator):
static func v4_rng(rng: RandomNumberGenerator) -> String:
# 16 random bytes with the bytes on index 6 and 8 modified
var b = uuidbinrng(rng)

View File

@ -56,6 +56,7 @@ func add_new_install() -> void:
install_item.setup_from_metadata(im)
install_item.edit_item_button_pressed.connect(edit_install.bind(install_item))
group_metadata.installs.append(im)
group_metadata.save_request.emit()
, CONNECT_ONE_SHOT)
install_edit_dialog.show()
@ -144,6 +145,7 @@ func setup_rename() -> void:
func(new_text: String):
header_text_label.text = new_text
group_metadata.name = new_text
group_metadata.save_request.emit()
reenable.call()
)

View File

@ -23,6 +23,8 @@ func get_group_metadata() -> GroupMetadata:
group_metadata.settings_overrides = override_editor_settings_menu.get_overrides()
group_metadata.name = name_line_edit.text
group_metadata.save_request.emit()
return group_metadata

View File

@ -30,6 +30,8 @@ func add_new_group() -> void:
group_menu.setup_from_metadata(gm)
group_menu.edit_group_button_pressed.connect(edit_group.bind(group_menu))
GroupsInstallsManager.create_group_folder(gm)
GroupsInstallsManager.group_metadata_should_save(gm)
, CONNECT_ONE_SHOT)

View File

@ -21,6 +21,7 @@ config/icon="res://icon.svg"
DotEnv="*res://Classes/DotEnv.gd"
ReleasesManager="*res://Classes/ReleasesManager.gd"
GroupsInstallsManager="*res://Classes/GroupsInstallsManager.gd"
[display]