BT*AgentProperty fixes

This commit is contained in:
Serhii Snitsaruk 2023-08-11 22:16:03 +02:00
parent 272824562b
commit f286673dde
7 changed files with 38 additions and 38 deletions

View File

@ -11,8 +11,8 @@
#include "bt_set_agent_property.h"
void BTSetAgentProperty::set_property_name(StringName p_prop) {
property_name = p_prop;
void BTSetAgentProperty::set_property(StringName p_prop) {
property = p_prop;
emit_changed();
}
@ -29,8 +29,8 @@ String BTSetAgentProperty::get_configuration_warning() const {
if (!warning.is_empty()) {
warning += "\n";
}
if (property_name == StringName()) {
warning += "`property_name` should be assigned.\n";
if (property == StringName()) {
warning += "`property` should be assigned.\n";
}
if (!value.is_valid()) {
warning += "`value` should be assigned.\n";
@ -39,30 +39,30 @@ String BTSetAgentProperty::get_configuration_warning() const {
}
String BTSetAgentProperty::_generate_name() const {
if (property_name == StringName()) {
if (property == StringName()) {
return "SetAgentProperty ???";
}
return vformat("Set agent.%s = %s", property_name,
return vformat("Set agent.%s = %s", property,
value.is_valid() ? Variant(value) : Variant("???"));
}
int BTSetAgentProperty::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(property_name == StringName(), FAILURE, "BTSetAgentProperty: `property_name` is not set.");
ERR_FAIL_COND_V_MSG(property == StringName(), FAILURE, "BTSetAgentProperty: `property` is not set.");
ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTSetAgentProperty: `value` is not set.");
bool r_valid;
get_agent()->set(property_name, value->get_value(get_agent(), get_blackboard()), &r_valid);
ERR_FAIL_COND_V_MSG(!r_valid, FAILURE, vformat("BTSetAgentProperty: Agent doesn't have property named \"%s\"", property_name));
get_agent()->set(property, value->get_value(get_agent(), get_blackboard()), &r_valid);
ERR_FAIL_COND_V_MSG(!r_valid, FAILURE, vformat("BTSetAgentProperty: Agent doesn't have property named \"%s\"", property));
return SUCCESS;
}
void BTSetAgentProperty::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_property_name", "p_property_name"), &BTSetAgentProperty::set_property_name);
ClassDB::bind_method(D_METHOD("get_property_name"), &BTSetAgentProperty::get_property_name);
ClassDB::bind_method(D_METHOD("set_property", "p_property"), &BTSetAgentProperty::set_property);
ClassDB::bind_method(D_METHOD("get_property"), &BTSetAgentProperty::get_property);
ClassDB::bind_method(D_METHOD("set_value", "p_value"), &BTSetAgentProperty::set_value);
ClassDB::bind_method(D_METHOD("get_value"), &BTSetAgentProperty::get_value);
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "property_name"), "set_property_name", "get_property_name");
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "property"), "set_property", "get_property");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "BBVariant"), "set_value", "get_value");
}

View File

@ -23,7 +23,7 @@ class BTSetAgentProperty : public BTAction {
GDCLASS(BTSetAgentProperty, BTAction);
private:
StringName property_name;
StringName property;
Ref<BBVariant> value;
protected:
@ -35,8 +35,8 @@ protected:
public:
virtual String get_configuration_warning() const override;
void set_property_name(StringName p_prop);
StringName get_property_name() const { return property_name; }
void set_property(StringName p_prop);
StringName get_property() const { return property; }
void set_value(Ref<BBVariant> p_value);
Ref<BBVariant> get_value() const { return value; }

View File

@ -15,8 +15,8 @@
#include "core/variant/callable.h"
void BTCheckAgentProperty::set_property_name(StringName p_prop) {
property_name = p_prop;
void BTCheckAgentProperty::set_property(StringName p_prop) {
property = p_prop;
emit_changed();
}
@ -38,8 +38,8 @@ String BTCheckAgentProperty::get_configuration_warning() const {
if (!warning.is_empty()) {
warning += "\n";
}
if (property_name == StringName()) {
warning += "`property_name` should be assigned.\n";
if (property == StringName()) {
warning += "`property` should be assigned.\n";
}
if (!value.is_valid()) {
warning += "`value` should be assigned.\n";
@ -48,22 +48,22 @@ String BTCheckAgentProperty::get_configuration_warning() const {
}
String BTCheckAgentProperty::_generate_name() const {
if (property_name == StringName()) {
if (property == StringName()) {
return "CheckAgentProperty ???";
}
return vformat("Check if: agent.%s %s %s", property_name,
return vformat("Check if: agent.%s %s %s", property,
LimboUtility::get_singleton()->get_check_operator_string(check_type),
value.is_valid() ? Variant(value) : Variant("???"));
}
int BTCheckAgentProperty::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(property_name == StringName(), FAILURE, "BTCheckAgentProperty: `property_name` is not set.");
ERR_FAIL_COND_V_MSG(property == StringName(), FAILURE, "BTCheckAgentProperty: `property` is not set.");
ERR_FAIL_COND_V_MSG(!value.is_valid(), FAILURE, "BTCheckAgentProperty: `value` is not set.");
bool r_valid;
Variant left_value = get_agent()->get(property_name, &r_valid);
ERR_FAIL_COND_V_MSG(r_valid == false, FAILURE, vformat("BTCheckAgentProperty: Agent has no property named \"%s\"", property_name));
Variant left_value = get_agent()->get(property, &r_valid);
ERR_FAIL_COND_V_MSG(r_valid == false, FAILURE, vformat("BTCheckAgentProperty: Agent has no property named \"%s\"", property));
Variant right_value = value->get_value(get_agent(), get_blackboard());
@ -71,14 +71,14 @@ int BTCheckAgentProperty::_tick(double p_delta) {
}
void BTCheckAgentProperty::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_property_name", "p_property_name"), &BTCheckAgentProperty::set_property_name);
ClassDB::bind_method(D_METHOD("get_property_name"), &BTCheckAgentProperty::get_property_name);
ClassDB::bind_method(D_METHOD("set_property", "p_property"), &BTCheckAgentProperty::set_property);
ClassDB::bind_method(D_METHOD("get_property"), &BTCheckAgentProperty::get_property);
ClassDB::bind_method(D_METHOD("set_check_type", "p_check_type"), &BTCheckAgentProperty::set_check_type);
ClassDB::bind_method(D_METHOD("get_check_type"), &BTCheckAgentProperty::get_check_type);
ClassDB::bind_method(D_METHOD("set_value", "p_value"), &BTCheckAgentProperty::set_value);
ClassDB::bind_method(D_METHOD("get_value"), &BTCheckAgentProperty::get_value);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property_name"), "set_property_name", "get_property_name");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property");
ADD_PROPERTY(PropertyInfo(Variant::INT, "check_type", PROPERTY_HINT_ENUM, "Equal,Less Than,Less Than Or Equal,Greater Than,Greater Than Or Equal,Not Equal"), "set_check_type", "get_check_type");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "value", PROPERTY_HINT_RESOURCE_TYPE, "BBVariant"), "set_value", "get_value");
}

View File

@ -24,7 +24,7 @@ class BTCheckAgentProperty : public BTCondition {
GDCLASS(BTCheckAgentProperty, BTCondition);
private:
StringName property_name;
StringName property;
LimboUtility::CheckType check_type = LimboUtility::CheckType::CHECK_EQUAL;
Ref<BBVariant> value;
@ -37,8 +37,8 @@ protected:
public:
virtual String get_configuration_warning() const override;
void set_property_name(StringName p_prop);
StringName get_property_name() const { return property_name; }
void set_property(StringName p_prop);
StringName get_property() const { return property; }
void set_check_type(LimboUtility::CheckType p_check_type);
LimboUtility::CheckType get_check_type() const { return check_type; }

View File

@ -6,7 +6,7 @@ saved_value = 200.0
type = 3
[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_0nprx"]
property_name = &"speed"
property = &"speed"
value = SubResource("BBVariant_5o8fh")
[sub_resource type="BTConsolePrint" id="BTConsolePrint_dlmwi"]
@ -28,7 +28,7 @@ saved_value = 300.0
type = 3
[sub_resource type="BTSetAgentProperty" id="BTSetAgentProperty_lh1xy"]
property_name = &"speed"
property = &"speed"
value = SubResource("BBVariant_r2elk")
[sub_resource type="BBVariant" id="BBVariant_jhcxn"]
@ -37,7 +37,7 @@ saved_value = 200.0
type = 3
[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_p20lt"]
property_name = &"speed"
property = &"speed"
check_type = 3
value = SubResource("BBVariant_jhcxn")
@ -60,7 +60,7 @@ saved_value = 400.0
type = 3
[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_avnfr"]
property_name = &"speed"
property = &"speed"
check_type = 1
value = SubResource("BBVariant_2aotu")
@ -83,7 +83,7 @@ saved_value = 300.0
type = 3
[sub_resource type="BTCheckAgentProperty" id="BTCheckAgentProperty_sayma"]
property_name = &"speed"
property = &"speed"
value = SubResource("BBVariant_28e2y")
[sub_resource type="BTConsolePrint" id="BTConsolePrint_xugph"]

View File

@ -12,8 +12,8 @@
<member name="check_type" type="int" setter="set_check_type" getter="get_check_type" enum="LimboUtility.CheckType" default="0">
Type of check to perform.
</member>
<member name="property_name" type="StringName" setter="set_property_name" getter="get_property_name" default="&amp;&quot;&quot;">
Parameter that specifies the agent's property name which will be compared.
<member name="property" type="StringName" setter="set_property" getter="get_property" default="&amp;&quot;&quot;">
Parameter that specifies the agent's property which will be compared.
</member>
<member name="value" type="BBVariant" setter="set_value" getter="get_value">
Parameter that specifies the value to which an agent's property will be compared.

View File

@ -10,7 +10,7 @@
<tutorials>
</tutorials>
<members>
<member name="property_name" type="StringName" setter="set_property_name" getter="get_property_name" default="&amp;&quot;&quot;">
<member name="property" type="StringName" setter="set_property" getter="get_property" default="&amp;&quot;&quot;">
Parameter that specifies the agent's property name.
</member>
<member name="value" type="BBVariant" setter="set_value" getter="get_value">