diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/path_db.cpp | 31 | ||||
-rw-r--r-- | core/path_db.h | 5 | ||||
-rw-r--r-- | core/resource.h | 2 |
3 files changed, 36 insertions, 2 deletions
diff --git a/core/path_db.cpp b/core/path_db.cpp index d3dc3aceb8..c6ea25d966 100644 --- a/core/path_db.cpp +++ b/core/path_db.cpp @@ -286,6 +286,37 @@ NodePath::NodePath(const Vector<StringName>& p_path,const Vector<StringName>& p_ data->property=p_property; } + +void NodePath::simplify() { + + if (!data) + return; + for(int i=0;i<data->path.size();i++) { + if (data->path.size()==1) + break; + if (data->path[i].operator String()==".") { + data->path.remove(i); + i--; + } else if (data->path[i].operator String()==".." && i>0 && data->path[i-1].operator String()!="." && data->path[i-1].operator String()!="..") { + //remove both + data->path.remove(i-1); + data->path.remove(i-1); + i-=2; + if (data->path.size()==0) { + data->path.push_back("."); + break; + } + } + } +} + +NodePath NodePath::simplified() const { + + NodePath np=*this; + np.simplify(); + return np; +} + NodePath::NodePath(const String& p_path) { data=NULL; diff --git a/core/path_db.h b/core/path_db.h index b4f13d50be..de84216006 100644 --- a/core/path_db.h +++ b/core/path_db.h @@ -84,7 +84,10 @@ public: bool operator==(const NodePath& p_path) const; bool operator!=(const NodePath& p_path) const; void operator=(const NodePath& p_path); - + + void simplify(); + NodePath simplified() const; + NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property=""); NodePath(const Vector<StringName>& p_path,const Vector<StringName>& p_subpath,bool p_absolute,const String& p_property=""); NodePath(const NodePath& p_path); diff --git a/core/resource.h b/core/resource.h index 9d9c445e1d..3596abe673 100644 --- a/core/resource.h +++ b/core/resource.h @@ -130,7 +130,7 @@ public: void set_name(const String& p_name); String get_name() const; - void set_path(const String& p_path,bool p_take_over=false); + virtual void set_path(const String& p_path,bool p_take_over=false); String get_path() const; void set_subindex(int p_sub_index); |