CallMethod: Store result on the blackboard
This commit is contained in:
parent
aca9784c95
commit
184361d460
|
@ -12,6 +12,7 @@
|
||||||
#include "bt_call_method.h"
|
#include "bt_call_method.h"
|
||||||
|
|
||||||
#include "../../../util/limbo_compat.h"
|
#include "../../../util/limbo_compat.h"
|
||||||
|
#include "../../../util/limbo_utility.h"
|
||||||
|
|
||||||
//**** Setters / Getters
|
//**** Setters / Getters
|
||||||
|
|
||||||
|
@ -33,11 +34,16 @@ void BTCallMethod::set_include_delta(bool p_include_delta) {
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BTCallMethod::set_args(Array p_args) {
|
void BTCallMethod::set_args(TypedArray<BBVariant> p_args) {
|
||||||
args = p_args;
|
args = p_args;
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BTCallMethod::set_result_var(const String &p_result_var) {
|
||||||
|
result_var = p_result_var;
|
||||||
|
emit_changed();
|
||||||
|
}
|
||||||
|
|
||||||
//**** Task Implementation
|
//**** Task Implementation
|
||||||
|
|
||||||
PackedStringArray BTCallMethod::get_configuration_warnings() {
|
PackedStringArray BTCallMethod::get_configuration_warnings() {
|
||||||
|
@ -63,10 +69,11 @@ String BTCallMethod::_generate_name() {
|
||||||
}
|
}
|
||||||
args_str += vformat("%s", args).trim_prefix("[").trim_suffix("]");
|
args_str += vformat("%s", args).trim_prefix("[").trim_suffix("]");
|
||||||
}
|
}
|
||||||
return vformat("CallMethod %s(%s) node: %s",
|
return vformat("CallMethod %s(%s) node: %s %s",
|
||||||
(method != StringName() ? method : "???"),
|
method != StringName() ? method : "???",
|
||||||
args_str,
|
args_str,
|
||||||
(node_param.is_valid() && !node_param->to_string().is_empty() ? node_param->to_string() : "???"));
|
node_param.is_valid() && !node_param->to_string().is_empty() ? node_param->to_string() : "???",
|
||||||
|
result_var.is_empty() ? "" : LW_NAME(output_var_prefix) + LimboUtility::get_singleton()->decorate_var(result_var));
|
||||||
}
|
}
|
||||||
|
|
||||||
BT::Status BTCallMethod::_tick(double p_delta) {
|
BT::Status BTCallMethod::_tick(double p_delta) {
|
||||||
|
@ -75,6 +82,8 @@ BT::Status BTCallMethod::_tick(double p_delta) {
|
||||||
Object *obj = node_param->get_value(get_agent(), get_blackboard());
|
Object *obj = node_param->get_value(get_agent(), get_blackboard());
|
||||||
ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string());
|
ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string());
|
||||||
|
|
||||||
|
Variant result;
|
||||||
|
|
||||||
#ifdef LIMBOAI_MODULE
|
#ifdef LIMBOAI_MODULE
|
||||||
const Variant delta = include_delta ? Variant(p_delta) : Variant();
|
const Variant delta = include_delta ? Variant(p_delta) : Variant();
|
||||||
const Variant **argptrs = nullptr;
|
const Variant **argptrs = nullptr;
|
||||||
|
@ -91,7 +100,7 @@ BT::Status BTCallMethod::_tick(double p_delta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Callable::CallError ce;
|
Callable::CallError ce;
|
||||||
obj->callp(method, argptrs, argument_count, ce);
|
result = obj->callp(method, argptrs, argument_count, ce);
|
||||||
if (ce.error != Callable::CallError::CALL_OK) {
|
if (ce.error != Callable::CallError::CALL_OK) {
|
||||||
ERR_FAIL_V_MSG(FAILURE, "BTCallMethod: Error calling method: " + Variant::get_call_error_text(obj, method, argptrs, argument_count, ce) + ".");
|
ERR_FAIL_V_MSG(FAILURE, "BTCallMethod: Error calling method: " + Variant::get_call_error_text(obj, method, argptrs, argument_count, ce) + ".");
|
||||||
}
|
}
|
||||||
|
@ -105,9 +114,13 @@ BT::Status BTCallMethod::_tick(double p_delta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Unsure how to detect call error, so we return SUCCESS for now...
|
// TODO: Unsure how to detect call error, so we return SUCCESS for now...
|
||||||
obj->callv(method, call_args);
|
result = obj->callv(method, call_args);
|
||||||
#endif // LIMBOAI_MODULE & LIMBOAI_GDEXTENSION
|
#endif // LIMBOAI_MODULE & LIMBOAI_GDEXTENSION
|
||||||
|
|
||||||
|
if (!result_var.is_empty()) {
|
||||||
|
get_blackboard()->set_var(result_var, result);
|
||||||
|
}
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,9 +135,12 @@ void BTCallMethod::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_args"), &BTCallMethod::get_args);
|
ClassDB::bind_method(D_METHOD("get_args"), &BTCallMethod::get_args);
|
||||||
ClassDB::bind_method(D_METHOD("set_include_delta", "p_include_delta"), &BTCallMethod::set_include_delta);
|
ClassDB::bind_method(D_METHOD("set_include_delta", "p_include_delta"), &BTCallMethod::set_include_delta);
|
||||||
ClassDB::bind_method(D_METHOD("is_delta_included"), &BTCallMethod::is_delta_included);
|
ClassDB::bind_method(D_METHOD("is_delta_included"), &BTCallMethod::is_delta_included);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_result_var", "p_result_var"), &BTCallMethod::set_result_var);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_result_var"), &BTCallMethod::get_result_var);
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "BBNode"), "set_node_param", "get_node_param");
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "BBNode"), "set_node_param", "get_node_param");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "method"), "set_method", "get_method");
|
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "method"), "set_method", "get_method");
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "result_var"), "set_result_var", "get_result_var");
|
||||||
ADD_GROUP("Arguments", "args_");
|
ADD_GROUP("Arguments", "args_");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "args_include_delta"), "set_include_delta", "is_delta_included");
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "args_include_delta"), "set_include_delta", "is_delta_included");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args"), "set_args", "get_args");
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "args"), "set_args", "get_args");
|
||||||
|
|
|
@ -25,6 +25,7 @@ private:
|
||||||
Ref<BBNode> node_param;
|
Ref<BBNode> node_param;
|
||||||
Array args;
|
Array args;
|
||||||
bool include_delta = false;
|
bool include_delta = false;
|
||||||
|
String result_var;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
@ -45,6 +46,9 @@ public:
|
||||||
void set_include_delta(bool p_include_delta);
|
void set_include_delta(bool p_include_delta);
|
||||||
bool is_delta_included() const { return include_delta; }
|
bool is_delta_included() const { return include_delta; }
|
||||||
|
|
||||||
|
void set_result_var(const String &p_result_var);
|
||||||
|
String get_result_var() const { return result_var; }
|
||||||
|
|
||||||
virtual PackedStringArray get_configuration_warnings() override;
|
virtual PackedStringArray get_configuration_warnings() override;
|
||||||
|
|
||||||
BTCallMethod();
|
BTCallMethod();
|
||||||
|
|
|
@ -136,4 +136,5 @@ LimboStringNames::LimboStringNames() {
|
||||||
|
|
||||||
EVENT_FINISHED = "finished";
|
EVENT_FINISHED = "finished";
|
||||||
repeat_forever.parse_utf8("Repeat ∞");
|
repeat_forever.parse_utf8("Repeat ∞");
|
||||||
|
output_var_prefix.parse_utf8("➜");
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ public:
|
||||||
|
|
||||||
String EVENT_FINISHED;
|
String EVENT_FINISHED;
|
||||||
String repeat_forever;
|
String repeat_forever;
|
||||||
|
String output_var_prefix;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LW_NAME(m_arg) LimboStringNames::get_singleton()->m_arg
|
#define LW_NAME(m_arg) LimboStringNames::get_singleton()->m_arg
|
||||||
|
|
Loading…
Reference in New Issue