feat: arealoader works on visibility/process_mode
This commit is contained in:
parent
6efbca7c40
commit
3f477bb725
2 changed files with 9 additions and 16 deletions
|
|
@ -4,7 +4,7 @@
|
|||
#include "viscosity/player_body.h"
|
||||
|
||||
void AreaLoader::_bind_methods() {
|
||||
BIND_HPROPERTY(Variant::OBJECT, area, PROPERTY_HINT_NODE_TYPE, "Node");
|
||||
BIND_HPROPERTY(Variant::OBJECT, area, PROPERTY_HINT_NODE_TYPE, "Node3D");
|
||||
BIND_PROPERTY(Variant::BOOL, start_loaded);
|
||||
}
|
||||
|
||||
|
|
@ -12,18 +12,16 @@ void AreaLoader::body_entered(Node3D *body) {
|
|||
if (!cast_to<PlayerBody>(body)) {
|
||||
return;
|
||||
}
|
||||
if (!this->area->is_inside_tree()) {
|
||||
this->area_parent->add_child(this->area);
|
||||
}
|
||||
this->area->set_process_mode(PROCESS_MODE_INHERIT);
|
||||
this->area->set_visible(true);
|
||||
}
|
||||
|
||||
void AreaLoader::body_exited(Node3D *body) {
|
||||
if (!cast_to<PlayerBody>(body)) {
|
||||
return;
|
||||
}
|
||||
if (this->area->is_inside_tree()) {
|
||||
this->area_parent->remove_child(this->area);
|
||||
}
|
||||
this->area->set_process_mode(PROCESS_MODE_DISABLED);
|
||||
this->area->set_visible(false);
|
||||
}
|
||||
|
||||
void AreaLoader::_notification(int what) {
|
||||
|
|
@ -35,17 +33,13 @@ void AreaLoader::_notification(int what) {
|
|||
return;
|
||||
case NOTIFICATION_READY:
|
||||
if (this->area) {
|
||||
this->area_parent = this->area->get_parent();
|
||||
ERR_FAIL_COND_EDMSG(!this->area_parent, "Area does not have a valid parent");
|
||||
if (!this->start_loaded) {
|
||||
callable_mp(cast_to<Node>(this->area_parent), &Node::remove_child).call_deferred(this->area);
|
||||
this->area->set_process_mode(PROCESS_MODE_DISABLED);
|
||||
this->area->set_visible(false);
|
||||
}
|
||||
connect("body_entered", callable_mp(this, &self_type::body_entered));
|
||||
connect("body_exited", callable_mp(this, &self_type::body_exited));
|
||||
}
|
||||
return;
|
||||
case NOTIFICATION_PREDELETE:
|
||||
this->area->queue_free();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,10 @@ protected:
|
|||
void _notification(int what);
|
||||
|
||||
private:
|
||||
Node *area{ nullptr };
|
||||
Node *area_parent{ nullptr };
|
||||
Node3D *area{ nullptr };
|
||||
bool start_loaded{ false };
|
||||
|
||||
public:
|
||||
GET_SET_FNS(Node *, area);
|
||||
GET_SET_FNS(Node3D *, area);
|
||||
GET_SET_FNS(bool, start_loaded);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue