Skip to content

Commit f964fa7

Browse files
committed
Merge pull request #118575 from DeeJayLSP/gdtype-name-hierarchy
Exchange use of `ClassDB::is_parent_class()` with `Object::is_class()` where possible
2 parents 1567add + d376b20 commit f964fa7

10 files changed

Lines changed: 19 additions & 21 deletions

core/variant/container_type_validate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ struct ContainerTypeValidate {
110110
}
111111

112112
const StringName &obj_class = object->get_class_name();
113-
if (obj_class != class_name && !ClassDB::is_parent_class(obj_class, class_name)) {
113+
if (obj_class != class_name && !object->is_class(class_name)) {
114114
if (p_output_errors) {
115-
ERR_FAIL_V_MSG(false, vformat("Attempted to %s an object of type '%s' into a %s, which does not inherit from '%s'.", String(p_operation), object->get_class(), where, String(class_name)));
115+
ERR_FAIL_V_MSG(false, vformat("Attempted to %s an object of type '%s' into a %s, which does not inherit from '%s'.", String(p_operation), obj_class, where, String(class_name)));
116116
} else {
117117
return false;
118118
}

editor/docks/scene_tree_dock.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
653653
// Prefer nodes that inherit from the current scene root.
654654
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
655655
if (current_edited_scene_root) {
656-
String root_class = current_edited_scene_root->get_class_name();
657656
static Vector<String> preferred_types;
658657
if (preferred_types.is_empty()) {
659658
preferred_types.push_back("Control");
@@ -662,7 +661,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
662661
}
663662

664663
for (int i = 0; i < preferred_types.size(); i++) {
665-
if (ClassDB::is_parent_class(root_class, preferred_types[i])) {
664+
if (current_edited_scene_root->is_class(preferred_types[i])) {
666665
create_dialog->set_preferred_search_result_type(preferred_types[i]);
667666
break;
668667
}

editor/inspector/editor_properties_array_dict.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,14 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
655655
return false;
656656
}
657657

658-
String res_type = res->get_class();
659658
StringName script_class;
660659
if (res->get_script()) {
661660
script_class = EditorNode::get_singleton()->get_object_custom_type_name(res->get_script());
662661
}
663662

664663
for (String at : allowed_type.split(",", false)) {
665664
at = at.strip_edges();
666-
if (ClassDB::is_parent_class(res_type, at) || EditorNode::get_editor_data().script_class_is_parent(script_class, at)) {
665+
if (res->is_class(at) || EditorNode::get_editor_data().script_class_is_parent(script_class, at)) {
667666
return true;
668667
}
669668
}
@@ -693,7 +692,7 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
693692
ERR_FAIL_NULL_V_MSG(dropped_node, false, "Could not get the dropped node by its path.");
694693

695694
if (allowed_type != "NodePath") {
696-
if (!ClassDB::is_parent_class(dropped_node->get_class_name(), allowed_type) &&
695+
if (!dropped_node->is_class(allowed_type) &&
697696
!EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, allowed_type)) {
698697
// Fail if one of the nodes is not of allowed type.
699698
return false;
@@ -705,7 +704,7 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
705704
if (!allowed_subtype_array.has(dropped_node->get_class_name())) {
706705
// The dropped node type was not found in the allowed subtype array, we must check if it inherits one of them.
707706
for (const String &ast : allowed_subtype_array) {
708-
if (ClassDB::is_parent_class(dropped_node->get_class_name(), ast) ||
707+
if (dropped_node->is_class(ast) ||
709708
EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, ast)) {
710709
is_drop_allowed = true;
711710
break;

editor/script/script_text_editor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ static String _get_dropped_resource_as_member(const Ref<Resource> &p_resource, b
20362036
path = ResourceUID::get_singleton()->id_to_text(id);
20372037
}
20382038
}
2039-
const bool is_script = ClassDB::is_parent_class(p_resource->get_class(), "Script");
2039+
const bool is_script = p_resource->is_class(SNAME("Script"));
20402040

20412041
if (!p_create_field) {
20422042
return vformat("preload(%s)", _quote_drop_data(path));

modules/gdscript/gdscript.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) {
413413
}
414414

415415
if (top->native.is_valid()) {
416-
if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) {
416+
if (!p_this->is_class(top->native->get_name())) {
417417
if (EngineDebugger::is_active()) {
418418
GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be assigned to an object of type: '" + p_this->get_class() + "'");
419419
}

modules/gdscript/gdscript_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool GDScriptDataType::is_type(const Variant &p_variant, bool p_allow_implicit_c
114114
return !was_freed;
115115
}
116116

117-
if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) {
117+
if (!obj->is_class(native_type)) {
118118
return false;
119119
}
120120
return true;

modules/gdscript/gdscript_utility_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ struct GDScriptUtilityFunctionsDefinitions {
478478

479479
GDScriptNativeClass *native_type = Object::cast_to<GDScriptNativeClass>(type_object);
480480
if (native_type) {
481-
*r_ret = ClassDB::is_parent_class(value_object->get_class_name(), native_type->get_name());
481+
*r_ret = value_object->is_class(native_type->get_name());
482482
return;
483483
}
484484

modules/gdscript/gdscript_vm.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
941941
OPCODE_BREAK;
942942
}
943943

944-
*dst = object && ClassDB::is_parent_class(object->get_class_name(), native_type);
944+
*dst = object && object->is_class(native_type);
945945
ip += 4;
946946
}
947947
DISPATCH_OPCODE;
@@ -1548,7 +1548,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
15481548
OPCODE_BREAK;
15491549
}
15501550

1551-
if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
1551+
if (src_obj && !src_obj->is_class(nc->get_name())) {
15521552
err_text = "Trying to assign value of type '" + src_obj->get_class_name() +
15531553
"' to a variable of type '" + nc->get_name() + "'.";
15541554
OPCODE_BREAK;
@@ -1669,7 +1669,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
16691669
#endif
16701670
Object *src_obj = src->operator Object *();
16711671

1672-
if (src_obj && !ClassDB::is_parent_class(src_obj->get_class_name(), nc->get_name())) {
1672+
if (src_obj && !src_obj->is_class(nc->get_name())) {
16731673
*dst = Variant(); // invalid cast, assign NULL
16741674
} else {
16751675
*dst = *src;
@@ -2943,7 +2943,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
29432943
#else
29442944
Object *ret_obj = r->operator Object *();
29452945
#endif // DEBUG_ENABLED
2946-
if (ret_obj && !ClassDB::is_parent_class(ret_obj->get_class_name(), nc->get_name())) {
2946+
if (ret_obj && !ret_obj->is_class(nc->get_name())) {
29472947
#ifdef DEBUG_ENABLED
29482948
err_text = vformat(R"(Trying to return a value of type "%s" from a function whose return type is "%s".)",
29492949
_get_var_type(r), nc->get_name());

modules/mono/csharp_script.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
894894
continue;
895895
}
896896

897-
if (!ClassDB::is_parent_class(obj->get_class_name(), native_name)) {
897+
if (!obj->is_class(native_name)) {
898898
// No longer inherits the same compatible type, can't reload
899899
scr->pending_reload_state.erase(obj_id);
900900
continue;
@@ -1158,7 +1158,7 @@ bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_b
11581158
ERR_FAIL_NULL_V(classinfo, false);
11591159
type_name = classinfo->gdtype->get_name();
11601160

1161-
bool parent_is_object_class = ClassDB::is_parent_class(p_object->get_class_name(), type_name);
1161+
bool parent_is_object_class = p_object->is_class(type_name);
11621162
ERR_FAIL_COND_V_MSG(!parent_is_object_class, false,
11631163
"Type inherits from native type '" + type_name + "', so it can't be instantiated in object of type: '" + p_object->get_class() + "'.");
11641164

@@ -2464,7 +2464,7 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) {
24642464

24652465
ERR_FAIL_COND_V(native_name == StringName(), nullptr);
24662466

2467-
if (!ClassDB::is_parent_class(p_this->get_class_name(), native_name)) {
2467+
if (!p_this->is_class(native_name)) {
24682468
if (EngineDebugger::is_active()) {
24692469
CSharpLanguage::get_singleton()->debug_break_parse(get_path(), 0,
24702470
"Script inherits from native type '" + String(native_name) +

modules/mono/glue/runtime_interop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ GCHandleIntPtr godotsharp_internal_unmanaged_instance_binding_create_managed(Obj
278278
CRASH_COND(script_binding.type_name == StringName());
279279
#endif
280280

281-
bool parent_is_object_class = ClassDB::is_parent_class(p_unmanaged->get_class_name(), script_binding.type_name);
281+
bool parent_is_object_class = p_unmanaged->is_class(script_binding.type_name);
282282
ERR_FAIL_COND_V_MSG(!parent_is_object_class, { nullptr },
283283
"Type inherits from native type '" + script_binding.type_name + "', so it can't be instantiated in object of type: '" + p_unmanaged->get_class() + "'.");
284284

@@ -356,7 +356,7 @@ void godotsharp_array_filter_godot_objects_by_native(StringName *p_native_name,
356356
memnew_placement(r_output, Array);
357357

358358
for (int i = 0; i < p_input->size(); ++i) {
359-
if (ClassDB::is_parent_class(((Object *)(*p_input)[i])->get_class(), *p_native_name)) {
359+
if (((Object *)(*p_input)[i])->is_class(*p_native_name)) {
360360
r_output->push_back(p_input[i]);
361361
}
362362
}

0 commit comments

Comments
 (0)