Add BTCheckTrigger
This commit is contained in:
parent
d6db3f5ed2
commit
a6077e202d
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* bt_check_trigger.cpp
|
||||
* =============================================================================
|
||||
* Copyright 2021-2023 Serhii Snitsaruk
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
* =============================================================================
|
||||
*/
|
||||
|
||||
#include "bt_check_trigger.h"
|
||||
|
||||
#include "modules/limboai/util/limbo_utility.h"
|
||||
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
void BTCheckTrigger::set_variable(String p_variable) {
|
||||
variable = p_variable;
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
String BTCheckTrigger::_generate_name() const {
|
||||
if (variable.is_empty()) {
|
||||
return "CheckTrigger ???";
|
||||
}
|
||||
return "CheckTrigger " + LimboUtility::get_singleton()->decorate_var(variable);
|
||||
}
|
||||
|
||||
int BTCheckTrigger::_tick(double p_delta) {
|
||||
ERR_FAIL_COND_V_MSG(variable.is_empty(), FAILURE, "BBCheckVar: `variable` is not set.");
|
||||
Variant trigger_value = get_blackboard()->get_var(variable, false);
|
||||
if (trigger_value == Variant(true)) {
|
||||
get_blackboard()->set_var(variable, false);
|
||||
return SUCCESS;
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
void BTCheckTrigger::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_variable", "p_variable"), &BTCheckTrigger::set_variable);
|
||||
ClassDB::bind_method(D_METHOD("get_variable"), &BTCheckTrigger::get_variable);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "variable"), "set_variable", "get_variable");
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* bt_check_trigger.h
|
||||
* =============================================================================
|
||||
* Copyright 2021-2023 Serhii Snitsaruk
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
* =============================================================================
|
||||
*/
|
||||
|
||||
/* bt_check_trigger.h */
|
||||
|
||||
#ifndef BT_CHECK_TRIGGER_H
|
||||
#define BT_CHECK_TRIGGER_H
|
||||
|
||||
#include "bt_condition.h"
|
||||
|
||||
#include "core/object/object.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/class_db.h"
|
||||
|
||||
class BTCheckTrigger : public BTCondition {
|
||||
GDCLASS(BTCheckTrigger, BTCondition);
|
||||
|
||||
private:
|
||||
String variable;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
virtual String _generate_name() const override;
|
||||
virtual int _tick(double p_delta) override;
|
||||
|
||||
public:
|
||||
void set_variable(String p_variable);
|
||||
String get_variable() const { return variable; }
|
||||
};
|
||||
|
||||
#endif // BT_CHECK_TRIGGER
|
|
@ -60,6 +60,7 @@ def get_doc_classes():
|
|||
"BTAction",
|
||||
"BTAlwaysFail",
|
||||
"BTAlwaysSucceed",
|
||||
"BTCheckTrigger",
|
||||
"BTCheckVar",
|
||||
"BTComposite",
|
||||
"BTCondition",
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#include "bt/composites/bt_random_sequence.h"
|
||||
#include "bt/composites/bt_selector.h"
|
||||
#include "bt/composites/bt_sequence.h"
|
||||
#include "bt/conditions/bt_check_trigger.h"
|
||||
#include "bt/conditions/bt_check_var.h"
|
||||
#include "bt/conditions/bt_condition.h"
|
||||
#include "bt/decorators/bt_always_fail.h"
|
||||
|
@ -145,6 +146,7 @@ void initialize_limboai_module(ModuleInitializationLevel p_level) {
|
|||
GDREGISTER_CLASS(BTWaitTicks);
|
||||
|
||||
GDREGISTER_CLASS(BTCondition);
|
||||
GDREGISTER_CLASS(BTCheckTrigger);
|
||||
GDREGISTER_CLASS(BTCheckVar);
|
||||
|
||||
GDREGISTER_ABSTRACT_CLASS(BBParam);
|
||||
|
|
Loading…
Reference in New Issue