summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorGeoffrey <geoffrey.irons@simedis.com>2018-02-28 10:12:06 +0100
committerGeoffrey Irons <geoffrey.irons@simedis.com>2018-04-09 15:01:37 +0200
commit8362ce4769b65f47c0d5d5a11d262a28a144e526 (patch)
tree689f5baab3f557f80335398fd2311e36d52f6027 /scene/main
parentea0e73f3c8be433dba3b98808b57dd1e2ca4d934 (diff)
Made print_tree_pretty() function which displays scene tree graphically
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/node.cpp22
-rw-r--r--scene/main/node.h2
2 files changed, 20 insertions, 4 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index ec01490ae5..fcf8768094 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1708,11 +1708,18 @@ bool Node::has_persistent_groups() const {
return false;
}
-void Node::_print_tree(const Node *p_node) {
+void Node::_print_tree_pretty(const String prefix, const bool last) {
- print_line(String(p_node->get_path_to(this)));
- for (int i = 0; i < data.children.size(); i++)
- data.children[i]->_print_tree(p_node);
+ String new_prefix = last ? String::utf8(" ┖╴") : String::utf8(" ┠╴");
+ print_line(prefix + new_prefix + String(get_name()));
+ for (int i = 0; i < data.children.size(); i++) {
+ new_prefix = last ? String::utf8(" ") : String::utf8(" ┃ ");
+ data.children[i]->_print_tree_pretty(prefix + new_prefix, i == data.children.size() - 1);
+ }
+}
+
+void Node::print_tree_pretty() {
+ _print_tree_pretty("", true);
}
void Node::print_tree() {
@@ -1720,6 +1727,12 @@ void Node::print_tree() {
_print_tree(this);
}
+void Node::_print_tree(const Node *p_node) {
+ print_line(String(p_node->get_path_to(this)));
+ for (int i = 0; i < data.children.size(); i++)
+ data.children[i]->_print_tree(p_node);
+}
+
void Node::_propagate_reverse_notification(int p_notification) {
data.blocked++;
@@ -2668,6 +2681,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_and_skip"), &Node::remove_and_skip);
ClassDB::bind_method(D_METHOD("get_index"), &Node::get_index);
ClassDB::bind_method(D_METHOD("print_tree"), &Node::print_tree);
+ ClassDB::bind_method(D_METHOD("print_tree_pretty"), &Node::print_tree_pretty);
ClassDB::bind_method(D_METHOD("set_filename", "filename"), &Node::set_filename);
ClassDB::bind_method(D_METHOD("get_filename"), &Node::get_filename);
ClassDB::bind_method(D_METHOD("propagate_notification", "what"), &Node::propagate_notification);
diff --git a/scene/main/node.h b/scene/main/node.h
index 2e8716cbd1..b9bafb1ed1 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -153,6 +153,7 @@ private:
Ref<MultiplayerAPI> multiplayer_api;
+ void _print_tree_pretty(const String prefix, const bool last);
void _print_tree(const Node *p_node);
Node *_get_node(const NodePath &p_path) const;
@@ -289,6 +290,7 @@ public:
int get_index() const;
void print_tree();
+ void print_tree_pretty();
void set_filename(const String &p_filename);
String get_filename() const;