2019-04-23 01:42:19 -04:00
|
|
|
#include "Node.hpp"
|
2019-05-02 20:11:45 -04:00
|
|
|
#include "Game.hpp"
|
2019-04-23 01:42:19 -04:00
|
|
|
|
2019-05-02 20:11:45 -04:00
|
|
|
Node::Node() : Node(NULL) {}
|
2019-05-02 06:45:41 -04:00
|
|
|
|
2019-06-16 03:05:02 -04:00
|
|
|
Node::Node(Node *parent, bool active) : parent(parent)
|
2019-05-02 06:45:41 -04:00
|
|
|
{
|
2019-06-16 03:05:02 -04:00
|
|
|
if (active)
|
|
|
|
{
|
|
|
|
activate();
|
|
|
|
}
|
2019-05-02 20:11:45 -04:00
|
|
|
std::cout << "Constructing ";
|
|
|
|
print_branch();
|
2019-05-02 06:45:41 -04:00
|
|
|
}
|
|
|
|
|
2020-07-13 00:53:12 -04:00
|
|
|
void Node::set_parent(Node* other)
|
2019-05-18 17:39:47 -04:00
|
|
|
{
|
2020-07-13 00:53:12 -04:00
|
|
|
parent = other;
|
2019-05-18 17:39:47 -04:00
|
|
|
}
|
|
|
|
|
2019-06-16 03:05:02 -04:00
|
|
|
void Node::activate()
|
|
|
|
{
|
|
|
|
active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::deactivate()
|
|
|
|
{
|
|
|
|
active = false;
|
|
|
|
}
|
|
|
|
|
2020-07-17 22:58:23 -04:00
|
|
|
bool Node::is_active() const
|
2019-07-21 03:13:19 -04:00
|
|
|
{
|
|
|
|
return active;
|
|
|
|
}
|
|
|
|
|
2019-05-04 03:25:35 -04:00
|
|
|
nlohmann::json& Node::get_configuration()
|
2019-05-02 06:45:41 -04:00
|
|
|
{
|
2019-05-18 17:39:47 -04:00
|
|
|
return get_root()->configuration.config;
|
2019-05-02 06:45:41 -04:00
|
|
|
}
|
|
|
|
|
2019-04-23 01:42:19 -04:00
|
|
|
Game* Node::get_root()
|
|
|
|
{
|
2020-07-17 22:58:23 -04:00
|
|
|
Node* current = this;
|
2019-04-23 01:42:19 -04:00
|
|
|
while (current->parent != NULL)
|
|
|
|
{
|
|
|
|
current = current->parent;
|
|
|
|
}
|
|
|
|
return static_cast<Game*>(current);
|
|
|
|
}
|
2019-05-02 20:11:45 -04:00
|
|
|
|
2019-05-18 17:39:47 -04:00
|
|
|
Delegate& Node::get_delegate()
|
2019-05-16 03:51:36 -04:00
|
|
|
{
|
|
|
|
return get_root()->delegate;
|
|
|
|
}
|
|
|
|
|
2019-05-18 17:39:47 -04:00
|
|
|
Display& Node::get_display()
|
2019-05-16 03:51:36 -04:00
|
|
|
{
|
|
|
|
return get_root()->display;
|
|
|
|
}
|
|
|
|
|
2019-05-02 20:11:45 -04:00
|
|
|
void Node::print_branch()
|
|
|
|
{
|
2019-05-31 21:53:39 -04:00
|
|
|
Node* current = this;
|
2019-05-02 20:11:45 -04:00
|
|
|
while (current != NULL)
|
|
|
|
{
|
|
|
|
std::cout << current->get_class_name() << " @ " << current;
|
|
|
|
if (current->parent != NULL)
|
|
|
|
{
|
|
|
|
std::cout << " -> ";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
current = current->parent;
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 00:53:12 -04:00
|
|
|
|
|
|
|
Node::~Node()
|
|
|
|
{
|
|
|
|
std::cout << "Destructing ";
|
|
|
|
print_branch();
|
|
|
|
get_delegate().unsubscribe(this);
|
|
|
|
}
|