feat: BehaviourInvertResult
This commit is contained in:
parent
e94c820090
commit
bd7936e357
3 changed files with 51 additions and 3 deletions
|
|
@ -2,8 +2,6 @@
|
|||
#include "behaviour_nodes/behaviour_node.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
void BehaviourAlwaysSuccess::_bind_methods() {}
|
||||
|
||||
PackedStringArray BehaviourAlwaysSuccess::get_configuration_warnings() const {
|
||||
PackedStringArray warnings{ super_type::get_configuration_warnings() };
|
||||
if (get_child_behaviours().size() != 1) {
|
||||
|
|
@ -28,3 +26,41 @@ BehaviourNode *BehaviourAlwaysSuccess::get_next() {
|
|||
? get_child_behaviours().get(0)
|
||||
: cast_to<BehaviourNode>(get_parent());
|
||||
}
|
||||
|
||||
PackedStringArray BehaviourInvertResult::get_configuration_warnings() const {
|
||||
PackedStringArray warnings{ super_type::get_configuration_warnings() };
|
||||
if (get_child_behaviours().size() != 1) {
|
||||
warnings.push_back("BehaviourInvertResult should have exactly one child behaviour");
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
void BehaviourInvertResult::enter() {
|
||||
set_status(Running);
|
||||
}
|
||||
|
||||
void BehaviourInvertResult::execute() {
|
||||
if (get_child_behaviours().is_empty()) {
|
||||
set_status(Fail);
|
||||
ERR_FAIL_EDMSG("BehaviourInvertResult executed with no children");
|
||||
} else if (get_status() == Running) {
|
||||
Status child_status{ get_child_behaviours().get(0)->get_status() };
|
||||
switch (child_status) {
|
||||
case Fail:
|
||||
set_status(Success);
|
||||
return;
|
||||
case Success:
|
||||
set_status(Fail);
|
||||
return;
|
||||
case Running:
|
||||
set_status(Running);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BehaviourNode *BehaviourInvertResult::get_next() {
|
||||
return get_status() == Running
|
||||
? get_child_behaviours().get(0)
|
||||
: cast_to<BehaviourNode>(get_parent());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,21 @@
|
|||
|
||||
class BehaviourAlwaysSuccess : public BehaviourComposite {
|
||||
GDCLASS(BehaviourAlwaysSuccess, BehaviourComposite);
|
||||
static void _bind_methods();
|
||||
static void _bind_methods() {}
|
||||
|
||||
public:
|
||||
PackedStringArray get_configuration_warnings() const override;
|
||||
void execute() override;
|
||||
BehaviourNode *get_next() override;
|
||||
};
|
||||
|
||||
class BehaviourInvertResult : public BehaviourComposite {
|
||||
GDCLASS(BehaviourInvertResult, BehaviourComposite);
|
||||
static void _bind_methods() {}
|
||||
|
||||
public:
|
||||
PackedStringArray get_configuration_warnings() const override;
|
||||
void enter() override;
|
||||
void execute() override;
|
||||
BehaviourNode *get_next() override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ void initialize_behaviour_nodes_module(ModuleInitializationLevel p_level) {
|
|||
ClassDB::register_class<BehaviourAction>();
|
||||
ClassDB::register_class<BehaviourRepeatUntilFail>();
|
||||
ClassDB::register_class<BehaviourAlwaysSuccess>();
|
||||
ClassDB::register_class<BehaviourInvertResult>();
|
||||
}
|
||||
|
||||
void uninitialize_behaviour_nodes_module(ModuleInitializationLevel p_level) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue