Compare commits

...

6 Commits

Author SHA1 Message Date
Legendsmith d980825f29
Merge bbdafa9033 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
Legendsmith bbdafa9033 Update editor_plugin, utility, amd compat files for Godot 4.4
- Update #includes and header macros to account for the changes in godotengine/godot/#96389
- Tested by compiling with mingw64
2024-10-22 22:55:34 +11:00
11 changed files with 74 additions and 21 deletions

View File

@ -10,6 +10,7 @@
*/ */
#include "blackboard.h" #include "blackboard.h"
#include "../util/limbo_compat.h"
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
#include "core/variant/variant.h" #include "core/variant/variant.h"
@ -75,6 +76,26 @@ TypedArray<StringName> Blackboard::list_vars() const {
return var_names; 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 Blackboard::get_vars_as_dict() const {
Dictionary dict; Dictionary dict;
for (const KeyValue<StringName, BBVariable> &kv : data) { 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("erase_var", "var_name"), &Blackboard::erase_var);
ClassDB::bind_method(D_METHOD("clear"), &Blackboard::clear); ClassDB::bind_method(D_METHOD("clear"), &Blackboard::clear);
ClassDB::bind_method(D_METHOD("list_vars"), &Blackboard::list_vars); 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("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("populate_from_dict", "dictionary"), &Blackboard::populate_from_dict);
ClassDB::bind_method(D_METHOD("top"), &Blackboard::top); ClassDB::bind_method(D_METHOD("top"), &Blackboard::top);

View File

@ -57,6 +57,7 @@ public:
void erase_var(const StringName &p_name); void erase_var(const StringName &p_name);
void clear() { data.clear(); } void clear() { data.clear(); }
TypedArray<StringName> list_vars() const; TypedArray<StringName> list_vars() const;
void print_state() const;
Dictionary get_vars_as_dict() const; Dictionary get_vars_as_dict() const;
void populate_from_dict(const Dictionary &p_dictionary); 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:`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_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``\ ) | | |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: .. _class_Blackboard_method_set_parent:
.. rst-class:: classref-method .. 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. 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> </description>
</method> </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"> <method name="set_parent">
<return type="void" /> <return type="void" />
<param index="0" name="blackboard" type="Blackboard" /> <param index="0" name="blackboard" type="Blackboard" />

View File

@ -36,6 +36,7 @@
#include "editor/editor_file_system.h" #include "editor/editor_file_system.h"
#include "editor/editor_help.h" #include "editor/editor_help.h"
#include "editor/editor_interface.h" #include "editor/editor_interface.h"
#include "editor/editor_main_screen.h"
#include "editor/editor_paths.h" #include "editor/editor_paths.h"
#include "editor/editor_settings.h" #include "editor/editor_settings.h"
#include "editor/filesystem_dock.h" #include "editor/filesystem_dock.h"
@ -399,8 +400,7 @@ void LimboAIEditor::_set_as_dirty(const Ref<BehaviorTree> &p_bt, bool p_dirty) {
} }
} }
void LimboAIEditor::_create_user_task_dir() { void LimboAIEditor::_create_user_task_dir(String task_dir) {
String task_dir = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dir_1");
ERR_FAIL_COND_MSG(DirAccess::dir_exists_absolute(task_dir), "LimboAIEditor: Directory already exists: " + 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); Error err = DirAccess::make_dir_recursive_absolute(task_dir);
@ -1045,7 +1045,10 @@ void LimboAIEditor::_on_filesystem_changed() {
} }
void LimboAIEditor::_on_new_script_pressed() { 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) { void LimboAIEditor::_task_type_selected(const String &p_class_or_path) {
@ -1415,12 +1418,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" }) { PackedStringArray user_task_directories = GLOBAL_GET("limbo_ai/behavior_tree/user_task_dirs");
String task_dir = GLOBAL_GET(dir_setting); for (const String &task_dir : user_task_directories) {
if (!task_dir.is_empty() && !DirAccess::dir_exists_absolute(task_dir)) { if (!task_dir.is_empty() && !DirAccess::dir_exists_absolute(task_dir)) {
ActionBanner *banner = memnew(ActionBanner); ActionBanner *banner = memnew(ActionBanner);
banner->set_text(vformat(TTR("Task folder not found: %s"), task_dir)); 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_action(TTR("Edit Path..."), callable_mp(this, &LimboAIEditor::_edit_project_settings));
banner->add_spacer(); banner->add_spacer();
banner->add_action(TTR("Help..."), callable_mp(LimboUtility::get_singleton(), &LimboUtility::open_doc_custom_tasks)); banner->add_action(TTR("Help..."), callable_mp(LimboUtility::get_singleton(), &LimboUtility::open_doc_custom_tasks));
@ -1893,9 +1896,9 @@ LimboAIEditor::LimboAIEditor() {
BASE_CONTROL()->add_child(disk_changed); 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/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"); PackedStringArray user_task_dir_default;
GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_2", PROPERTY_HINT_DIR), ""); user_task_dir_default.append("res://ai/tasks");
GLOBAL_DEF(PropertyInfo(Variant::STRING, "limbo_ai/behavior_tree/user_task_dir_3", PROPERTY_HINT_DIR), ""); 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"); String bt_default_dir = GLOBAL_GET("limbo_ai/behavior_tree/behavior_tree_default_dir");
save_dialog->set_current_dir(bt_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 _update_task_tree(const Ref<BehaviorTree> &p_bt, const Ref<BTTask> &p_specific_task = nullptr);
void _disable_editing(); void _disable_editing();
void _set_as_dirty(const Ref<BehaviorTree> &p_bt, bool p_dirty); 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 _remove_task_from_favorite(const String &p_task);
void _save_and_restart(); void _save_and_restart();
void _extract_subtree(const String &p_path); void _extract_subtree(const String &p_path);

View File

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

View File

@ -17,6 +17,7 @@
#include "core/io/resource.h" #include "core/io/resource.h"
#include "core/variant/variant.h" #include "core/variant/variant.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_main_screen.h"
#include "editor/plugins/script_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h"
#endif // TOOLS_ENABLED #endif // TOOLS_ENABLED
@ -213,7 +214,7 @@ Variant VARIANT_DEFAULT(Variant::Type p_type) {
void SHOW_BUILTIN_DOC(const String &p_topic) { void SHOW_BUILTIN_DOC(const String &p_topic) {
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
ScriptEditor::get_singleton()->goto_help(p_topic); 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 #elif LIMBOAI_GDEXTENSION
TypedArray<ScriptEditorBase> open_editors = EditorInterface::get_singleton()->get_script_editor()->get_open_script_editors(); 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."); 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_FILE_SYSTEM() (EditorFileSystem::get_singleton())
#define EDITOR_SETTINGS() (EditorSettings::get_singleton()) #define EDITOR_SETTINGS() (EditorSettings::get_singleton())
#define BASE_CONTROL() (EditorNode::get_singleton()->get_gui_base()) #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 SCENE_TREE() (SceneTree::get_singleton())
#define IS_DEBUGGER_ACTIVE() (EngineDebugger::is_active()) #define IS_DEBUGGER_ACTIVE() (EngineDebugger::is_active())
#define FS_DOCK_SELECT_FILE(m_path) FileSystemDock::get_singleton()->select_file(m_path) #define FS_DOCK_SELECT_FILE(m_path) FileSystemDock::get_singleton()->select_file(m_path)
@ -47,7 +47,7 @@
#define GET_PROJECT_SETTINGS_DIR() EditorPaths::get_singleton()->get_project_settings_dir() #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 EDIT_RESOURCE(m_res) EditorNode::get_singleton()->edit_resource(m_res)
#define INSPECTOR_GET_EDITED_OBJECT() (InspectorDock::get_inspector_singleton()->get_edited_object()) #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 FILE_EXISTS(m_path) FileAccess::exists(m_path)
#define DIR_ACCESS_CREATE() DirAccess::create(DirAccess::ACCESS_RESOURCES) #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())) #define PERFORMANCE_ADD_CUSTOM_MONITOR(m_id, m_callable) (Performance::get_singleton()->add_custom_monitor(m_id, m_callable, Variant()))
@ -85,7 +85,7 @@ using namespace godot;
#define EDITOR_FILE_SYSTEM() (EditorInterface::get_singleton()->get_resource_filesystem()) #define EDITOR_FILE_SYSTEM() (EditorInterface::get_singleton()->get_resource_filesystem())
#define EDITOR_SETTINGS() (EditorInterface::get_singleton()->get_editor_settings()) #define EDITOR_SETTINGS() (EditorInterface::get_singleton()->get_editor_settings())
#define BASE_CONTROL() (EditorInterface::get_singleton()->get_base_control()) #define BASE_CONTROL() (EditorInterface::get_singleton()->get_base_control())
#define MAIN_SCREEN_CONTROL() (EditorInterface::get_singleton()->get_editor_main_screen()) #define MAIN_SCREEN_CONTROL() (EditorInterface::get_singleton()->get_editor_main_screen()->get_control())
#define SCENE_TREE() ((SceneTree *)(Engine::get_singleton()->get_main_loop())) #define SCENE_TREE() ((SceneTree *)(Engine::get_singleton()->get_main_loop()))
#define IS_DEBUGGER_ACTIVE() (EngineDebugger::get_singleton()->is_active()) #define IS_DEBUGGER_ACTIVE() (EngineDebugger::get_singleton()->is_active())
#define FS_DOCK_SELECT_FILE(m_path) EditorInterface::get_singleton()->get_file_system_dock()->navigate_to_path(m_path) #define FS_DOCK_SELECT_FILE(m_path) EditorInterface::get_singleton()->get_file_system_dock()->navigate_to_path(m_path)

View File

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

View File

@ -416,6 +416,12 @@ String LimboUtility::get_property_hint_text(PropertyHint p_hint) const {
case PROPERTY_HINT_MAX: { case PROPERTY_HINT_MAX: {
return "MAX"; return "MAX";
} }
case PROPERTY_HINT_DICTIONARY_TYPE: {
return "DICTIONARY_TYPE";
}
case PROPERTY_HINT_TOOL_BUTTON: {
return "TOOL_BUTTON";
}
} }
return ""; return "";
} }
@ -575,7 +581,7 @@ inline void _open_online_doc_page(const String &p_page) {
} }
void LimboUtility::open_doc_introduction() { 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() { void LimboUtility::open_doc_online() {
@ -583,11 +589,11 @@ void LimboUtility::open_doc_online() {
} }
void LimboUtility::open_doc_gdextension_limitations() { 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() { 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) { void LimboUtility::open_doc_class(const String &p_class_name) {