spacebox/src/Node.cpp

91 lines
1.5 KiB
C++

#include "Node.hpp"
#include "Game.hpp"
Node::Node() : Node(NULL) {}
Node::Node(Node *parent) : parent(parent)
{
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::suppress_input_temporarily(int length)
{
get_root()->input.suppress();
if (length == 0)
{
length = get_configuration()["input"]["default-unsuppress-delay"];
}
get_root()->input.unsuppress_animation.play_once(length);
}
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);
}