feat: defining map region unit un-/registering behaviour
This commit is contained in:
parent
92c38e54b6
commit
d8ae45df0f
7 changed files with 87 additions and 1 deletions
|
|
@ -1,7 +1,45 @@
|
|||
#include "map_region.h"
|
||||
#include "enemy_body.h"
|
||||
|
||||
String const MapRegion::sig_phase_changed{ "phase_changed" };
|
||||
|
||||
void MapRegion::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo(sig_phase_changed, PropertyInfo(Variant::BOOL, "hunt_phase")));
|
||||
}
|
||||
|
||||
void MapRegion::on_node_entered(Node *node) {
|
||||
if (EnemyBody * body{ cast_to<EnemyBody>(node) }) {
|
||||
if (!this->units.has(body->get_unit())) {
|
||||
body->get_unit()->set_region(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapRegion::ready() {
|
||||
connect("body_entered", callable_mp(this, &self_type::on_node_entered));
|
||||
}
|
||||
|
||||
void MapRegion::_notification(int what) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_READY:
|
||||
ready();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MapRegion::register_unit(NpcUnit *unit) {
|
||||
if (!this->units.has(unit)) {
|
||||
this->units.insert(unit);
|
||||
}
|
||||
}
|
||||
|
||||
void MapRegion::remove_unit(NpcUnit *unit) {
|
||||
if (this->units.has(unit)) {
|
||||
this->units.erase(unit);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue