Compare commits

...

6 Commits

Author SHA1 Message Date
speak 4fd5c37f39
Merge 2dfe775f7b into 672f92c87b 2024-12-30 23:54:50 +01:00
Serhii Snitsaruk 672f92c87b
Update doc 2024-12-30 01:24:52 +01:00
Serhii Snitsaruk e2e42b90a8 Fix documentation links in the editor 2024-12-29 16:03:21 -08:00
Serhii Snitsaruk a952009293
Add `Blackboard.print_state()` (#264)
Method that prints values of all variables in each scope.
2024-12-29 23:45:59 +01:00
Pheubel 0982804a86
Remove arbitrary limit on user task directories (#263)
Resolves GH-256
2024-12-28 19:03:51 +01:00
Jesse Viikari 2dfe775f7b Fix compatibility with Godot dev 4.4dev4 2024-11-13 14:04:44 +02:00
12 changed files with 71 additions and 24 deletions

View File

@ -10,6 +10,7 @@
*/
#include "blackboard.h"
#include "../util/limbo_compat.h"
#ifdef LIMBOAI_MODULE
#include "core/variant/variant.h"
@ -75,6 +76,26 @@ TypedArray<StringName> Blackboard::list_vars() const {
return var_names;
}
void Blackboard::print_state() const {
Ref<Blackboard> bb{ this };
int scope_idx = 0;
while (bb.is_valid()) {
int i = 0;
String line = "Scope " + itos(scope_idx) + ": { ";
for (const KeyValue<StringName, BBVariable> &kv : bb->data) {
if (i > 0) {
line += ", ";
}
line += String(kv.key) + ": " + String(kv.value.get_value());
i++;
}
line += " }";
PRINT_LINE(line);
bb = bb->get_parent();
scope_idx++;
}
}
Dictionary Blackboard::get_vars_as_dict() const {
Dictionary dict;
for (const KeyValue<StringName, BBVariable> &kv : data) {
@ -136,6 +157,7 @@ void Blackboard::_bind_methods() {
ClassDB::bind_method(D_METHOD("erase_var", "var_name"), &Blackboard::erase_var);
ClassDB::bind_method(D_METHOD("clear"), &Blackboard::clear);
ClassDB::bind_method(D_METHOD("list_vars"), &Blackboard::list_vars);
ClassDB::bind_method(D_METHOD("print_state"), &Blackboard::print_state);
ClassDB::bind_method(D_METHOD("get_vars_as_dict"), &Blackboard::get_vars_as_dict);
ClassDB::bind_method(D_METHOD("populate_from_dict", "dictionary"), &Blackboard::populate_from_dict);
ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);

View File

@ -57,6 +57,7 @@ public:
void erase_var(const StringName &p_name);
void clear() { data.clear(); }
TypedArray<StringName> list_vars() const;
void print_state() const;
Dictionary get_vars_as_dict() const;
void populate_from_dict(const Dictionary &p_dictionary);

View File

@ -54,6 +54,8 @@ Methods
+---------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`populate_from_dict<class_Blackboard_method_populate_from_dict>`\ (\ dictionary\: ``Dictionary``\ ) |
+---------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`print_state<class_Blackboard_method_print_state>`\ (\ ) |const| |
+---------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_parent<class_Blackboard_method_set_parent>`\ (\ blackboard\: :ref:`Blackboard<class_Blackboard>`\ ) |
+---------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_var<class_Blackboard_method_set_var>`\ (\ var_name\: ``StringName``, value\: ``Variant``\ ) |
@ -194,6 +196,18 @@ Fills the Blackboard with multiple variables from a dictionary. The dictionary k
----
.. _class_Blackboard_method_print_state:
.. rst-class:: classref-method
|void| **print_state**\ (\ ) |const| :ref:`🔗<class_Blackboard_method_print_state>`
Prints the values of all variables in each scope.
.. rst-class:: classref-item-separator
----
.. _class_Blackboard_method_set_parent:
.. rst-class:: classref-method

View File

@ -86,6 +86,12 @@
Fills the Blackboard with multiple variables from a dictionary. The dictionary keys must be variable names and the dictionary values must be variable values. Keys must be StringName or String.
</description>
</method>
<method name="print_state" qualifiers="const">
<return type="void" />
<description>
Prints the values of all variables in each scope.
</description>
</method>
<method name="set_parent">
<return type="void" />
<param index="0" name="blackboard" type="Blackboard" />

View File

@ -287,14 +287,14 @@ void EditorPropertyBBParam::update_property() {
variable_editor->update_property();
variable_editor->show();
bottom_container->hide();
type_choice->set_icon(get_editor_theme_icon(SNAME("LimboExtraVariable")));
type_choice->set_button_icon(get_editor_theme_icon(SNAME("LimboExtraVariable")));
} else {
_create_value_editor(param->get_type());
variable_editor->hide();
value_editor->show();
value_editor->set_object_and_property(param.ptr(), SNAME("saved_value"));
value_editor->update_property();
type_choice->set_icon(get_editor_theme_icon(Variant::get_type_name(param->get_type())));
type_choice->set_button_icon(get_editor_theme_icon(Variant::get_type_name(param->get_type())));
}
}
@ -316,7 +316,7 @@ void EditorPropertyBBParam::_notification(int p_what) {
{
String type = Variant::get_type_name(_get_edited_param()->get_type());
type_choice->set_icon(get_editor_theme_icon(type));
type_choice->set_button_icon(get_editor_theme_icon(type));
}
// Initialize type choice.

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

@ -27,6 +27,7 @@
#include "core/object/object.h"
#include "core/templates/hash_set.h"
#include "editor/editor_node.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_spin_slider.h"
#include "editor/plugins/editor_plugin.h"
@ -211,7 +212,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

@ -4,7 +4,7 @@ major = 1
minor = 3
patch = 0
status = "dev"
doc_branch = "master"
doc_branch = "latest"
godot_cpp_ref = "godot-4.3-stable"
# Code that generates version header

View File

@ -17,6 +17,7 @@
#include "core/io/resource.h"
#include "core/variant/variant.h"
#include "editor/editor_node.h"
#include "editor/editor_main_screen.h"
#include "editor/plugins/script_editor_plugin.h"
#endif // TOOLS_ENABLED
@ -213,7 +214,7 @@ Variant VARIANT_DEFAULT(Variant::Type p_type) {
void SHOW_BUILTIN_DOC(const String &p_topic) {
#ifdef LIMBOAI_MODULE
ScriptEditor::get_singleton()->goto_help(p_topic);
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
#elif LIMBOAI_GDEXTENSION
TypedArray<ScriptEditorBase> open_editors = EditorInterface::get_singleton()->get_script_editor()->get_open_script_editors();
ERR_FAIL_COND_MSG(open_editors.size() == 0, "Can't open help page. Need at least one script open in the script editor.");

View File

@ -28,7 +28,7 @@
#define EDITOR_FILE_SYSTEM() (EditorFileSystem::get_singleton())
#define EDITOR_SETTINGS() (EditorSettings::get_singleton())
#define BASE_CONTROL() (EditorNode::get_singleton()->get_gui_base())
#define MAIN_SCREEN_CONTROL() (EditorNode::get_singleton()->get_main_screen_control())
#define MAIN_SCREEN_CONTROL() (EditorNode::get_singleton()->get_editor_main_screen()->get_control())
#define SCENE_TREE() (SceneTree::get_singleton())
#define IS_DEBUGGER_ACTIVE() (EngineDebugger::is_active())
#define FS_DOCK_SELECT_FILE(m_path) FileSystemDock::get_singleton()->select_file(m_path)
@ -37,7 +37,7 @@
#define IS_CLASS(m_obj, m_class) (m_obj->is_class_ptr(m_class::get_class_ptr_static()))
#define RAND_RANGE(m_from, m_to) (Math::random(m_from, m_to))
#define RANDF() (Math::randf())
#define BUTTON_SET_ICON(m_btn, m_icon) m_btn->set_icon(m_icon)
#define BUTTON_SET_ICON(m_btn, m_icon) m_btn->set_button_icon(m_icon)
#define RESOURCE_LOAD(m_path, m_hint) ResourceLoader::load(m_path, m_hint)
#define RESOURCE_LOAD_NO_CACHE(m_path, m_hint) ResourceLoader::load(m_path, m_hint, ResourceFormatLoader::CACHE_MODE_IGNORE)
#define RESOURCE_SAVE(m_res, m_path, m_flags) ResourceSaver::save(m_res, m_path, m_flags)
@ -47,7 +47,7 @@
#define GET_PROJECT_SETTINGS_DIR() EditorPaths::get_singleton()->get_project_settings_dir()
#define EDIT_RESOURCE(m_res) EditorNode::get_singleton()->edit_resource(m_res)
#define INSPECTOR_GET_EDITED_OBJECT() (InspectorDock::get_inspector_singleton()->get_edited_object())
#define SET_MAIN_SCREEN_EDITOR(m_name) (EditorNode::get_singleton()->select_editor_by_name(m_name))
#define SET_MAIN_SCREEN_EDITOR(m_name) (EditorNode::get_singleton()->get_editor_main_screen()->select_by_name(m_name))
#define FILE_EXISTS(m_path) FileAccess::exists(m_path)
#define DIR_ACCESS_CREATE() DirAccess::create(DirAccess::ACCESS_RESOURCES)
#define PERFORMANCE_ADD_CUSTOM_MONITOR(m_id, m_callable) (Performance::get_singleton()->add_custom_monitor(m_id, m_callable, Variant()))

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) {

View File

@ -575,7 +575,7 @@ inline void _open_online_doc_page(const String &p_page) {
}
void LimboUtility::open_doc_introduction() {
_open_online_doc_page("getting-started/introduction.html");
_open_online_doc_page("behavior-trees/introduction.html");
}
void LimboUtility::open_doc_online() {
@ -583,11 +583,11 @@ void LimboUtility::open_doc_online() {
}
void LimboUtility::open_doc_gdextension_limitations() {
_open_online_doc_page("getting-started/gdextension.html#limitations-of-the-gdextension-version");
_open_online_doc_page("getting-started/getting-limboai.html#get-gdextension-version");
}
void LimboUtility::open_doc_custom_tasks() {
_open_online_doc_page("getting-started/custom-tasks.html");
_open_online_doc_page("behavior-trees/custom-tasks.html");
}
void LimboUtility::open_doc_class(const String &p_class_name) {