couch/core/Node.cpp

49 lines
1021 B
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-21 15:26:39 -06:00
Name Node::GetType() const {return "Node";}
2021-01-24 16:37:35 -06:00
Node *Node::root = {Node().Instance()};
2021-01-14 11:52:01 -06:00
Node *Node::GetRoot() {
return root;
}
bool Node::IsDrawable() const {
return false;
}
bool Node::IsTransformable() const {
return false;
}
2021-01-24 16:37:35 -06:00
Node* Node::Create() {
return new Node;
}
Node* Node::Duplicate() {
return Create();
}
Node* Node::Instance() {
if (not this->isPrefab) {
Util::Die("Attempt to instance an instanced node!");
}
Node* instance = Duplicate();
instance->isPrefab = false;
instance->children = NodeList();
instance->children.isPrefabList = false;
for (Node *child : children) {
instance->children.Append(child->Instance());
}
return instance;
}
2021-01-14 11:52:01 -06:00
void NodeList::Append(Node *node) {
2021-01-24 16:37:35 -06:00
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!");
}
2021-01-14 11:52:01 -06:00
push_back(node);
}