couch/core/Node.cpp

60 lines
1.1 KiB
C++
Raw Normal View History

2021-01-14 11:52:01 -06:00
#include "Node.h"
2021-01-24 16:37:35 -06:00
#include "Util.h"
2021-01-14 11:52:01 -06:00
2021-01-26 16:42:28 -06:00
void NodeList::Append(Node *node) {
if (this->isPrefabList and not node->isPrefab) {
Util::Die("Attempt to add instanced node to prefab list!");
}
if (node->isPrefab and not this->isPrefabList) {
Util::Die("Attempt to add prefab node to instanced list!");
}
push_back(node);
}
bool NodeList::IsPrefabList() {
return isPrefabList;
}
2021-01-21 15:26:39 -06:00
Name Node::GetType() const {return "Node";}
2021-01-26 16:42:28 -06:00
bool Node::IsPrefab() {
return isPrefab;
2021-01-14 11:52:01 -06:00
}
2021-01-26 16:42:28 -06:00
NodeList Node::GetChildren() {
return children;
2021-01-14 11:52:01 -06:00
}
2021-01-26 16:42:28 -06:00
void Node::AddChild(Node *child) {
children.Append(child);
}
Node *Node::GetRoot() {
return root;
2021-01-14 11:52:01 -06:00
}
2021-01-24 16:37:35 -06:00
Node* Node::Create() {
return new Node;
}
Node* Node::Duplicate() {
return Create();
}
Node* Node::Instance() {
2021-01-26 16:42:28 -06:00
if (not isPrefab) {
2021-01-24 16:37:35 -06:00
Util::Die("Attempt to instance an instanced node!");
}
Node* instance = Duplicate();
instance->isPrefab = false;
instance->children.isPrefabList = false;
2021-01-26 16:42:28 -06:00
// Instance the children to the instanced list
2021-01-24 16:37:35 -06:00
for (Node *child : children) {
instance->children.Append(child->Instance());
}
return instance;
}
2021-01-26 16:42:28 -06:00
Node *Node::root = {Node().Instance()};