2023-08-10 11:04:53 +00:00
/**
* bt_check_agent_property . 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_agent_property.h"
2023-08-11 20:16:03 +00:00
void BTCheckAgentProperty : : set_property ( StringName p_prop ) {
property = p_prop ;
2023-08-10 11:04:53 +00:00
emit_changed ( ) ;
}
void BTCheckAgentProperty : : set_check_type ( LimboUtility : : CheckType p_check_type ) {
check_type = p_check_type ;
emit_changed ( ) ;
}
void BTCheckAgentProperty : : set_value ( Ref < BBVariant > p_value ) {
value = p_value ;
emit_changed ( ) ;
if ( Engine : : get_singleton ( ) - > is_editor_hint ( ) & & value . is_valid ( ) ) {
2024-01-09 12:42:54 +00:00
value - > connect ( LW_NAME ( changed ) , Callable ( this , LW_NAME ( emit_changed ) ) ) ;
2023-08-10 11:04:53 +00:00
}
}
2024-01-06 23:47:46 +00:00
PackedStringArray BTCheckAgentProperty : : get_configuration_warnings ( ) {
2023-08-15 15:05:30 +00:00
PackedStringArray warnings = BTCondition : : get_configuration_warnings ( ) ;
2023-08-11 20:16:03 +00:00
if ( property = = StringName ( ) ) {
2023-08-15 15:05:30 +00:00
warnings . append ( " `property` should be assigned. " ) ;
2023-08-10 11:04:53 +00:00
}
if ( ! value . is_valid ( ) ) {
2023-08-15 15:05:30 +00:00
warnings . append ( " `value` should be assigned. " ) ;
2023-08-10 11:04:53 +00:00
}
2023-08-15 15:05:30 +00:00
return warnings ;
2023-08-10 11:04:53 +00:00
}
2024-01-06 23:47:46 +00:00
String BTCheckAgentProperty : : _generate_name ( ) {
2023-08-11 20:16:03 +00:00
if ( property = = StringName ( ) ) {
2023-08-10 11:04:53 +00:00
return " CheckAgentProperty ??? " ;
}
2023-08-11 20:16:03 +00:00
return vformat ( " Check if: agent.%s %s %s " , property ,
2023-08-10 11:04:53 +00:00
LimboUtility : : get_singleton ( ) - > get_check_operator_string ( check_type ) ,
value . is_valid ( ) ? Variant ( value ) : Variant ( " ??? " ) ) ;
}
2023-09-19 11:43:26 +00:00
BT : : Status BTCheckAgentProperty : : _tick ( double p_delta ) {
2023-08-11 20:16:03 +00:00
ERR_FAIL_COND_V_MSG ( property = = StringName ( ) , FAILURE , " BTCheckAgentProperty: `property` is not set. " ) ;
2023-08-10 11:04:53 +00:00
ERR_FAIL_COND_V_MSG ( ! value . is_valid ( ) , FAILURE , " BTCheckAgentProperty: `value` is not set. " ) ;
2024-01-06 23:47:46 +00:00
# ifdef LIMBOAI_MODULE
2023-08-10 11:04:53 +00:00
bool r_valid ;
2023-08-11 20:16:03 +00:00
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 ) ) ;
2024-01-13 16:10:42 +00:00
# elif LIMBOAI_GDEXTENSION
2024-01-06 23:47:46 +00:00
Variant left_value = get_agent ( ) - > get ( property ) ;
# endif
2023-08-10 11:04:53 +00:00
Variant right_value = value - > get_value ( get_agent ( ) , get_blackboard ( ) ) ;
return LimboUtility : : get_singleton ( ) - > perform_check ( check_type , left_value , right_value ) ? SUCCESS : FAILURE ;
}
void BTCheckAgentProperty : : _bind_methods ( ) {
2023-08-11 20:16:03 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_property " , " p_property " ) , & BTCheckAgentProperty : : set_property ) ;
ClassDB : : bind_method ( D_METHOD ( " get_property " ) , & BTCheckAgentProperty : : get_property ) ;
2023-08-10 11:04:53 +00:00
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 ) ;
2023-08-11 20:16:03 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " property " ) , " set_property " , " get_property " ) ;
2023-08-10 11:04:53 +00:00
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 " ) ;
}