Remove arbitrary limit on user task directories (#263)

Resolves GH-256
This commit is contained in:
Pheubel 2024-12-28 19:03:51 +01:00 committed by GitHub
parent dd427c25e2
commit 0982804a86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 13 deletions

View File

@ -399,8 +399,7 @@ void LimboAIEditor::_set_as_dirty(const Ref<BehaviorTree> &p_bt, bool p_dirty) {
}
}
void LimboAIEditor::_create_user_task_dir() {
String task_dir = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1");
void LimboAIEditor::_create_user_task_dir(String task_dir) {
ERR_FAIL_COND_MSG(DirAccess::dir_exists_absolute(task_dir), "LimboAIEditor: Directory already exists: " + task_dir);
Error err = DirAccess::make_dir_recursive_absolute(task_dir);
@ -1045,7 +1044,10 @@ void LimboAIEditor::_on_filesystem_changed() {
}
void LimboAIEditor::_on_new_script_pressed() {
SCRIPT_EDITOR()->open_script_create_dialog("BTAction", String(GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1")).path_join("new_task"));
PackedStringArray user_task_directories = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dirs");
ERR_FAIL_INDEX_MSG(0, user_task_directories.size(), "LimboAI: No user task directory set");
String default_task_dir = user_task_directories[0];
SCRIPT_EDITOR()->open_script_create_dialog("BTAction", default_task_dir.path_join("new_task"));
}
void LimboAIEditor::_task_type_selected(const String &p_class_or_path) {
@ -1415,12 +1417,12 @@ void LimboAIEditor::_update_banners() {
}
}
for (String dir_setting : { "limbo_ai/behavior_tree/user_task_dir_1", "limbo_ai/behavior_tree/user_task_dir_2", "limbo_ai/behavior_tree/user_task_dir_3" }) {
String task_dir = GLOBAL_GET(dir_setting);
PackedStringArray user_task_directories = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dirs");
for (const String &task_dir : user_task_directories) {
if (!task_dir.is_empty() && !DirAccess::dir_exists_absolute(task_dir)) {
ActionBanner *banner = memnew(ActionBanner);
banner->set_text(vformat(TTR("Task folder not found: %s"), task_dir));
banner->add_action(TTR("Create"), callable_mp(this, &LimboAIEditor::_create_user_task_dir), true);
banner->add_action(TTR("Create"), callable_mp(this, &LimboAIEditor::_create_user_task_dir).bind(task_dir), true);
banner->add_action(TTR("Edit Path..."), callable_mp(this, &LimboAIEditor::_edit_project_settings));
banner->add_spacer();
banner->add_action(TTR("Help..."), callable_mp(LimboUtility::get_singleton(), &LimboUtility::open_doc_custom_tasks));
@ -1893,9 +1895,9 @@ LimboAIEditor::LimboAIEditor() {
BASE_CONTROL()->add_child(disk_changed);
GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/behavior_tree_default_dir", PROPERTY_HINT_DIR), "res://ai/trees");
GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_1", PROPERTY_HINT_DIR), "res://ai/tasks");
GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_2", PROPERTY_HINT_DIR), "");
GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_3", PROPERTY_HINT_DIR), "");
PackedStringArray user_task_dir_default;
user_task_dir_default.append("res://ai/tasks");
GLOBAL_DEF(PropertyInfo(Variant::PACKED_STRING_ARRAY, "limbo_ai/behavior_tree/user_task_dirs", PROPERTY_HINT_TYPE_STRING, vformat("%s/%s:", Variant::STRING, PROPERTY_HINT_DIR)), user_task_dir_default);
String bt_default_dir = GLOBAL_GET("limbo_ai/behavior_tree/behavior_tree_default_dir");
save_dialog->set_current_dir(bt_default_dir);

View File

@ -211,7 +211,7 @@ private:
void _update_task_tree(const Ref<BehaviorTree> &p_bt, const Ref<BTTask> &p_specific_task = nullptr);
void _disable_editing();
void _set_as_dirty(const Ref<BehaviorTree> &p_bt, bool p_dirty);
void _create_user_task_dir();
void _create_user_task_dir(String task_dir);
void _remove_task_from_favorite(const String &p_task);
void _save_and_restart();
void _extract_subtree(const String &p_path);

View File

@ -95,9 +95,9 @@ void LimboTaskDB::scan_user_tasks() {
tasks_cache[LimboTaskDB::get_misc_category()] = List<String>();
}
for (int i = 1; i < 4; i++) {
String dir1 = ProjectSettings::get_singleton()->get_setting_with_override("limbo_ai/behavior_tree/user_task_dir_" + itos(i));
_populate_from_user_dir(dir1, &tasks_cache);
PackedStringArray user_task_directories = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dirs");
for (const String &user_task_dir : user_task_directories) {
_populate_from_user_dir(user_task_dir, &tasks_cache);
}
for (KeyValue<String, List<String>> &E : tasks_cache) {