Skip to content

Commit 6114bd1

Browse files
Add node path calculation to node
1 parent a3ae512 commit 6114bd1

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

source/inochi2d/core/nodes/package.d

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ private:
9191
@Name("lockToRoot")
9292
bool lockToRoot_;
9393

94+
@Ignore
95+
string nodePath_;
96+
9497
protected:
9598

9699
/**
@@ -208,6 +211,14 @@ public:
208211
*/
209212
string name = "Unnamed Node";
210213

214+
/**
215+
Name of node as a null-terminated C string
216+
*/
217+
const(char)* cName() {
218+
import std.string : toStringz;
219+
return name.toStringz;
220+
}
221+
211222
/**
212223
Returns the unique identifier for this node
213224
*/
@@ -384,6 +395,25 @@ public:
384395
return vec3(cm * vec4(0, 0, 0, 1));
385396
}
386397

398+
/**
399+
Gets the path to the node.
400+
*/
401+
final
402+
string getNodePath() {
403+
import std.array : join;
404+
if (nodePath_.length > 0) return nodePath_;
405+
406+
string[] pathSegments;
407+
Node parent = this;
408+
while(parent !is null) {
409+
pathSegments = parent.name ~ pathSegments;
410+
parent = parent.parent;
411+
}
412+
413+
nodePath_ = "/"~pathSegments.join("/");
414+
return nodePath_;
415+
}
416+
387417
/**
388418
Gets the depth of this node
389419
*/
@@ -455,6 +485,7 @@ public:
455485
enum OFFSET_START = size_t.min;
456486
enum OFFSET_END = size_t.max;
457487
final void insertInto(Node node, size_t offset) {
488+
nodePath_ = null;
458489
import std.algorithm.mutation : remove;
459490
import std.algorithm.searching : countUntil;
460491

0 commit comments

Comments
 (0)