spacebox/src/Node.cpp

49 lines
869 B
C++

#include "Node.hpp"
#include "Game.hpp"
Node::Node() : Node(NULL) {}
Node::Node(Node *parent) : parent(parent)
{
std::cout << "Constructing ";
print_branch();
}
nlohmann::json& Node::get_configuration()
{
return get_root()->configuration->config;
}
Delegate* Node::get_delegate()
{
return get_root()->delegate;
}
Game* Node::get_root()
{
Node *current = this;
while (current->parent != NULL)
{
current = current->parent;
}
return static_cast<Game*>(current);
}
void Node::print_branch()
{
Node *current = this;
while (current != NULL)
{
std::cout << current->get_class_name() << " @ " << current;
if (current->parent != NULL)
{
std::cout << " -> ";
}
else
{
std::cout << std::endl;
}
current = current->parent;
}
}