| 279 | } |
| 280 | |
| 281 | NodePath 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 | |
| 330 | NodePath NodePath::get_as_property_path() const { |
| 331 | if (!data || !data->path.size()) { |
no test coverage detected