Skip to content

Commit

Permalink
GH-537 Fix Godot 4.2.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jul 20, 2024
1 parent c011903 commit 674fb74
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/editor/graph/actions/default_action_registrar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,17 @@ void OrchestratorDefaultGraphActionRegistrar::register_actions(const Orchestrato
{
const Object* object = p_context.filter->target_object->get_target();
const Ref<Script> script = object->get_script();
if (script.is_valid() && !script->get_global_name().is_empty())

String global_name;
if (script.is_valid())
global_name = ScriptServer::get_global_name(script);

if (!global_name.is_empty())
{
// The target object has a named script attached
// In this context,register script methods, properties, and signals using the script's
// class_name rather than adding these as part of the base script type.
const PackedStringArray script_class_names = ScriptServer::get_class_hierarchy(script->get_global_name());
const PackedStringArray script_class_names = ScriptServer::get_class_hierarchy(global_name);
for (const String& class_name : script_class_names)
{
const ScriptServer::GlobalClass global_class = ScriptServer::get_global_class(class_name);
Expand Down
11 changes: 7 additions & 4 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "script/language.h"
#include "script/nodes/script_nodes.h"
#include "script/script.h"
#include "script/script_server.h"

#include <godot_cpp/classes/center_container.hpp>
#include <godot_cpp/classes/confirmation_dialog.hpp>
Expand Down Expand Up @@ -587,10 +588,12 @@ void OrchestratorGraphEdit::_drop_data(const Vector2& p_position, const Variant&
context.node_path = root->get_path_to(dropped_node);

const Ref<Script> node_script = dropped_node->get_script();
if (node_script.is_valid() && !node_script->get_global_name().is_empty())
context.class_name = node_script->get_global_name();
else
context.class_name = dropped_node->get_class();

String global_name;
if (node_script.is_valid())
global_name = ScriptServer::get_global_name(node_script);

context.class_name = StringUtils::default_if_empty(global_name, dropped_node->get_class());

spawn_node<OScriptNodeSceneNode>(context, _saved_mouse_position);
}
Expand Down
6 changes: 5 additions & 1 deletion src/editor/graph/pins/graph_node_pin_node_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "common/callable_lambda.h"
#include "common/scene_utils.h"
#include "common/string_utils.h"
#include "common/version.h"
#include "editor/plugins/orchestrator_editor_plugin.h"
#include "editor/property_selector.h"
#include "editor/scene_node_selector.h"
Expand All @@ -27,7 +28,6 @@
#include "script/script.h"

#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/os.hpp>
#include <godot_cpp/classes/scene_tree.hpp>

#define EDSCALE OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_scale()
Expand Down Expand Up @@ -214,6 +214,10 @@ void OrchestratorGraphNodePinNodePath::_pin_disconnected(int p_type, int p_index

void OrchestratorGraphNodePinNodePath::_notification(int p_what)
{
#if GODOT_VERSION < 0x040300
OrchestratorGraphNodePin::_notification(p_what);
#endif

if (p_what == NOTIFICATION_READY)
{
if (_has_descriptor())
Expand Down
19 changes: 19 additions & 0 deletions src/script/script_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,23 @@ PackedStringArray ScriptServer::get_class_hierarchy(const StringName& p_class_na
break;
}
return hierarchy;
}

String ScriptServer::get_global_name(const Ref<Script>& p_script)
{
if (p_script.is_valid())
{
#if GODOT_VERSION >= 0x040300
return p_script->get_global_name();
#else
TypedArray<Dictionary> global_classes = ProjectSettings::get_singleton()->get_global_class_list();
for (int index = 0; index < global_classes.size(); ++index)
{
const Dictionary& entry = global_classes[index];
if (entry.has("path") && p_script->get_path().match(entry["path"]) && entry.has("class"))
return entry["class"];
}
#endif
}
return "";
}
6 changes: 6 additions & 0 deletions src/script/script_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef ORCHESTRATOR_SCRIPT_SERVER_H
#define ORCHESTRATOR_SCRIPT_SERVER_H

#include <godot_cpp/classes/script.hpp>
#include <godot_cpp/variant/typed_array.hpp>
#include <godot_cpp/variant/variant.hpp>

Expand Down Expand Up @@ -96,6 +97,11 @@ class ScriptServer
/// @param p_include_native_classes if true, all native classes are included in bottom-up order
/// @return all classes in the hierarchy, in bottom-up order
static PackedStringArray get_class_hierarchy(const StringName& p_class_name, bool p_include_native_classes = false);

/// Get the global name of the specified script
/// @param p_script the script instance
/// @return the global name of the script, if one is present
static String get_global_name(const Ref<Script>& p_script);
};

#endif // ORCHESTRATOR_SCRIPT_SERVER_H

0 comments on commit 674fb74

Please sign in to comment.