MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / find_class

Method find_class

modules/gdscript/gdscript.cpp:1213–1245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1211}
1212
1213GDScript *GDScript::find_class(const String &p_qualified_name) {
1214 String first = p_qualified_name.get_slice("::", 0);
1215
1216 Vector<String> class_names;
1217 GDScript *result = nullptr;
1218 // Empty initial name means start here.
1219 if (first.is_empty() || first == global_name) {
1220 class_names = p_qualified_name.split("::");
1221 result = this;
1222 } else if (p_qualified_name.begins_with(get_root_script()->path)) {
1223 // Script path could have a class path separator("::") in it.
1224 class_names = p_qualified_name.trim_prefix(get_root_script()->path).split("::");
1225 result = get_root_script();
1226 } else if (HashMap<StringName, Ref<GDScript>>::Iterator E = subclasses.find(first)) {
1227 class_names = p_qualified_name.split("::");
1228 result = E->value.ptr();
1229 } else if (_owner != nullptr) {
1230 // Check parent scope.
1231 return _owner->find_class(p_qualified_name);
1232 }
1233
1234 // Starts at index 1 because index 0 was handled above.
1235 for (int i = 1; result != nullptr && i < class_names.size(); i++) {
1236 if (HashMap<StringName, Ref<GDScript>>::Iterator E = result->subclasses.find(class_names[i])) {
1237 result = E->value.ptr();
1238 } else {
1239 // Couldn't find inner class.
1240 return nullptr;
1241 }
1242 }
1243
1244 return result;
1245}
1246
1247bool GDScript::has_class(const GDScript *p_script) {
1248 String fqn = p_script->fully_qualified_name;

Calls 8

get_sliceMethod · 0.80
splitMethod · 0.80
begins_withMethod · 0.80
trim_prefixMethod · 0.80
sizeMethod · 0.65
is_emptyMethod · 0.45
findMethod · 0.45
ptrMethod · 0.45

Tested by

no test coverage detected