feat: formatting and invoking of child_added reordered
parent
36637b1f8a
commit
d4a436da2f
|
@ -5,6 +5,12 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace ce {
|
namespace ce {
|
||||||
|
void Level::instantiate() {
|
||||||
|
std::unique_ptr<Node> constructed{this->construct()};
|
||||||
|
constructed->set_is_inside_tree(true);
|
||||||
|
this->root = std::move(constructed);
|
||||||
|
this->root->propagate_added();
|
||||||
|
}
|
||||||
void Level::deinstantiate() {
|
void Level::deinstantiate() {
|
||||||
this->root.reset();
|
this->root.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ protected:
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
virtual ~Level() = default;
|
virtual ~Level() = default;
|
||||||
virtual void instantiate() = 0;
|
void instantiate();
|
||||||
|
virtual Node::OwnedPtr construct() = 0;
|
||||||
void deinstantiate();
|
void deinstantiate();
|
||||||
void propagate_tick(double const &delta_time);
|
void propagate_tick(double const &delta_time);
|
||||||
void propagate_draw(SDL_Renderer *render);
|
void propagate_draw(SDL_Renderer *render);
|
||||||
|
|
|
@ -17,8 +17,8 @@ void Node::add_child(Node::OwnedPtr &child) {
|
||||||
Node *added{child.get()};
|
Node *added{child.get()};
|
||||||
this->children.push_back({child->get_name(), std::move(child)});
|
this->children.push_back({child->get_name(), std::move(child)});
|
||||||
added->parent = this;
|
added->parent = this;
|
||||||
this->child_added.invoke(added);
|
|
||||||
added->set_is_inside_tree(this->inside_tree);
|
added->set_is_inside_tree(this->inside_tree);
|
||||||
|
this->child_added.invoke(added);
|
||||||
added->propagate_added();
|
added->propagate_added();
|
||||||
}
|
}
|
||||||
// specialize to skip dynamic_cast
|
// specialize to skip dynamic_cast
|
||||||
|
@ -44,7 +44,9 @@ std::string const &Node::get_name() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::set_name(std::string const &name) {
|
void Node::set_name(std::string const &name) {
|
||||||
if(this->parent != nullptr)
|
if(this->parent == nullptr)
|
||||||
|
this->name = name;
|
||||||
|
else
|
||||||
this->parent->rename_child(this->get_name(), name);
|
this->parent->rename_child(this->get_name(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,16 +88,14 @@ void Node::set_level(ce::Level *level) {
|
||||||
// parent level needs to match
|
// parent level needs to match
|
||||||
assert(this->parent == nullptr || this->parent->get_level() == level);
|
assert(this->parent == nullptr || this->parent->get_level() == level);
|
||||||
this->level = level;
|
this->level = level;
|
||||||
for(ChildrenVector::value_type &pair : this->children) {
|
for(ChildrenVector::value_type &pair : this->children)
|
||||||
pair.second->set_level(level);
|
pair.second->set_level(level);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::set_is_inside_tree(bool value) {
|
void Node::set_is_inside_tree(bool value) {
|
||||||
this->inside_tree = value;
|
this->inside_tree = value;
|
||||||
for(ChildrenVector::value_type &pair : this->children) {
|
for(ChildrenVector::value_type &pair : this->children)
|
||||||
pair.second->set_is_inside_tree(value);
|
pair.second->set_is_inside_tree(value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Node::OwnedPtr> Node::remove_child(Node *node) {
|
std::optional<Node::OwnedPtr> Node::remove_child(Node *node) {
|
||||||
|
|
Loading…
Reference in New Issue