make the default library group location be based on the executable location (#164)

closes #163

Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/164
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-05-26 16:05:22 +00:00 committed by yagich
parent f720efcc72
commit ac6ede2b41
5 changed files with 22 additions and 12 deletions

5
.gitignore vendored
View file

@ -5,4 +5,7 @@
dist/*/ dist/*/
# vscode folder # vscode folder
.vscode/ .vscode/
# lib groups folder
library_groups/

View file

@ -95,7 +95,7 @@ static func create_lib_descriptors(path: String) -> void:
current_file = dir.get_next() current_file = dir.get_next()
continue continue
if libraries.has(type): if libraries.has(type):
DeckHolder.logger.toast_error("Library group '%s' collides with a library group with the same type." % type) DeckHolder.logger.toast_error("Library group '%s' is already added by a different library." % type)
current_file = dir.get_next() current_file = dir.get_next()
continue continue
var lib = deck.deck.library var lib = deck.deck.library
@ -121,7 +121,7 @@ static func create_lib_descriptors(path: String) -> void:
static func reload_libraries() -> void: static func reload_libraries() -> void:
libraries.clear() libraries.clear()
for path in StreamGraphConfig.get_library_search_paths(): for path in StreamGraphConfig.get_library_search_paths():
create_lib_descriptors(path) create_lib_descriptors(Util.globalize_path(path))
## Instantiates a [DeckNode] from a given [param node_type]. See [member DeckNode.node_type]. ## Instantiates a [DeckNode] from a given [param node_type]. See [member DeckNode.node_type].

View file

@ -5,9 +5,7 @@ class_name StreamGraphConfig
static var config := { static var config := {
&"library_search_paths": [ &"library_search_paths": [],
ProjectSettings.globalize_path("user://library_groups"),
],
} }
const SAVE_PATH := "user://config.json" const SAVE_PATH := "user://config.json"
@ -53,7 +51,7 @@ static func add_library_search_path(path: String) -> void:
static func remove_library_search_path(path: String) -> void: static func remove_library_search_path(path: String) -> void:
var arr: Array = config[&"library_search_paths"] var arr: Array = config[&"library_search_paths"]
if arr.find(path) < 1: if arr.find(path) < 0:
return return
arr.erase(path) arr.erase(path)
NodeDB.reload_libraries() NodeDB.reload_libraries()
@ -63,7 +61,7 @@ static func remove_library_search_path(path: String) -> void:
static func rename_library_search_path(old_path: String, new_path: String) -> void: static func rename_library_search_path(old_path: String, new_path: String) -> void:
var arr: Array = config[&"library_search_paths"] var arr: Array = config[&"library_search_paths"]
var idx := arr.find(old_path) var idx := arr.find(old_path)
if idx < 1: if idx < 0:
return return
arr[idx] = new_path arr[idx] = new_path
@ -74,7 +72,7 @@ static func rename_library_search_path(old_path: String, new_path: String) -> vo
static func move_library_path_up(path: String) -> void: static func move_library_path_up(path: String) -> void:
var arr: Array = config[&"library_search_paths"] var arr: Array = config[&"library_search_paths"]
var idx := arr.find(path) var idx := arr.find(path)
if idx < 1: if idx < 0:
return return
var old_path = arr[idx] var old_path = arr[idx]
@ -87,7 +85,7 @@ static func move_library_path_up(path: String) -> void:
static func move_library_path_down(path: String) -> void: static func move_library_path_down(path: String) -> void:
var arr: Array = config[&"library_search_paths"] var arr: Array = config[&"library_search_paths"]
var idx := arr.find(path) var idx := arr.find(path)
if idx < 1 or idx == arr.size() - 1: if idx < 0 or idx == arr.size() - 1:
return return
var old_path = arr[idx] var old_path = arr[idx]
@ -98,7 +96,9 @@ static func move_library_path_down(path: String) -> void:
static func get_library_search_paths() -> Array: static func get_library_search_paths() -> Array:
return config[&"library_search_paths"] var res := ["{$PWD}/library_groups"]
res.append_array(config[&"library_search_paths"])
return res
static func save() -> void: static func save() -> void:

View file

@ -39,6 +39,13 @@ static func pop_batch(key: StringName) -> void:
_batches.erase(key) _batches.erase(key)
## Customized version of [method ProjectSettings.globalize_path] that handles
## a [code]$PWD[/code] template which points to the current working folder.
static func globalize_path(path: String) -> String:
var pwd: String = ProjectSettings.globalize_path("res://").trim_suffix("/") if OS.has_feature("editor") else OS.get_executable_path().get_base_dir()
return path.format({"$PWD": pwd})
## An object representing multiple connections. ## An object representing multiple connections.
## ##
## Useful when there's a need to connect multiple signals in one operation, to be disconnected later. ## Useful when there's a need to connect multiple signals in one operation, to be disconnected later.

View file

@ -94,7 +94,7 @@ class FolderView extends HBoxContainer:
is_default = p_default is_default = p_default
label = Label.new() label = Label.new()
label.text = path label.text = path.replace("$PWD", "app directory")
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
label.clip_text = true label.clip_text = true
label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS