85 lines
1.3 KiB
C++
85 lines
1.3 KiB
C++
#include "Node.hpp"
|
|
#include "Game.hpp"
|
|
|
|
Node::Node() : Node(NULL) {}
|
|
|
|
Node::Node(Node *parent, bool active) : parent(parent)
|
|
{
|
|
if (active)
|
|
{
|
|
activate();
|
|
}
|
|
std::cout << "Constructing ";
|
|
print_branch();
|
|
}
|
|
|
|
void Node::set_parent(Node* other)
|
|
{
|
|
parent = other;
|
|
}
|
|
|
|
void Node::activate()
|
|
{
|
|
active = true;
|
|
}
|
|
|
|
void Node::deactivate()
|
|
{
|
|
active = false;
|
|
}
|
|
|
|
bool Node::is_active() const
|
|
{
|
|
return active;
|
|
}
|
|
|
|
nlohmann::json& Node::get_configuration()
|
|
{
|
|
return get_root()->configuration.config;
|
|
}
|
|
|
|
Game* Node::get_root()
|
|
{
|
|
Node* current = this;
|
|
while (current->parent != NULL)
|
|
{
|
|
current = current->parent;
|
|
}
|
|
return static_cast<Game*>(current);
|
|
}
|
|
|
|
Delegate& Node::get_delegate()
|
|
{
|
|
return get_root()->delegate;
|
|
}
|
|
|
|
Display& Node::get_display()
|
|
{
|
|
return get_root()->display;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
Node::~Node()
|
|
{
|
|
std::cout << "Destructing ";
|
|
print_branch();
|
|
get_delegate().unsubscribe(this);
|
|
}
|