Skip to content

Commit

Permalink
Add node path calculation to node
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Jul 3, 2022
1 parent a3ae512 commit 6114bd1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions source/inochi2d/core/nodes/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ private:
@Name("lockToRoot")
bool lockToRoot_;

@Ignore
string nodePath_;

protected:

/**
Expand Down Expand Up @@ -208,6 +211,14 @@ public:
*/
string name = "Unnamed Node";

/**
Name of node as a null-terminated C string
*/
const(char)* cName() {
import std.string : toStringz;
return name.toStringz;
}

/**
Returns the unique identifier for this node
*/
Expand Down Expand Up @@ -384,6 +395,25 @@ public:
return vec3(cm * vec4(0, 0, 0, 1));
}

/**
Gets the path to the node.
*/
final
string getNodePath() {
import std.array : join;
if (nodePath_.length > 0) return nodePath_;

string[] pathSegments;
Node parent = this;
while(parent !is null) {
pathSegments = parent.name ~ pathSegments;
parent = parent.parent;
}

nodePath_ = "/"~pathSegments.join("/");
return nodePath_;
}

/**
Gets the depth of this node
*/
Expand Down Expand Up @@ -455,6 +485,7 @@ public:
enum OFFSET_START = size_t.min;
enum OFFSET_END = size_t.max;
final void insertInto(Node node, size_t offset) {
nodePath_ = null;
import std.algorithm.mutation : remove;
import std.algorithm.searching : countUntil;

Expand Down

0 comments on commit 6114bd1

Please sign in to comment.