Skip to content

Commit

Permalink
GH-537 Fix target resolution
Browse files Browse the repository at this point in the history
* Resolves methods, properties, and signals on nodes & scripts
* Correctly assigns target types for global class types
* Excludes private properties, prefixed with `_`
* Excludes internal methods, prefixed with `@`
* Reworks method/properties/signals for global classes
  • Loading branch information
Naros committed Jul 20, 2024
1 parent dbced0d commit c011903
Show file tree
Hide file tree
Showing 23 changed files with 869 additions and 331 deletions.
66 changes: 65 additions & 1 deletion src/common/method_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
//
#include "common/method_utils.h"

#include "dictionary_utils.h"
#include "property_utils.h"
#include "script/script_server.h"

#include <godot_cpp/core/class_db.hpp>

namespace MethodUtils
Expand Down Expand Up @@ -60,7 +64,12 @@ namespace MethodUtils
String class_name = p_class_name;
while (!class_name.is_empty())
{
TypedArray<Dictionary> methods = ClassDB::class_get_method_list(class_name, true);
TypedArray<Dictionary> methods;
if (ScriptServer::is_global_class(p_class_name))
methods = ScriptServer::get_global_class(p_class_name).get_method_list();
else
ClassDB::class_get_method_list(class_name, true);

for (int i = 0; i < methods.size(); i++)
{
const Dictionary& method = methods[i];
Expand All @@ -71,4 +80,59 @@ namespace MethodUtils
}
return {};
}

String get_signature(const MethodInfo& p_method)
{
String signature = p_method.name.replace("_", " ").capitalize() + "\n\n";

if (MethodUtils::has_return_value(p_method))
{
if (PropertyUtils::is_variant(p_method.return_val))
signature += "Variant";
else if (p_method.return_val.hint == PROPERTY_HINT_ARRAY_TYPE)
signature += "Array[" + p_method.return_val.hint_string + "]";
else
signature += Variant::get_type_name(p_method.return_val.type);
}
else
signature += "void";

signature += " " + p_method.name + " (";

int index = 0;
for (const PropertyInfo& property : p_method.arguments)
{
if (!signature.ends_with("("))
signature += ", ";

if (property.name.is_empty())
signature += "p" + itos(index++);
else
signature += property.name;

signature += ":" + PropertyUtils::get_property_type_name(property);
}

if (p_method.flags & METHOD_FLAG_VARARG)
{
if (!p_method.arguments.empty())
signature += ", ";
signature += "...";
}

signature += ")";

if (p_method.flags & METHOD_FLAG_CONST)
signature += " const";
else if (p_method.flags & METHOD_FLAG_VIRTUAL)
signature += " virtual";

#if DEBUG_ENABLED
signature += "\n\n";
signature += vformat("%s", DictionaryUtils::from_method(p_method));
#endif

return signature;
}

}
5 changes: 5 additions & 0 deletions src/common/method_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ namespace MethodUtils
/// @param p_method_name the name of the method to search for
/// @return the class that contains the method, or an empty string if the method is not found
String get_method_class(const String& p_class_name, const String& p_method_name);

/// Generates a method signature based on the specified method.
/// @param p_method the method
/// @return the signature
String get_signature(const MethodInfo& p_method);
}

#endif // ORCHESTRATOR_METHOD_UTILS_H
11 changes: 11 additions & 0 deletions src/common/scene_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#include "scene_utils.h"

#include "editor/plugins/orchestrator_editor_plugin.h"
#include "script/script_server.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/font.hpp>
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/style_box.hpp>
#include <godot_cpp/classes/theme.hpp>
Expand Down Expand Up @@ -50,6 +52,15 @@ namespace SceneUtils
return vbox->get_theme_icon(instantiable ? "Object" : "ObjectDisabled", "EditorIcons");
}

if (ScriptServer::is_global_class(p_class_name))
{
const String icon = ScriptServer::get_global_class(p_class_name).icon_path;
if (!icon.is_empty())
return ResourceLoader::get_singleton()->load(icon);

return get_class_icon(ScriptServer::get_native_class_name(p_class_name));
}

return nullptr;
}

Expand Down
4 changes: 3 additions & 1 deletion src/editor/graph/actions/action_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ TreeItem* OrchestratorGraphActionMenu::_make_item(TreeItem* p_parent,
TreeItem* child = p_parent->create_child();
child->set_text(0, p_text);
child->set_expand_right(0, true);
child->set_icon(0, SceneUtils::get_editor_icon(p_menu_item->get_spec().icon));
child->set_icon(0, SceneUtils::get_class_icon(p_menu_item->get_spec().icon));
child->set_tooltip_text(0, p_menu_item->get_spec().tooltip);
child->set_selectable(0, p_menu_item->get_handler().is_valid());

Expand Down Expand Up @@ -450,6 +450,8 @@ void OrchestratorGraphActionMenu::_on_filter_text_changed(const String& p_new_te
// Update filters
_filter.keywords.clear();

_on_expand_tree(true);

const String filter_text = p_new_text.trim_prefix(" ").trim_suffix(" ");
if (!filter_text.is_empty())
for (const String& element : filter_text.split(" "))
Expand Down
Loading

0 comments on commit c011903

Please sign in to comment.