From b07fb713599d609105e0edbdd1fdd284ce476171 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Tue, 9 Jan 2024 16:25:28 +0100 Subject: [PATCH] Fix documentation related crash --- util/limbo_compat.cpp | 19 ++++++++++++++++++- util/limbo_compat.h | 8 ++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/util/limbo_compat.cpp b/util/limbo_compat.cpp index 4901de9..e9810a9 100644 --- a/util/limbo_compat.cpp +++ b/util/limbo_compat.cpp @@ -24,10 +24,14 @@ void EDIT_SCRIPT(const String &p_path) { #ifdef LIMBOAI_GDEXTENSION #include "godot_cpp/classes/editor_interface.hpp" +#include "godot_cpp/core/error_macros.hpp" +#include "godot_cpp/variant/typed_array.hpp" #include #include #include #include +#include +#include #include using namespace godot; @@ -83,4 +87,17 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p return ret; } -#endif // LIMBOAI_GDEXTENSION +void SHOW_DOC(const String &p_topic) { +#ifdef LIMBOAI_MODULE + ScriptEditor::get_singleton()->goto_help(m_doc); + EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); +#else // LIMBOAI_GDEXTENSION + TypedArray 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."); + ScriptEditorBase *seb = Object::cast_to(open_editors.front()); + ERR_FAIL_NULL(seb); + seb->emit_signal("go_to_help", p_topic); +#endif // ! LIMBOAI_MODULE +} + +#endif // ! LIMBOAI_GDEXTENSION diff --git a/util/limbo_compat.h b/util/limbo_compat.h index efa2c76..e4b3300 100644 --- a/util/limbo_compat.h +++ b/util/limbo_compat.h @@ -51,10 +51,6 @@ #define FILE_EXISTS(m_path) FileAccess::exists(m_path) #define DIR_ACCESS_CREATE() DirAccess::create(DirAccess::ACCESS_RESOURCES) -#define SHOW_DOC(m_doc) ( \ - ScriptEditor::get_singleton()->goto_help(m_doc); \ - EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);) - #define VARIANT_EVALUATE(m_op, m_lvalue, m_rvalue, r_ret) r_ret = Variant::evaluate(m_op, m_lvalue, m_rvalue) // * Enum @@ -104,8 +100,6 @@ void EDIT_SCRIPT(const String &p_path); // TODO: need a module version! #define FILE_EXISTS(m_path) FileAccess::file_exists(m_path) #define DIR_ACCESS_CREATE() DirAccess::open("res://") -#define SHOW_DOC(m_doc) EditorInterface::get_singleton()->get_script_editor()->get_current_editor()->emit_signal("go_to_help", m_doc) - #define VARIANT_EVALUATE(m_op, m_lvalue, m_rvalue, r_ret) \ { \ bool r_valid; \ @@ -151,4 +145,6 @@ inline void VARIANT_DELETE_IF_OBJECT(Variant m_variant) { #define PROJECT_CONFIG_FILE() GET_PROJECT_SETTINGS_DIR().path_join("limbo_ai.cfg") +void SHOW_DOC(const String &p_topic); + #endif // LIMBO_COMPAT_H