save groups meta

This commit is contained in:
2023-05-27 05:54:11 +03:00
parent 14b56cf5ed
commit 97b1aad886
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)