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

Method rel_path_to

core/string/node_path.cpp:281–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281NodePath NodePath::rel_path_to(const NodePath &p_np) const {
282 ERR_FAIL_COND_V(!is_absolute(), NodePath());
283 ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath());
284
285 Vector<StringName> src_dirs = get_names();
286 Vector<StringName> dst_dirs = p_np.get_names();
287
288 //find common parent
289 int common_parent = 0;
290
291 while (true) {
292 if (src_dirs.size() == common_parent) {
293 break;
294 }
295 if (dst_dirs.size() == common_parent) {
296 break;
297 }
298 if (src_dirs[common_parent] != dst_dirs[common_parent]) {
299 break;
300 }
301 common_parent++;
302 }
303
304 common_parent--;
305
306 Vector<StringName> relpath;
307 relpath.resize(src_dirs.size() + dst_dirs.size() + 1);
308
309 StringName *relpath_ptr = relpath.ptrw();
310
311 int path_size = 0;
312 StringName back_str("..");
313 for (int i = common_parent + 1; i < src_dirs.size(); i++) {
314 relpath_ptr[path_size++] = back_str;
315 }
316
317 for (int i = common_parent + 1; i < dst_dirs.size(); i++) {
318 relpath_ptr[path_size++] = dst_dirs[i];
319 }
320
321 if (path_size == 0) {
322 relpath_ptr[path_size++] = ".";
323 }
324
325 relpath.resize(path_size);
326
327 return NodePath(relpath, p_np.get_subnames(), false);
328}
329
330NodePath NodePath::get_as_property_path() const {
331 if (!data || !data->path.size()) {

Callers 11

_send_confirm_pathMethod · 0.80
_send_rpcMethod · 0.80
_node_selectedMethod · 0.80
_gui_input_selectMethod · 0.80
_list_selectMethod · 0.80
_node_selectedMethod · 0.80
drop_data_fwMethod · 0.80
_tool_selectedMethod · 0.80
_update_node_pathMethod · 0.80
perform_node_renamesMethod · 0.80
_tree_rmbMethod · 0.80

Calls 7

is_absoluteMethod · 0.80
get_subnamesMethod · 0.80
NodePathClass · 0.70
sizeMethod · 0.65
get_namesMethod · 0.45
resizeMethod · 0.45
ptrwMethod · 0.45

Tested by

no test coverage detected