From ac6ede2b419afd3f3d444832d549029a90c00e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sun, 26 May 2024 16:05:22 +0000 Subject: [PATCH] make the default library group location be based on the executable location (#164) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #163 Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/164 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- .gitignore | 5 ++++- classes/deck/node_db.gd | 4 ++-- classes/stream_graph_config.gd | 16 ++++++++-------- classes/util.gd | 7 +++++++ .../settings/library_group_paths_editor.gd | 2 +- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 313e7a2..5241be9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ dist/*/ # vscode folder -.vscode/ \ No newline at end of file +.vscode/ + +# lib groups folder +library_groups/ diff --git a/classes/deck/node_db.gd b/classes/deck/node_db.gd index dda32d0..b057aa8 100644 --- a/classes/deck/node_db.gd +++ b/classes/deck/node_db.gd @@ -95,7 +95,7 @@ static func create_lib_descriptors(path: String) -> void: current_file = dir.get_next() continue 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() continue var lib = deck.deck.library @@ -121,7 +121,7 @@ static func create_lib_descriptors(path: String) -> void: static func reload_libraries() -> void: libraries.clear() 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]. diff --git a/classes/stream_graph_config.gd b/classes/stream_graph_config.gd index 9509fd6..f9f60c8 100644 --- a/classes/stream_graph_config.gd +++ b/classes/stream_graph_config.gd @@ -5,9 +5,7 @@ class_name StreamGraphConfig static var config := { - &"library_search_paths": [ - ProjectSettings.globalize_path("user://library_groups"), - ], + &"library_search_paths": [], } 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: var arr: Array = config[&"library_search_paths"] - if arr.find(path) < 1: + if arr.find(path) < 0: return arr.erase(path) 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: var arr: Array = config[&"library_search_paths"] var idx := arr.find(old_path) - if idx < 1: + if idx < 0: return 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: var arr: Array = config[&"library_search_paths"] var idx := arr.find(path) - if idx < 1: + if idx < 0: return 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: var arr: Array = config[&"library_search_paths"] var idx := arr.find(path) - if idx < 1 or idx == arr.size() - 1: + if idx < 0 or idx == arr.size() - 1: return 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: - return config[&"library_search_paths"] + var res := ["{$PWD}/library_groups"] + res.append_array(config[&"library_search_paths"]) + return res static func save() -> void: diff --git a/classes/util.gd b/classes/util.gd index 7b950bc..b40f353 100644 --- a/classes/util.gd +++ b/classes/util.gd @@ -39,6 +39,13 @@ static func pop_batch(key: StringName) -> void: _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. ## ## Useful when there's a need to connect multiple signals in one operation, to be disconnected later. diff --git a/graph_node_renderer/settings/library_group_paths_editor.gd b/graph_node_renderer/settings/library_group_paths_editor.gd index c66f81c..4b03e3d 100644 --- a/graph_node_renderer/settings/library_group_paths_editor.gd +++ b/graph_node_renderer/settings/library_group_paths_editor.gd @@ -94,7 +94,7 @@ class FolderView extends HBoxContainer: is_default = p_default label = Label.new() - label.text = path + label.text = path.replace("$PWD", "app directory") label.size_flags_horizontal = Control.SIZE_EXPAND_FILL label.clip_text = true label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS