2017-03-05 14:47:28 +00:00
/*************************************************************************/
/* visual_script_func_nodes.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 12:16:55 +00:00
/* https://godotengine.org */
2017-03-05 14:47:28 +00:00
/*************************************************************************/
2021-01-01 19:13:46 +00:00
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
2017-03-05 14:47:28 +00:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2018-01-04 23:50:27 +00:00
2016-08-02 22:11:05 +00:00
# include "visual_script_func_nodes.h"
2017-03-05 14:47:28 +00:00
2020-11-07 22:33:38 +00:00
# include "core/config/engine.h"
2018-09-11 16:13:45 +00:00
# include "core/io/resource_loader.h"
# include "core/os/os.h"
2016-08-02 22:11:05 +00:00
# include "scene/main/node.h"
2017-06-27 01:58:03 +00:00
# include "scene/main/scene_tree.h"
2016-08-02 22:11:05 +00:00
# include "visual_script_nodes.h"
//////////////////////////////////////////
////////////////CALL//////////////////////
//////////////////////////////////////////
int VisualScriptFunctionCall : : get_output_sequence_port_count ( ) const {
2020-11-11 16:16:08 +00:00
if ( ( method_cache . flags & METHOD_FLAG_CONST & & call_mode ! = CALL_MODE_INSTANCE ) | | ( call_mode = = CALL_MODE_BASIC_TYPE & & Variant : : is_builtin_method_const ( basic_type , function ) ) ) {
2016-08-31 02:44:14 +00:00
return 0 ;
2020-05-14 14:41:43 +00:00
} else {
2016-08-31 02:44:14 +00:00
return 1 ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
bool VisualScriptFunctionCall : : has_input_sequence_port ( ) const {
2020-11-11 16:16:08 +00:00
return ! ( ( method_cache . flags & METHOD_FLAG_CONST & & call_mode ! = CALL_MODE_INSTANCE ) | | ( call_mode = = CALL_MODE_BASIC_TYPE & & Variant : : is_builtin_method_const ( basic_type , function ) ) ) ;
2016-08-02 22:11:05 +00:00
}
# ifdef TOOLS_ENABLED
2017-03-05 15:44:50 +00:00
static Node * _find_script_node ( Node * p_edited_scene , Node * p_current_node , const Ref < Script > & script ) {
2020-05-14 14:41:43 +00:00
if ( p_edited_scene ! = p_current_node & & p_current_node - > get_owner ( ) ! = p_edited_scene ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
Ref < Script > scr = p_current_node - > get_script ( ) ;
2020-05-14 14:41:43 +00:00
if ( scr . is_valid ( ) & & scr = = script ) {
2016-08-02 22:11:05 +00:00
return p_current_node ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < p_current_node - > get_child_count ( ) ; i + + ) {
Node * n = _find_script_node ( p_edited_scene , p_current_node - > get_child ( i ) , script ) ;
2020-05-14 14:41:43 +00:00
if ( n ) {
2016-08-02 22:11:05 +00:00
return n ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
}
2020-04-01 23:20:12 +00:00
return nullptr ;
2016-08-02 22:11:05 +00:00
}
# endif
Node * VisualScriptFunctionCall : : _get_base_node ( ) const {
# ifdef TOOLS_ENABLED
Ref < Script > script = get_visual_script ( ) ;
2020-05-14 14:41:43 +00:00
if ( ! script . is_valid ( ) ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
MainLoop * main_loop = OS : : get_singleton ( ) - > get_main_loop ( ) ;
2017-08-24 20:58:51 +00:00
SceneTree * scene_tree = Object : : cast_to < SceneTree > ( main_loop ) ;
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! scene_tree ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
Node * edited_scene = scene_tree - > get_edited_scene_root ( ) ;
2020-05-14 14:41:43 +00:00
if ( ! edited_scene ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
Node * script_node = _find_script_node ( edited_scene , edited_scene , script ) ;
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! script_node ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! script_node - > has_node ( base_path ) ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
Node * path_to = script_node - > get_node ( base_path ) ;
return path_to ;
# else
2020-04-01 23:20:12 +00:00
return nullptr ;
2016-08-02 22:11:05 +00:00
# endif
}
StringName VisualScriptFunctionCall : : _get_base_type ( ) const {
2020-05-14 14:41:43 +00:00
if ( call_mode = = CALL_MODE_SELF & & get_visual_script ( ) . is_valid ( ) ) {
2016-08-02 22:11:05 +00:00
return get_visual_script ( ) - > get_instance_base_type ( ) ;
2020-05-14 14:41:43 +00:00
} else if ( call_mode = = CALL_MODE_NODE_PATH & & get_visual_script ( ) . is_valid ( ) ) {
2016-08-02 22:11:05 +00:00
Node * path = _get_base_node ( ) ;
2020-05-14 14:41:43 +00:00
if ( path ) {
2017-01-03 02:03:46 +00:00
return path - > get_class ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
}
return base_type ;
}
2017-03-05 15:44:50 +00:00
int VisualScriptFunctionCall : : get_input_value_port_count ( ) const {
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2020-11-11 16:16:08 +00:00
Vector < Variant : : Type > types ;
int argc = Variant : : get_builtin_method_argument_count ( basic_type , function ) ;
for ( int i = 0 ; i < argc ; i + + ) {
types . push_back ( Variant : : get_builtin_method_argument_type ( basic_type , function , i ) ) ;
}
2019-03-04 20:39:17 +00:00
return types . size ( ) + ( rpc_call_mode > = RPC_RELIABLE_TO_ID ? 1 : 0 ) + 1 ;
2016-08-03 14:28:20 +00:00
} else {
2017-03-05 15:44:50 +00:00
MethodBind * mb = ClassDB : : get_method ( _get_base_type ( ) , function ) ;
2016-08-25 20:45:20 +00:00
if ( mb ) {
2019-09-13 19:14:12 +00:00
int defaulted_args = mb - > get_argument_count ( ) < use_default_args ? mb - > get_argument_count ( ) : use_default_args ;
return mb - > get_argument_count ( ) + ( call_mode = = CALL_MODE_INSTANCE ? 1 : 0 ) + ( rpc_call_mode > = RPC_RELIABLE_TO_ID ? 1 : 0 ) - defaulted_args ;
2016-08-25 20:45:20 +00:00
}
2016-08-03 14:28:20 +00:00
2019-09-13 19:14:12 +00:00
int defaulted_args = method_cache . arguments . size ( ) < use_default_args ? method_cache . arguments . size ( ) : use_default_args ;
return method_cache . arguments . size ( ) + ( call_mode = = CALL_MODE_INSTANCE ? 1 : 0 ) + ( rpc_call_mode > = RPC_RELIABLE_TO_ID ? 1 : 0 ) - defaulted_args ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2017-03-05 15:44:50 +00:00
int VisualScriptFunctionCall : : get_output_value_port_count ( ) const {
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2020-11-11 16:16:08 +00:00
bool returns = Variant : : has_builtin_method_return_value ( basic_type , function ) ;
2017-03-05 15:44:50 +00:00
return returns ? 1 : 0 ;
2016-08-03 14:28:20 +00:00
} else {
2016-08-28 23:57:27 +00:00
int ret ;
2017-03-05 15:44:50 +00:00
MethodBind * mb = ClassDB : : get_method ( _get_base_type ( ) , function ) ;
2016-08-25 20:45:20 +00:00
if ( mb ) {
2016-08-28 23:57:27 +00:00
ret = mb - > has_return ( ) ? 1 : 0 ;
2020-05-14 14:41:43 +00:00
} else {
2016-08-28 23:57:27 +00:00
ret = 1 ; //it is assumed that script always returns something
2020-05-14 14:41:43 +00:00
}
2016-08-28 23:57:27 +00:00
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_INSTANCE ) {
2016-08-28 23:57:27 +00:00
ret + + ;
2016-08-25 20:45:20 +00:00
}
2016-08-02 22:11:05 +00:00
2016-08-28 23:57:27 +00:00
return ret ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
}
String VisualScriptFunctionCall : : get_output_sequence_port_text ( int p_port ) const {
return String ( ) ;
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptFunctionCall : : get_input_value_port_info ( int p_idx ) const {
if ( call_mode = = CALL_MODE_INSTANCE | | call_mode = = CALL_MODE_BASIC_TYPE ) {
if ( p_idx = = 0 ) {
2016-08-02 22:11:05 +00:00
PropertyInfo pi ;
2017-03-05 15:44:50 +00:00
pi . type = ( call_mode = = CALL_MODE_INSTANCE ? Variant : : OBJECT : basic_type ) ;
pi . name = ( call_mode = = CALL_MODE_INSTANCE ? String ( " instance " ) : Variant : : get_type_name ( basic_type ) . to_lower ( ) ) ;
2016-08-02 22:11:05 +00:00
return pi ;
} else {
p_idx - - ;
}
}
2017-03-05 15:44:50 +00:00
if ( rpc_call_mode > = RPC_RELIABLE_TO_ID ) {
if ( p_idx = = 0 ) {
return PropertyInfo ( Variant : : INT , " peer_id " ) ;
2016-08-25 20:45:20 +00:00
} else {
p_idx - - ;
}
}
2016-08-02 22:11:05 +00:00
# ifdef DEBUG_METHODS_ENABLED
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2020-11-11 16:16:08 +00:00
return PropertyInfo ( Variant : : get_builtin_method_argument_type ( basic_type , function , p_idx ) , Variant : : get_builtin_method_argument_name ( basic_type , function , p_idx ) ) ;
2016-08-03 14:28:20 +00:00
} else {
2017-03-05 15:44:50 +00:00
MethodBind * mb = ClassDB : : get_method ( _get_base_type ( ) , function ) ;
2016-08-25 20:45:20 +00:00
if ( mb ) {
return mb - > get_argument_info ( p_idx ) ;
}
2017-03-05 15:44:50 +00:00
if ( p_idx > = 0 & & p_idx < method_cache . arguments . size ( ) ) {
2016-08-25 20:45:20 +00:00
return method_cache . arguments [ p_idx ] ;
}
2016-08-02 22:11:05 +00:00
2016-08-25 20:45:20 +00:00
return PropertyInfo ( ) ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
# else
return PropertyInfo ( ) ;
# endif
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptFunctionCall : : get_output_value_port_info ( int p_idx ) const {
2016-08-02 22:11:05 +00:00
# ifdef DEBUG_METHODS_ENABLED
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2020-11-11 16:16:08 +00:00
return PropertyInfo ( Variant : : get_builtin_method_return_type ( basic_type , function ) , " " ) ;
2016-08-03 14:28:20 +00:00
} else {
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_INSTANCE ) {
if ( p_idx = = 0 ) {
2018-05-13 03:34:35 +00:00
return PropertyInfo ( Variant : : OBJECT , " pass " , PROPERTY_HINT_TYPE_STRING , get_base_type ( ) ) ;
2016-08-28 23:57:27 +00:00
} else {
p_idx - - ;
}
}
PropertyInfo ret ;
2017-01-03 02:03:46 +00:00
/*MethodBind *mb = ClassDB::get_method(_get_base_type(),function);
2016-08-25 20:45:20 +00:00
if ( mb ) {
2016-08-28 23:57:27 +00:00
ret = mb - > get_argument_info ( - 1 ) ;
} else { */
ret = method_cache . return_val ;
//}
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_INSTANCE ) {
ret . name = " return " ;
2016-08-28 23:57:27 +00:00
} else {
2017-03-05 15:44:50 +00:00
ret . name = " " ;
2016-08-25 20:45:20 +00:00
}
2016-08-28 23:57:27 +00:00
return ret ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
# else
return PropertyInfo ( ) ;
# endif
}
String VisualScriptFunctionCall : : get_caption ( ) const {
2020-05-14 14:41:43 +00:00
if ( call_mode = = CALL_MODE_SELF ) {
2017-03-05 15:44:50 +00:00
return " " + String ( function ) + " () " ;
2020-05-14 14:41:43 +00:00
}
if ( call_mode = = CALL_MODE_SINGLETON ) {
2017-03-05 15:44:50 +00:00
return String ( singleton ) + " : " + String ( function ) + " () " ;
2020-05-14 14:41:43 +00:00
} else if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2017-03-05 15:44:50 +00:00
return Variant : : get_type_name ( basic_type ) + " . " + String ( function ) + " () " ;
2020-05-14 14:41:43 +00:00
} else if ( call_mode = = CALL_MODE_NODE_PATH ) {
2017-03-05 15:44:50 +00:00
return " [ " + String ( base_path . simplified ( ) ) + " ]. " + String ( function ) + " () " ;
2020-05-14 14:41:43 +00:00
} else {
2017-03-05 15:44:50 +00:00
return " " + base_type + " . " + String ( function ) + " () " ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
}
2018-04-29 23:28:31 +00:00
String VisualScriptFunctionCall : : get_text ( ) const {
if ( rpc_call_mode ) {
return " RPC " ;
}
return " " ;
}
2016-08-03 14:28:20 +00:00
void VisualScriptFunctionCall : : set_basic_type ( Variant : : Type p_type ) {
2020-05-14 14:41:43 +00:00
if ( basic_type = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
basic_type = p_type ;
2016-08-25 20:45:20 +00:00
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
Variant : : Type VisualScriptFunctionCall : : get_basic_type ( ) const {
2016-08-03 14:28:20 +00:00
return basic_type ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
void VisualScriptFunctionCall : : set_base_type ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( base_type = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
base_type = p_type ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
StringName VisualScriptFunctionCall : : get_base_type ( ) const {
2016-08-02 22:11:05 +00:00
return base_type ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptFunctionCall : : set_base_script ( const String & p_path ) {
2020-05-14 14:41:43 +00:00
if ( base_script = = p_path ) {
2016-08-25 20:45:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
base_script = p_path ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-25 20:45:20 +00:00
ports_changed_notify ( ) ;
}
String VisualScriptFunctionCall : : get_base_script ( ) const {
return base_script ;
}
2017-08-12 16:52:50 +00:00
void VisualScriptFunctionCall : : set_singleton ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( singleton = = p_type ) {
2016-08-28 23:57:27 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-28 23:57:27 +00:00
2017-08-12 16:52:50 +00:00
singleton = p_type ;
2017-11-13 20:46:57 +00:00
Object * obj = Engine : : get_singleton ( ) - > get_singleton_object ( singleton ) ;
2016-08-28 23:57:27 +00:00
if ( obj ) {
2017-03-05 15:44:50 +00:00
base_type = obj - > get_class ( ) ;
2016-08-28 23:57:27 +00:00
}
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-28 23:57:27 +00:00
ports_changed_notify ( ) ;
}
StringName VisualScriptFunctionCall : : get_singleton ( ) const {
return singleton ;
}
2016-08-25 20:45:20 +00:00
void VisualScriptFunctionCall : : _update_method_cache ( ) {
StringName type ;
Ref < Script > script ;
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_NODE_PATH ) {
Node * node = _get_base_node ( ) ;
2016-08-25 20:45:20 +00:00
if ( node ) {
2017-03-05 15:44:50 +00:00
type = node - > get_class ( ) ;
base_type = type ; //cache, too
2016-08-25 20:45:20 +00:00
script = node - > get_script ( ) ;
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF ) {
2016-08-25 20:45:20 +00:00
if ( get_visual_script ( ) . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
type = get_visual_script ( ) - > get_instance_base_type ( ) ;
base_type = type ; //cache, too
script = get_visual_script ( ) ;
2016-08-25 20:45:20 +00:00
}
2016-08-28 23:57:27 +00:00
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SINGLETON ) {
2017-11-13 20:46:57 +00:00
Object * obj = Engine : : get_singleton ( ) - > get_singleton_object ( singleton ) ;
2016-08-28 23:57:27 +00:00
if ( obj ) {
2017-03-05 15:44:50 +00:00
type = obj - > get_class ( ) ;
script = obj - > get_script ( ) ;
2016-08-28 23:57:27 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_INSTANCE ) {
type = base_type ;
if ( base_script ! = String ( ) ) {
2016-08-25 20:45:20 +00:00
if ( ! ResourceCache : : has ( base_script ) & & ScriptServer : : edit_request_func ) {
ScriptServer : : edit_request_func ( base_script ) ; //make sure it's loaded
}
if ( ResourceCache : : has ( base_script ) ) {
2017-03-05 15:44:50 +00:00
script = Ref < Resource > ( ResourceCache : : get ( base_script ) ) ;
2016-08-25 20:45:20 +00:00
} else {
return ;
}
}
}
2017-03-05 15:44:50 +00:00
MethodBind * mb = ClassDB : : get_method ( type , function ) ;
2016-08-25 20:45:20 +00:00
if ( mb ) {
2017-03-05 15:44:50 +00:00
use_default_args = mb - > get_default_argument_count ( ) ;
2016-08-25 20:45:20 +00:00
method_cache = MethodInfo ( ) ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < mb - > get_argument_count ( ) ; i + + ) {
2016-08-25 20:45:20 +00:00
# ifdef DEBUG_METHODS_ENABLED
method_cache . arguments . push_back ( mb - > get_argument_info ( i ) ) ;
# else
method_cache . arguments . push_back ( PropertyInfo ( ) ) ;
# endif
}
2016-08-31 02:44:14 +00:00
if ( mb - > is_const ( ) ) {
2017-03-05 15:44:50 +00:00
method_cache . flags | = METHOD_FLAG_CONST ;
2016-08-31 02:44:14 +00:00
}
2016-08-25 20:45:20 +00:00
# ifdef DEBUG_METHODS_ENABLED
2018-01-11 22:35:12 +00:00
method_cache . return_val = mb - > get_return_info ( ) ;
2016-08-25 20:45:20 +00:00
# endif
2016-09-07 22:39:02 +00:00
if ( mb - > is_vararg ( ) ) {
//for vararg just give it 10 arguments (should be enough for most use cases)
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < 10 ; i + + ) {
method_cache . arguments . push_back ( PropertyInfo ( Variant : : NIL , " arg " + itos ( i ) ) ) ;
2016-09-07 22:39:02 +00:00
use_default_args + + ;
}
}
2016-08-25 20:45:20 +00:00
} else if ( script . is_valid ( ) & & script - > has_method ( function ) ) {
method_cache = script - > get_method_info ( function ) ;
2017-03-05 15:44:50 +00:00
use_default_args = method_cache . default_arguments . size ( ) ;
2016-08-25 20:45:20 +00:00
}
}
2017-03-05 15:44:50 +00:00
void VisualScriptFunctionCall : : set_function ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( function = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
function = p_type ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2020-11-11 16:16:08 +00:00
use_default_args = Variant : : get_builtin_method_default_arguments ( basic_type , function ) . size ( ) ;
2016-08-25 20:45:20 +00:00
} else {
//update all caches
_update_method_cache ( ) ;
}
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
StringName VisualScriptFunctionCall : : get_function ( ) const {
return function ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptFunctionCall : : set_base_path ( const NodePath & p_type ) {
2020-05-14 14:41:43 +00:00
if ( base_path = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
base_path = p_type ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
NodePath VisualScriptFunctionCall : : get_base_path ( ) const {
return base_path ;
}
void VisualScriptFunctionCall : : set_call_mode ( CallMode p_mode ) {
2020-05-14 14:41:43 +00:00
if ( call_mode = = p_mode ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
call_mode = p_mode ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
VisualScriptFunctionCall : : CallMode VisualScriptFunctionCall : : get_call_mode ( ) const {
return call_mode ;
}
void VisualScriptFunctionCall : : set_use_default_args ( int p_amount ) {
2020-05-14 14:41:43 +00:00
if ( use_default_args = = p_amount ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
use_default_args = p_amount ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2016-08-25 20:45:20 +00:00
void VisualScriptFunctionCall : : set_rpc_call_mode ( VisualScriptFunctionCall : : RPCCallMode p_mode ) {
2020-05-14 14:41:43 +00:00
if ( rpc_call_mode = = p_mode ) {
2016-08-25 20:45:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
rpc_call_mode = p_mode ;
2016-08-25 20:45:20 +00:00
ports_changed_notify ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-25 20:45:20 +00:00
}
2017-03-05 15:44:50 +00:00
VisualScriptFunctionCall : : RPCCallMode VisualScriptFunctionCall : : get_rpc_call_mode ( ) const {
2016-08-25 20:45:20 +00:00
return rpc_call_mode ;
}
2017-03-05 15:44:50 +00:00
int VisualScriptFunctionCall : : get_use_default_args ( ) const {
2016-08-02 22:11:05 +00:00
return use_default_args ;
}
2016-08-25 20:45:20 +00:00
2016-08-31 20:58:51 +00:00
void VisualScriptFunctionCall : : set_validate ( bool p_amount ) {
2017-03-05 15:44:50 +00:00
validate = p_amount ;
2016-08-31 20:58:51 +00:00
}
bool VisualScriptFunctionCall : : get_validate ( ) const {
return validate ;
}
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
void VisualScriptFunctionCall : : _set_argument_cache ( const Dictionary & p_cache ) {
2016-08-25 20:45:20 +00:00
//so everything works in case all else fails
2017-03-05 15:44:50 +00:00
method_cache = MethodInfo : : from_dict ( p_cache ) ;
2016-08-25 20:45:20 +00:00
}
Dictionary VisualScriptFunctionCall : : _get_argument_cache ( ) const {
return method_cache ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptFunctionCall : : _validate_property ( PropertyInfo & property ) const {
2017-07-01 00:30:17 +00:00
if ( property . name = = " base_type " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_INSTANCE ) {
2018-01-11 22:35:12 +00:00
property . usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ;
2016-08-02 22:11:05 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " base_script " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_INSTANCE ) {
property . usage = 0 ;
2016-08-25 20:45:20 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " basic_type " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_BASIC_TYPE ) {
property . usage = 0 ;
2016-08-03 14:28:20 +00:00
}
}
2016-08-02 22:11:05 +00:00
2017-07-01 00:30:17 +00:00
if ( property . name = = " singleton " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_SINGLETON ) {
property . usage = 0 ;
2016-08-28 23:57:27 +00:00
} else {
2017-11-13 20:46:57 +00:00
List < Engine : : Singleton > names ;
Engine : : get_singleton ( ) - > get_singletons ( & names ) ;
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_ENUM ;
2016-08-28 23:57:27 +00:00
String sl ;
2017-11-13 20:46:57 +00:00
for ( List < Engine : : Singleton > : : Element * E = names . front ( ) ; E ; E = E - > next ( ) ) {
2020-05-14 14:41:43 +00:00
if ( sl ! = String ( ) ) {
2017-03-05 15:44:50 +00:00
sl + = " , " ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
sl + = E - > get ( ) . name ;
2016-08-28 23:57:27 +00:00
}
2017-03-05 15:44:50 +00:00
property . hint_string = sl ;
2016-08-28 23:57:27 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " node_path " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_NODE_PATH ) {
property . usage = 0 ;
2016-08-02 22:11:05 +00:00
} else {
Node * bnode = _get_base_node ( ) ;
if ( bnode ) {
2021-03-12 13:35:16 +00:00
property . hint_string = bnode - > get_path ( ) ; //convert to long string
2016-08-02 22:11:05 +00:00
}
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " function " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
property . hint = PROPERTY_HINT_METHOD_OF_VARIANT_TYPE ;
property . hint_string = Variant : : get_type_name ( basic_type ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF & & get_visual_script ( ) . is_valid ( ) ) {
property . hint = PROPERTY_HINT_METHOD_OF_SCRIPT ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( get_visual_script ( ) - > get_instance_id ( ) ) ;
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SINGLETON ) {
2017-11-13 20:46:57 +00:00
Object * obj = Engine : : get_singleton ( ) - > get_singleton_object ( singleton ) ;
2016-08-28 23:57:27 +00:00
if ( obj ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_METHOD_OF_INSTANCE ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( obj - > get_instance_id ( ) ) ;
2016-08-28 23:57:27 +00:00
} else {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE ;
property . hint_string = base_type ; //should be cached
2016-08-28 23:57:27 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_INSTANCE ) {
property . hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE ;
property . hint_string = base_type ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
if ( base_script ! = String ( ) ) {
2016-08-25 20:45:20 +00:00
if ( ! ResourceCache : : has ( base_script ) & & ScriptServer : : edit_request_func ) {
ScriptServer : : edit_request_func ( base_script ) ; //make sure it's loaded
}
if ( ResourceCache : : has ( base_script ) ) {
2017-03-05 15:44:50 +00:00
Ref < Script > script = Ref < Resource > ( ResourceCache : : get ( base_script ) ) ;
2016-08-25 20:45:20 +00:00
if ( script . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_METHOD_OF_SCRIPT ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( script - > get_instance_id ( ) ) ;
2016-08-25 20:45:20 +00:00
}
}
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_NODE_PATH ) {
2016-08-23 22:29:07 +00:00
Node * node = _get_base_node ( ) ;
if ( node ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_METHOD_OF_INSTANCE ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( node - > get_instance_id ( ) ) ;
2016-08-23 22:29:07 +00:00
} else {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE ;
property . hint_string = get_base_type ( ) ;
2016-08-23 22:29:07 +00:00
}
2016-08-02 22:11:05 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " use_default_args " ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_RANGE ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
int mc = 0 ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2020-11-11 16:16:08 +00:00
mc = Variant : : get_builtin_method_default_arguments ( basic_type , function ) . size ( ) ;
2016-08-03 14:28:20 +00:00
} else {
2017-03-05 15:44:50 +00:00
MethodBind * mb = ClassDB : : get_method ( _get_base_type ( ) , function ) ;
2016-08-03 14:28:20 +00:00
if ( mb ) {
2017-03-05 15:44:50 +00:00
mc = mb - > get_default_argument_count ( ) ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
if ( mc = = 0 ) {
property . usage = 0 ; //do not show
2016-08-03 14:28:20 +00:00
} else {
2017-03-05 15:44:50 +00:00
property . hint_string = " 0, " + itos ( mc ) + " ,1 " ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
}
2016-08-25 20:45:20 +00:00
2017-07-01 00:30:17 +00:00
if ( property . name = = " rpc_call_mode " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
property . usage = 0 ;
2016-08-25 20:45:20 +00:00
}
}
2016-08-02 22:11:05 +00:00
}
void VisualScriptFunctionCall : : _bind_methods ( ) {
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_type " , " base_type " ) , & VisualScriptFunctionCall : : set_base_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_type " ) , & VisualScriptFunctionCall : : get_base_type ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_script " , " base_script " ) , & VisualScriptFunctionCall : : set_base_script ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_script " ) , & VisualScriptFunctionCall : : get_base_script ) ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_basic_type " , " basic_type " ) , & VisualScriptFunctionCall : : set_basic_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_basic_type " ) , & VisualScriptFunctionCall : : get_basic_type ) ;
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_singleton " , " singleton " ) , & VisualScriptFunctionCall : : set_singleton ) ;
ClassDB : : bind_method ( D_METHOD ( " get_singleton " ) , & VisualScriptFunctionCall : : get_singleton ) ;
2016-08-28 23:57:27 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_function " , " function " ) , & VisualScriptFunctionCall : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualScriptFunctionCall : : get_function ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_call_mode " , " mode " ) , & VisualScriptFunctionCall : : set_call_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_call_mode " ) , & VisualScriptFunctionCall : : get_call_mode ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_path " , " base_path " ) , & VisualScriptFunctionCall : : set_base_path ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_path " ) , & VisualScriptFunctionCall : : get_base_path ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_use_default_args " , " amount " ) , & VisualScriptFunctionCall : : set_use_default_args ) ;
ClassDB : : bind_method ( D_METHOD ( " get_use_default_args " ) , & VisualScriptFunctionCall : : get_use_default_args ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " _set_argument_cache " , " argument_cache " ) , & VisualScriptFunctionCall : : _set_argument_cache ) ;
ClassDB : : bind_method ( D_METHOD ( " _get_argument_cache " ) , & VisualScriptFunctionCall : : _get_argument_cache ) ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_rpc_call_mode " , " mode " ) , & VisualScriptFunctionCall : : set_rpc_call_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_rpc_call_mode " ) , & VisualScriptFunctionCall : : get_rpc_call_mode ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_validate " , " enable " ) , & VisualScriptFunctionCall : : set_validate ) ;
ClassDB : : bind_method ( D_METHOD ( " get_validate " ) , & VisualScriptFunctionCall : : get_validate ) ;
2016-08-31 20:58:51 +00:00
2016-08-03 14:28:20 +00:00
String bt ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < Variant : : VARIANT_MAX ; i + + ) {
2020-05-14 14:41:43 +00:00
if ( i > 0 ) {
2017-03-05 15:44:50 +00:00
bt + = " , " ;
2020-05-14 14:41:43 +00:00
}
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
bt + = Variant : : get_type_name ( Variant : : Type ( i ) ) ;
2016-08-03 14:28:20 +00:00
}
2016-08-25 20:45:20 +00:00
List < String > script_extensions ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < ScriptServer : : get_language_count ( ) ; i + + ) {
2016-08-25 20:45:20 +00:00
ScriptServer : : get_language ( i ) - > get_recognized_extensions ( & script_extensions ) ;
}
String script_ext_hint ;
2017-03-05 15:44:50 +00:00
for ( List < String > : : Element * E = script_extensions . front ( ) ; E ; E = E - > next ( ) ) {
2020-05-14 14:41:43 +00:00
if ( script_ext_hint ! = String ( ) ) {
2017-03-05 15:44:50 +00:00
script_ext_hint + = " , " ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
script_ext_hint + = " *. " + E - > get ( ) ;
}
2017-07-01 00:30:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " call_mode " , PROPERTY_HINT_ENUM , " Self,Node Path,Instance,Basic Type,Singleton " ) , " set_call_mode " , " get_call_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " base_type " , PROPERTY_HINT_TYPE_STRING , " Object " ) , " set_base_type " , " get_base_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " base_script " , PROPERTY_HINT_FILE , script_ext_hint ) , " set_base_script " , " get_base_script " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " singleton " ) , " set_singleton " , " get_singleton " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " basic_type " , PROPERTY_HINT_ENUM , bt ) , " set_basic_type " , " get_basic_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : NODE_PATH , " node_path " , PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE ) , " set_base_path " , " get_base_path " ) ;
2018-01-11 22:35:12 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : DICTIONARY , " argument_cache " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ) , " _set_argument_cache " , " _get_argument_cache " ) ;
2017-07-01 00:30:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " function " ) , " set_function " , " get_function " ) ; //when set, if loaded properly, will override argument count.
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " use_default_args " ) , " set_use_default_args " , " get_use_default_args " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " validate " ) , " set_validate " , " get_validate " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " rpc_call_mode " , PROPERTY_HINT_ENUM , " Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID " ) , " set_rpc_call_mode " , " get_rpc_call_mode " ) ; //when set, if loaded properly, will override argument count.
2017-03-05 15:44:50 +00:00
2017-08-20 15:45:01 +00:00
BIND_ENUM_CONSTANT ( CALL_MODE_SELF ) ;
BIND_ENUM_CONSTANT ( CALL_MODE_NODE_PATH ) ;
BIND_ENUM_CONSTANT ( CALL_MODE_INSTANCE ) ;
BIND_ENUM_CONSTANT ( CALL_MODE_BASIC_TYPE ) ;
2017-09-12 19:09:06 +00:00
BIND_ENUM_CONSTANT ( CALL_MODE_SINGLETON ) ;
BIND_ENUM_CONSTANT ( RPC_DISABLED ) ;
BIND_ENUM_CONSTANT ( RPC_RELIABLE ) ;
BIND_ENUM_CONSTANT ( RPC_UNRELIABLE ) ;
BIND_ENUM_CONSTANT ( RPC_RELIABLE_TO_ID ) ;
BIND_ENUM_CONSTANT ( RPC_UNRELIABLE_TO_ID ) ;
2016-08-02 22:11:05 +00:00
}
2016-08-06 01:46:45 +00:00
class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance {
public :
VisualScriptFunctionCall : : CallMode call_mode ;
NodePath node_path ;
int input_args ;
2016-08-31 20:58:51 +00:00
bool validate ;
2017-09-30 14:18:50 +00:00
int returns ;
2016-08-25 20:45:20 +00:00
VisualScriptFunctionCall : : RPCCallMode rpc_mode ;
2016-08-06 01:46:45 +00:00
StringName function ;
2016-08-28 23:57:27 +00:00
StringName singleton ;
2016-08-06 01:46:45 +00:00
VisualScriptFunctionCall * node ;
VisualScriptInstance * instance ;
//virtual int get_working_memory_size() const { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
2017-03-05 15:44:50 +00:00
_FORCE_INLINE_ bool call_rpc ( Object * p_base , const Variant * * p_args , int p_argcount ) {
2020-05-14 14:41:43 +00:00
if ( ! p_base ) {
2016-08-25 20:45:20 +00:00
return false ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2017-08-24 20:58:51 +00:00
Node * node = Object : : cast_to < Node > ( p_base ) ;
2020-05-14 14:41:43 +00:00
if ( ! node ) {
2016-08-25 20:45:20 +00:00
return false ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
int to_id = 0 ;
2021-05-26 12:07:57 +00:00
//bool reliable = true;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
if ( rpc_mode > = VisualScriptFunctionCall : : RPC_RELIABLE_TO_ID ) {
2016-08-25 20:45:20 +00:00
to_id = * p_args [ 0 ] ;
2017-03-05 15:44:50 +00:00
p_args + = 1 ;
p_argcount - = 1 ;
2021-05-26 12:07:57 +00:00
//if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE_TO_ID) {
//reliable = false;
//}
2016-08-25 20:45:20 +00:00
}
2021-05-26 12:07:57 +00:00
//else if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE) {
//reliable = false;
//}
2016-08-25 20:45:20 +00:00
2021-05-26 12:07:57 +00:00
// TODO reliable?
node - > rpcp ( to_id , function , p_args , p_argcount ) ;
2016-08-25 20:45:20 +00:00
return true ;
}
2020-02-19 19:27:19 +00:00
virtual int step ( const Variant * * p_inputs , Variant * * p_outputs , StartMode p_start_mode , Variant * p_working_mem , Callable : : CallError & r_error , String & r_error_str ) {
2017-03-05 15:44:50 +00:00
switch ( call_mode ) {
2016-08-06 01:46:45 +00:00
case VisualScriptFunctionCall : : CALL_MODE_SELF : {
2017-03-05 15:44:50 +00:00
Object * object = instance - > get_owner_ptr ( ) ;
2016-08-06 01:46:45 +00:00
2016-08-25 20:45:20 +00:00
if ( rpc_mode ) {
2017-03-05 15:44:50 +00:00
call_rpc ( object , p_inputs , input_args ) ;
2016-08-25 20:45:20 +00:00
} else if ( returns ) {
2017-03-05 15:44:50 +00:00
* p_outputs [ 0 ] = object - > call ( function , p_inputs , input_args , r_error ) ;
2016-08-06 01:46:45 +00:00
} else {
2017-03-05 15:44:50 +00:00
object - > call ( function , p_inputs , input_args , r_error ) ;
2016-08-06 01:46:45 +00:00
}
} break ;
case VisualScriptFunctionCall : : CALL_MODE_NODE_PATH : {
2017-08-24 20:58:51 +00:00
Node * node = Object : : cast_to < Node > ( instance - > get_owner_ptr ( ) ) ;
2016-08-06 01:46:45 +00:00
if ( ! node ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Base object is not a Node! " ;
2016-08-06 01:46:45 +00:00
return 0 ;
}
2017-03-05 15:44:50 +00:00
Node * another = node - > get_node ( node_path ) ;
2017-08-25 15:14:33 +00:00
if ( ! another ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Path does not lead Node! " ;
2016-08-06 01:46:45 +00:00
return 0 ;
}
2016-08-25 20:45:20 +00:00
if ( rpc_mode ) {
2017-03-05 15:44:50 +00:00
call_rpc ( node , p_inputs , input_args ) ;
2016-08-25 20:45:20 +00:00
} else if ( returns ) {
2017-03-05 15:44:50 +00:00
* p_outputs [ 0 ] = another - > call ( function , p_inputs , input_args , r_error ) ;
2016-08-06 01:46:45 +00:00
} else {
2017-03-05 15:44:50 +00:00
another - > call ( function , p_inputs , input_args , r_error ) ;
2016-08-06 01:46:45 +00:00
}
} break ;
case VisualScriptFunctionCall : : CALL_MODE_INSTANCE :
case VisualScriptFunctionCall : : CALL_MODE_BASIC_TYPE : {
Variant v = * p_inputs [ 0 ] ;
2016-08-07 22:22:33 +00:00
2016-08-25 20:45:20 +00:00
if ( rpc_mode ) {
Object * obj = v ;
if ( obj ) {
2017-03-05 15:44:50 +00:00
call_rpc ( obj , p_inputs + 1 , input_args - 1 ) ;
2016-08-25 20:45:20 +00:00
}
} else if ( returns ) {
2017-03-05 15:44:50 +00:00
if ( call_mode = = VisualScriptFunctionCall : : CALL_MODE_INSTANCE ) {
2017-09-30 14:18:50 +00:00
if ( returns > = 2 ) {
2020-11-11 16:16:08 +00:00
v . call ( function , p_inputs + 1 , input_args , * p_outputs [ 1 ] , r_error ) ;
2017-11-08 19:34:05 +00:00
} else if ( returns = = 1 ) {
2020-11-11 16:16:08 +00:00
Variant ret ;
v . call ( function , p_inputs + 1 , input_args , ret , r_error ) ;
2017-09-30 14:18:50 +00:00
} else {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-09-30 14:18:50 +00:00
r_error_str = " Invalid returns count for call_mode == CALL_MODE_INSTANCE " ;
return 0 ;
}
2016-08-28 23:57:27 +00:00
} else {
2020-11-11 16:16:08 +00:00
v . call ( function , p_inputs + 1 , input_args , * p_outputs [ 0 ] , r_error ) ;
2016-08-28 23:57:27 +00:00
}
2016-08-06 01:46:45 +00:00
} else {
2020-11-11 16:16:08 +00:00
Variant ret ;
v . call ( function , p_inputs + 1 , input_args , ret , r_error ) ;
2016-08-06 01:46:45 +00:00
}
2017-03-05 15:44:50 +00:00
if ( call_mode = = VisualScriptFunctionCall : : CALL_MODE_INSTANCE ) {
* p_outputs [ 0 ] = * p_inputs [ 0 ] ;
2016-08-28 23:57:27 +00:00
}
2016-08-06 01:46:45 +00:00
} break ;
2016-08-28 23:57:27 +00:00
case VisualScriptFunctionCall : : CALL_MODE_SINGLETON : {
2017-11-13 20:46:57 +00:00
Object * object = Engine : : get_singleton ( ) - > get_singleton_object ( singleton ) ;
2016-08-28 23:57:27 +00:00
if ( ! object ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Invalid singleton name: ' " + String ( singleton ) + " ' " ;
2016-08-28 23:57:27 +00:00
return 0 ;
}
2016-08-06 01:46:45 +00:00
2016-08-28 23:57:27 +00:00
if ( rpc_mode ) {
2017-03-05 15:44:50 +00:00
call_rpc ( object , p_inputs , input_args ) ;
2016-08-28 23:57:27 +00:00
} else if ( returns ) {
2017-03-05 15:44:50 +00:00
* p_outputs [ 0 ] = object - > call ( function , p_inputs , input_args , r_error ) ;
2016-08-28 23:57:27 +00:00
} else {
2017-03-05 15:44:50 +00:00
object - > call ( function , p_inputs , input_args , r_error ) ;
2016-08-28 23:57:27 +00:00
}
} break ;
2016-08-06 01:46:45 +00:00
}
2016-08-31 20:58:51 +00:00
if ( ! validate ) {
//ignore call errors if validation is disabled
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_OK ;
2017-03-05 15:44:50 +00:00
r_error_str = String ( ) ;
2016-08-31 20:58:51 +00:00
}
2016-08-06 01:46:45 +00:00
return 0 ;
}
} ;
2021-06-17 22:03:09 +00:00
VisualScriptNodeInstance * VisualScriptFunctionCall : : instantiate ( VisualScriptInstance * p_instance ) {
2017-03-05 15:44:50 +00:00
VisualScriptNodeInstanceFunctionCall * instance = memnew ( VisualScriptNodeInstanceFunctionCall ) ;
instance - > node = this ;
instance - > instance = p_instance ;
instance - > singleton = singleton ;
instance - > function = function ;
instance - > call_mode = call_mode ;
instance - > returns = get_output_value_port_count ( ) ;
instance - > node_path = base_path ;
instance - > input_args = get_input_value_port_count ( ) - ( ( call_mode = = CALL_MODE_BASIC_TYPE | | call_mode = = CALL_MODE_INSTANCE ) ? 1 : 0 ) ;
instance - > rpc_mode = rpc_call_mode ;
instance - > validate = validate ;
2016-08-06 01:46:45 +00:00
return instance ;
}
2016-09-03 17:58:23 +00:00
2017-03-05 15:44:50 +00:00
VisualScriptFunctionCall : : TypeGuess VisualScriptFunctionCall : : guess_output_type ( TypeGuess * p_inputs , int p_output ) const {
if ( p_output = = 0 & & call_mode = = CALL_MODE_INSTANCE ) {
2016-09-03 17:58:23 +00:00
return p_inputs [ 0 ] ;
}
2017-03-05 15:44:50 +00:00
return VisualScriptNode : : guess_output_type ( p_inputs , p_output ) ;
2016-09-03 17:58:23 +00:00
}
2016-08-02 22:11:05 +00:00
VisualScriptFunctionCall : : VisualScriptFunctionCall ( ) {
2017-03-05 15:44:50 +00:00
validate = true ;
call_mode = CALL_MODE_SELF ;
basic_type = Variant : : NIL ;
use_default_args = 0 ;
base_type = " Object " ;
rpc_call_mode = RPC_DISABLED ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
template < VisualScriptFunctionCall : : CallMode cmode >
static Ref < VisualScriptNode > create_function_call_node ( const String & p_name ) {
2016-08-02 22:11:05 +00:00
Ref < VisualScriptFunctionCall > node ;
2021-06-17 22:03:09 +00:00
node . instantiate ( ) ;
2016-08-02 22:11:05 +00:00
node - > set_call_mode ( cmode ) ;
return node ;
}
//////////////////////////////////////////
////////////////SET//////////////////////
//////////////////////////////////////////
int VisualScriptPropertySet : : get_output_sequence_port_count ( ) const {
2017-03-05 15:44:50 +00:00
return call_mode ! = CALL_MODE_BASIC_TYPE ? 1 : 0 ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
bool VisualScriptPropertySet : : has_input_sequence_port ( ) const {
2019-06-26 13:08:25 +00:00
return call_mode ! = CALL_MODE_BASIC_TYPE ;
2016-08-02 22:11:05 +00:00
}
Node * VisualScriptPropertySet : : _get_base_node ( ) const {
# ifdef TOOLS_ENABLED
Ref < Script > script = get_visual_script ( ) ;
2020-05-14 14:41:43 +00:00
if ( ! script . is_valid ( ) ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
MainLoop * main_loop = OS : : get_singleton ( ) - > get_main_loop ( ) ;
2016-08-02 22:11:05 +00:00
2017-08-24 20:58:51 +00:00
SceneTree * scene_tree = Object : : cast_to < SceneTree > ( main_loop ) ;
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! scene_tree ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
Node * edited_scene = scene_tree - > get_edited_scene_root ( ) ;
2020-05-14 14:41:43 +00:00
if ( ! edited_scene ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
Node * script_node = _find_script_node ( edited_scene , edited_scene , script ) ;
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! script_node ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! script_node - > has_node ( base_path ) ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
Node * path_to = script_node - > get_node ( base_path ) ;
return path_to ;
# else
2020-04-01 23:20:12 +00:00
return nullptr ;
2016-08-02 22:11:05 +00:00
# endif
}
StringName VisualScriptPropertySet : : _get_base_type ( ) const {
2020-05-14 14:41:43 +00:00
if ( call_mode = = CALL_MODE_SELF & & get_visual_script ( ) . is_valid ( ) ) {
2016-08-02 22:11:05 +00:00
return get_visual_script ( ) - > get_instance_base_type ( ) ;
2020-05-14 14:41:43 +00:00
} else if ( call_mode = = CALL_MODE_NODE_PATH & & get_visual_script ( ) . is_valid ( ) ) {
2016-08-02 22:11:05 +00:00
Node * path = _get_base_node ( ) ;
2020-05-14 14:41:43 +00:00
if ( path ) {
2017-01-03 02:03:46 +00:00
return path - > get_class ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
}
return base_type ;
}
2017-03-05 15:44:50 +00:00
int VisualScriptPropertySet : : get_input_value_port_count ( ) const {
int pc = ( call_mode = = CALL_MODE_BASIC_TYPE | | call_mode = = CALL_MODE_INSTANCE ) ? 2 : 1 ;
2016-08-02 22:11:05 +00:00
2016-08-03 14:28:20 +00:00
return pc ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2017-03-05 15:44:50 +00:00
int VisualScriptPropertySet : : get_output_value_port_count ( ) const {
return ( call_mode = = CALL_MODE_BASIC_TYPE | | call_mode = = CALL_MODE_INSTANCE ) ? 1 : 0 ;
2016-08-02 22:11:05 +00:00
}
String VisualScriptPropertySet : : get_output_sequence_port_text ( int p_port ) const {
return String ( ) ;
}
2017-07-01 00:30:17 +00:00
void VisualScriptPropertySet : : _adjust_input_index ( PropertyInfo & pinfo ) const {
if ( index ! = StringName ( ) ) {
Variant v ;
2020-02-19 19:27:19 +00:00
Callable : : CallError ce ;
2020-11-09 03:19:09 +00:00
Variant : : construct ( pinfo . type , v , nullptr , 0 , ce ) ;
2017-07-01 00:30:17 +00:00
Variant i = v . get ( index ) ;
pinfo . type = i . get_type ( ) ;
}
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptPropertySet : : get_input_value_port_info ( int p_idx ) const {
if ( call_mode = = CALL_MODE_INSTANCE | | call_mode = = CALL_MODE_BASIC_TYPE ) {
if ( p_idx = = 0 ) {
2016-08-02 22:11:05 +00:00
PropertyInfo pi ;
2017-03-05 15:44:50 +00:00
pi . type = ( call_mode = = CALL_MODE_INSTANCE ? Variant : : OBJECT : basic_type ) ;
pi . name = ( call_mode = = CALL_MODE_INSTANCE ? String ( " instance " ) : Variant : : get_type_name ( basic_type ) . to_lower ( ) ) ;
2017-07-01 00:30:17 +00:00
_adjust_input_index ( pi ) ;
2016-08-02 22:11:05 +00:00
return pi ;
}
}
2019-05-25 22:29:21 +00:00
List < PropertyInfo > props ;
2019-10-09 05:47:05 +00:00
ClassDB : : get_property_list ( _get_base_type ( ) , & props , false ) ;
2019-05-25 22:29:21 +00:00
for ( List < PropertyInfo > : : Element * E = props . front ( ) ; E ; E = E - > next ( ) ) {
if ( E - > get ( ) . name = = property ) {
PropertyInfo pinfo = PropertyInfo ( E - > get ( ) . type , " value " , PROPERTY_HINT_TYPE_STRING , E - > get ( ) . hint_string ) ;
_adjust_input_index ( pinfo ) ;
return pinfo ;
}
}
2017-03-05 15:44:50 +00:00
PropertyInfo pinfo = type_cache ;
pinfo . name = " value " ;
2017-07-01 00:30:17 +00:00
_adjust_input_index ( pinfo ) ;
2016-08-25 20:45:20 +00:00
return pinfo ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptPropertySet : : get_output_value_port_info ( int p_idx ) const {
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
return PropertyInfo ( basic_type , " out " ) ;
} else if ( call_mode = = CALL_MODE_INSTANCE ) {
2018-05-13 03:34:35 +00:00
return PropertyInfo ( Variant : : OBJECT , " pass " , PROPERTY_HINT_TYPE_STRING , get_base_type ( ) ) ;
2016-08-07 22:22:33 +00:00
} else {
return PropertyInfo ( ) ;
}
2016-08-02 22:11:05 +00:00
}
String VisualScriptPropertySet : : get_caption ( ) const {
2017-07-01 00:30:17 +00:00
static const char * opname [ ASSIGN_OP_MAX ] = {
2018-04-30 22:39:28 +00:00
" Set " , " Add " , " Subtract " , " Multiply " , " Divide " , " Mod " , " ShiftLeft " , " ShiftRight " , " BitAnd " , " BitOr " , " BitXor "
2017-07-01 00:30:17 +00:00
} ;
2018-04-30 22:39:28 +00:00
String prop = String ( opname [ assign_op ] ) + " " + property ;
if ( index ! = StringName ( ) ) {
prop + = " . " + String ( index ) ;
}
return prop ;
2016-08-02 22:11:05 +00:00
}
String VisualScriptPropertySet : : get_text ( ) const {
2018-04-30 22:39:28 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
return String ( " On " ) + Variant : : get_type_name ( basic_type ) ;
}
2016-08-03 14:28:20 +00:00
2018-04-30 22:39:28 +00:00
static const char * cname [ 3 ] = {
" Self " ,
" Scene Node " ,
" Instance "
} ;
2016-08-03 14:28:20 +00:00
2018-04-30 22:39:28 +00:00
return String ( " On " ) + cname [ call_mode ] ;
2016-08-03 14:28:20 +00:00
}
2016-08-04 01:06:39 +00:00
void VisualScriptPropertySet : : _update_base_type ( ) {
//cache it because this information may not be available on load
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_NODE_PATH ) {
Node * node = _get_base_node ( ) ;
2016-08-04 01:06:39 +00:00
if ( node ) {
2017-03-05 15:44:50 +00:00
base_type = node - > get_class ( ) ;
2016-08-04 01:06:39 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF ) {
2016-08-04 01:06:39 +00:00
if ( get_visual_script ( ) . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
base_type = get_visual_script ( ) - > get_instance_base_type ( ) ;
2016-08-04 01:06:39 +00:00
}
}
}
2020-05-14 12:29:06 +00:00
2016-08-03 14:28:20 +00:00
void VisualScriptPropertySet : : set_basic_type ( Variant : : Type p_type ) {
2020-05-14 14:41:43 +00:00
if ( basic_type = = p_type ) {
2016-08-03 14:28:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
basic_type = p_type ;
2016-08-03 14:28:20 +00:00
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
_update_base_type ( ) ;
ports_changed_notify ( ) ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
Variant : : Type VisualScriptPropertySet : : get_basic_type ( ) const {
2016-08-03 14:28:20 +00:00
return basic_type ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertySet : : set_base_type ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( base_type = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
base_type = p_type ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
StringName VisualScriptPropertySet : : get_base_type ( ) const {
2016-08-02 22:11:05 +00:00
return base_type ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertySet : : set_base_script ( const String & p_path ) {
2020-05-14 14:41:43 +00:00
if ( base_script = = p_path ) {
2016-08-25 20:45:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
base_script = p_path ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-25 20:45:20 +00:00
ports_changed_notify ( ) ;
}
String VisualScriptPropertySet : : get_base_script ( ) const {
return base_script ;
}
void VisualScriptPropertySet : : _update_cache ( ) {
2020-05-14 14:41:43 +00:00
if ( ! Object : : cast_to < SceneTree > ( OS : : get_singleton ( ) - > get_main_loop ( ) ) ) {
2016-08-25 20:45:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2020-05-14 14:41:43 +00:00
if ( ! Engine : : get_singleton ( ) - > is_editor_hint ( ) ) { //only update cache if editor exists, it's pointless otherwise
2016-08-25 20:45:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2016-08-25 20:45:20 +00:00
//not super efficient..
Variant v ;
2020-02-19 19:27:19 +00:00
Callable : : CallError ce ;
2020-11-09 03:19:09 +00:00
Variant : : construct ( basic_type , v , nullptr , 0 , ce ) ;
2016-08-25 20:45:20 +00:00
List < PropertyInfo > pinfo ;
v . get_property_list ( & pinfo ) ;
2017-03-05 15:44:50 +00:00
for ( List < PropertyInfo > : : Element * E = pinfo . front ( ) ; E ; E = E - > next ( ) ) {
if ( E - > get ( ) . name = = property ) {
type_cache = E - > get ( ) ;
2016-08-25 20:45:20 +00:00
}
}
} else {
StringName type ;
Ref < Script > script ;
2020-04-01 23:20:12 +00:00
Node * node = nullptr ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_NODE_PATH ) {
node = _get_base_node ( ) ;
2016-08-25 20:45:20 +00:00
if ( node ) {
2017-03-05 15:44:50 +00:00
type = node - > get_class ( ) ;
base_type = type ; //cache, too
2016-08-25 20:45:20 +00:00
script = node - > get_script ( ) ;
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF ) {
2016-08-25 20:45:20 +00:00
if ( get_visual_script ( ) . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
type = get_visual_script ( ) - > get_instance_base_type ( ) ;
base_type = type ; //cache, too
script = get_visual_script ( ) ;
2016-08-25 20:45:20 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_INSTANCE ) {
type = base_type ;
if ( base_script ! = String ( ) ) {
2016-08-25 20:45:20 +00:00
if ( ! ResourceCache : : has ( base_script ) & & ScriptServer : : edit_request_func ) {
ScriptServer : : edit_request_func ( base_script ) ; //make sure it's loaded
}
if ( ResourceCache : : has ( base_script ) ) {
2017-03-05 15:44:50 +00:00
script = Ref < Resource > ( ResourceCache : : get ( base_script ) ) ;
2016-08-25 20:45:20 +00:00
} else {
return ;
}
}
}
List < PropertyInfo > pinfo ;
if ( node ) {
node - > get_property_list ( & pinfo ) ;
} else {
2017-03-05 15:44:50 +00:00
ClassDB : : get_property_list ( type , & pinfo ) ;
2016-08-25 20:45:20 +00:00
}
if ( script . is_valid ( ) ) {
script - > get_script_property_list ( & pinfo ) ;
}
2017-03-05 15:44:50 +00:00
for ( List < PropertyInfo > : : Element * E = pinfo . front ( ) ; E ; E = E - > next ( ) ) {
if ( E - > get ( ) . name = = property ) {
type_cache = E - > get ( ) ;
2016-08-25 20:45:20 +00:00
return ;
}
}
}
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertySet : : set_property ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( property = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
property = p_type ;
2017-07-01 00:30:17 +00:00
index = StringName ( ) ;
2016-08-25 20:45:20 +00:00
_update_cache ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
StringName VisualScriptPropertySet : : get_property ( ) const {
return property ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertySet : : set_base_path ( const NodePath & p_type ) {
2020-05-14 14:41:43 +00:00
if ( base_path = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
base_path = p_type ;
2016-08-04 01:06:39 +00:00
_update_base_type ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
NodePath VisualScriptPropertySet : : get_base_path ( ) const {
return base_path ;
}
void VisualScriptPropertySet : : set_call_mode ( CallMode p_mode ) {
2020-05-14 14:41:43 +00:00
if ( call_mode = = p_mode ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
call_mode = p_mode ;
2016-08-04 01:06:39 +00:00
_update_base_type ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
VisualScriptPropertySet : : CallMode VisualScriptPropertySet : : get_call_mode ( ) const {
return call_mode ;
}
2016-08-25 20:45:20 +00:00
void VisualScriptPropertySet : : _set_type_cache ( const Dictionary & p_type ) {
2017-03-05 15:44:50 +00:00
type_cache = PropertyInfo : : from_dict ( p_type ) ;
2016-08-25 20:45:20 +00:00
}
Dictionary VisualScriptPropertySet : : _get_type_cache ( ) const {
return type_cache ;
}
2017-07-01 00:30:17 +00:00
void VisualScriptPropertySet : : set_index ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( index = = p_type ) {
2017-07-01 00:30:17 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2017-07-01 00:30:17 +00:00
index = p_type ;
_update_cache ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2017-07-01 00:30:17 +00:00
ports_changed_notify ( ) ;
}
StringName VisualScriptPropertySet : : get_index ( ) const {
return index ;
}
void VisualScriptPropertySet : : set_assign_op ( AssignOp p_op ) {
ERR_FAIL_INDEX ( p_op , ASSIGN_OP_MAX ) ;
2020-05-14 14:41:43 +00:00
if ( assign_op = = p_op ) {
2017-07-01 00:30:17 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2017-07-01 00:30:17 +00:00
assign_op = p_op ;
_update_cache ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2017-07-01 00:30:17 +00:00
ports_changed_notify ( ) ;
}
VisualScriptPropertySet : : AssignOp VisualScriptPropertySet : : get_assign_op ( ) const {
return assign_op ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertySet : : _validate_property ( PropertyInfo & property ) const {
2017-07-01 00:30:17 +00:00
if ( property . name = = " base_type " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_INSTANCE ) {
2018-01-11 22:35:12 +00:00
property . usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ;
2016-08-02 22:11:05 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " base_script " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_INSTANCE ) {
property . usage = 0 ;
2016-08-25 20:45:20 +00:00
}
}
2016-08-02 22:11:05 +00:00
2017-07-01 00:30:17 +00:00
if ( property . name = = " basic_type " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_BASIC_TYPE ) {
property . usage = 0 ;
2016-08-03 14:28:20 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " node_path " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_NODE_PATH ) {
property . usage = 0 ;
2016-08-02 22:11:05 +00:00
} else {
Node * bnode = _get_base_node ( ) ;
if ( bnode ) {
2021-03-12 13:35:16 +00:00
property . hint_string = bnode - > get_path ( ) ; //convert to long string
2016-08-02 22:11:05 +00:00
}
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " property " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
property . hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE ;
property . hint_string = Variant : : get_type_name ( basic_type ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF & & get_visual_script ( ) . is_valid ( ) ) {
property . hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( get_visual_script ( ) - > get_instance_id ( ) ) ;
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_INSTANCE ) {
property . hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE ;
property . hint_string = base_type ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
if ( base_script ! = String ( ) ) {
2016-08-25 20:45:20 +00:00
if ( ! ResourceCache : : has ( base_script ) & & ScriptServer : : edit_request_func ) {
ScriptServer : : edit_request_func ( base_script ) ; //make sure it's loaded
}
if ( ResourceCache : : has ( base_script ) ) {
2017-03-05 15:44:50 +00:00
Ref < Script > script = Ref < Resource > ( ResourceCache : : get ( base_script ) ) ;
2016-08-25 20:45:20 +00:00
if ( script . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( script - > get_instance_id ( ) ) ;
2016-08-25 20:45:20 +00:00
}
}
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_NODE_PATH ) {
2016-08-23 22:29:07 +00:00
Node * node = _get_base_node ( ) ;
if ( node ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( node - > get_instance_id ( ) ) ;
2016-08-02 22:11:05 +00:00
} else {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE ;
property . hint_string = get_base_type ( ) ;
2016-08-02 22:11:05 +00:00
}
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " index " ) {
2020-02-19 19:27:19 +00:00
Callable : : CallError ce ;
2020-11-09 03:19:09 +00:00
Variant v ;
Variant : : construct ( type_cache . type , v , nullptr , 0 , ce ) ;
2017-07-01 00:30:17 +00:00
List < PropertyInfo > plist ;
v . get_property_list ( & plist ) ;
String options = " " ;
for ( List < PropertyInfo > : : Element * E = plist . front ( ) ; E ; E = E - > next ( ) ) {
options + = " , " + E - > get ( ) . name ;
}
property . hint = PROPERTY_HINT_ENUM ;
property . hint_string = options ;
property . type = Variant : : STRING ;
2020-05-14 14:41:43 +00:00
if ( options = = " " ) {
2017-07-01 00:30:17 +00:00
property . usage = 0 ; //hide if type has no usable index
2020-05-14 14:41:43 +00:00
}
2017-07-01 00:30:17 +00:00
}
2016-08-02 22:11:05 +00:00
}
void VisualScriptPropertySet : : _bind_methods ( ) {
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_type " , " base_type " ) , & VisualScriptPropertySet : : set_base_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_type " ) , & VisualScriptPropertySet : : get_base_type ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_script " , " base_script " ) , & VisualScriptPropertySet : : set_base_script ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_script " ) , & VisualScriptPropertySet : : get_base_script ) ;
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_basic_type " , " basic_type " ) , & VisualScriptPropertySet : : set_basic_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_basic_type " ) , & VisualScriptPropertySet : : get_basic_type ) ;
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " _set_type_cache " , " type_cache " ) , & VisualScriptPropertySet : : _set_type_cache ) ;
ClassDB : : bind_method ( D_METHOD ( " _get_type_cache " ) , & VisualScriptPropertySet : : _get_type_cache ) ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_property " , " property " ) , & VisualScriptPropertySet : : set_property ) ;
ClassDB : : bind_method ( D_METHOD ( " get_property " ) , & VisualScriptPropertySet : : get_property ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_call_mode " , " mode " ) , & VisualScriptPropertySet : : set_call_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_call_mode " ) , & VisualScriptPropertySet : : get_call_mode ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_path " , " base_path " ) , & VisualScriptPropertySet : : set_base_path ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_path " ) , & VisualScriptPropertySet : : get_base_path ) ;
2016-08-02 22:11:05 +00:00
2017-07-01 00:30:17 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_index " , " index " ) , & VisualScriptPropertySet : : set_index ) ;
ClassDB : : bind_method ( D_METHOD ( " get_index " ) , & VisualScriptPropertySet : : get_index ) ;
ClassDB : : bind_method ( D_METHOD ( " set_assign_op " , " assign_op " ) , & VisualScriptPropertySet : : set_assign_op ) ;
ClassDB : : bind_method ( D_METHOD ( " get_assign_op " ) , & VisualScriptPropertySet : : get_assign_op ) ;
2016-08-03 14:28:20 +00:00
String bt ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < Variant : : VARIANT_MAX ; i + + ) {
2020-05-14 14:41:43 +00:00
if ( i > 0 ) {
2017-03-05 15:44:50 +00:00
bt + = " , " ;
2020-05-14 14:41:43 +00:00
}
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
bt + = Variant : : get_type_name ( Variant : : Type ( i ) ) ;
2016-08-03 14:28:20 +00:00
}
2016-08-25 20:45:20 +00:00
List < String > script_extensions ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < ScriptServer : : get_language_count ( ) ; i + + ) {
2016-08-25 20:45:20 +00:00
ScriptServer : : get_language ( i ) - > get_recognized_extensions ( & script_extensions ) ;
}
String script_ext_hint ;
2017-03-05 15:44:50 +00:00
for ( List < String > : : Element * E = script_extensions . front ( ) ; E ; E = E - > next ( ) ) {
2020-05-14 14:41:43 +00:00
if ( script_ext_hint ! = String ( ) ) {
2017-03-05 15:44:50 +00:00
script_ext_hint + = " , " ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
script_ext_hint + = " *. " + E - > get ( ) ;
2016-08-25 20:45:20 +00:00
}
2016-08-07 22:22:33 +00:00
2017-07-01 00:30:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " set_mode " , PROPERTY_HINT_ENUM , " Self,Node Path,Instance,Basic Type " ) , " set_call_mode " , " get_call_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " base_type " , PROPERTY_HINT_TYPE_STRING , " Object " ) , " set_base_type " , " get_base_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " base_script " , PROPERTY_HINT_FILE , script_ext_hint ) , " set_base_script " , " get_base_script " ) ;
2018-01-11 22:35:12 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " type_cache " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ) , " _set_type_cache " , " _get_type_cache " ) ;
2017-07-01 00:30:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " basic_type " , PROPERTY_HINT_ENUM , bt ) , " set_basic_type " , " get_basic_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : NODE_PATH , " node_path " , PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE ) , " set_base_path " , " get_base_path " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " property " ) , " set_property " , " get_property " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " index " ) , " set_index " , " get_index " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " assign_op " , PROPERTY_HINT_ENUM , " Assign,Add,Sub,Mul,Div,Mod,ShiftLeft,ShiftRight,BitAnd,BitOr,Bitxor " ) , " set_assign_op " , " get_assign_op " ) ;
2017-08-20 15:45:01 +00:00
BIND_ENUM_CONSTANT ( CALL_MODE_SELF ) ;
BIND_ENUM_CONSTANT ( CALL_MODE_NODE_PATH ) ;
BIND_ENUM_CONSTANT ( CALL_MODE_INSTANCE ) ;
2017-09-12 19:09:06 +00:00
BIND_ENUM_CONSTANT ( CALL_MODE_BASIC_TYPE ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_NONE ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_ADD ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_SUB ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_MUL ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_DIV ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_MOD ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_SHIFT_LEFT ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_SHIFT_RIGHT ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_BIT_AND ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_BIT_OR ) ;
BIND_ENUM_CONSTANT ( ASSIGN_OP_BIT_XOR ) ;
2016-08-02 22:11:05 +00:00
}
2016-08-06 01:46:45 +00:00
class VisualScriptNodeInstancePropertySet : public VisualScriptNodeInstance {
public :
VisualScriptPropertySet : : CallMode call_mode ;
NodePath node_path ;
StringName property ;
VisualScriptPropertySet * node ;
VisualScriptInstance * instance ;
2017-07-01 00:30:17 +00:00
VisualScriptPropertySet : : AssignOp assign_op ;
StringName index ;
bool needs_get ;
2016-08-06 01:46:45 +00:00
//virtual int get_working_memory_size() const { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
2017-07-01 00:30:17 +00:00
_FORCE_INLINE_ void _process_get ( Variant & source , const Variant & p_argument , bool & valid ) {
if ( index ! = StringName ( ) & & assign_op = = VisualScriptPropertySet : : ASSIGN_OP_NONE ) {
2020-11-07 01:29:22 +00:00
source . set_named ( index , p_argument , valid ) ;
2017-07-01 00:30:17 +00:00
} else {
Variant value ;
if ( index ! = StringName ( ) ) {
2020-11-07 01:29:22 +00:00
value = source . get_named ( index , valid ) ;
2017-07-01 00:30:17 +00:00
} else {
value = source ;
}
switch ( assign_op ) {
case VisualScriptPropertySet : : ASSIGN_OP_NONE : {
//should never get here
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_ADD : {
value = Variant : : evaluate ( Variant : : OP_ADD , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_SUB : {
2017-09-17 00:32:05 +00:00
value = Variant : : evaluate ( Variant : : OP_SUBTRACT , value , p_argument ) ;
2017-07-01 00:30:17 +00:00
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_MUL : {
value = Variant : : evaluate ( Variant : : OP_MULTIPLY , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_DIV : {
value = Variant : : evaluate ( Variant : : OP_DIVIDE , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_MOD : {
value = Variant : : evaluate ( Variant : : OP_MODULE , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_SHIFT_LEFT : {
value = Variant : : evaluate ( Variant : : OP_SHIFT_LEFT , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_SHIFT_RIGHT : {
value = Variant : : evaluate ( Variant : : OP_SHIFT_RIGHT , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_BIT_AND : {
value = Variant : : evaluate ( Variant : : OP_BIT_AND , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_BIT_OR : {
value = Variant : : evaluate ( Variant : : OP_BIT_OR , value , p_argument ) ;
} break ;
case VisualScriptPropertySet : : ASSIGN_OP_BIT_XOR : {
value = Variant : : evaluate ( Variant : : OP_BIT_XOR , value , p_argument ) ;
} break ;
2019-04-09 15:08:36 +00:00
default : {
}
2017-07-01 00:30:17 +00:00
}
if ( index ! = StringName ( ) ) {
2020-11-07 01:29:22 +00:00
source . set_named ( index , value , valid ) ;
2017-07-01 00:30:17 +00:00
} else {
source = value ;
}
}
}
2020-02-19 19:27:19 +00:00
virtual int step ( const Variant * * p_inputs , Variant * * p_outputs , StartMode p_start_mode , Variant * p_working_mem , Callable : : CallError & r_error , String & r_error_str ) {
2017-03-05 15:44:50 +00:00
switch ( call_mode ) {
2016-08-06 01:46:45 +00:00
case VisualScriptPropertySet : : CALL_MODE_SELF : {
2017-03-05 15:44:50 +00:00
Object * object = instance - > get_owner_ptr ( ) ;
2016-08-06 01:46:45 +00:00
bool valid ;
2017-07-01 00:30:17 +00:00
if ( needs_get ) {
Variant value = object - > get ( property , & valid ) ;
_process_get ( value , * p_inputs [ 0 ] , valid ) ;
object - > set ( property , value , & valid ) ;
} else {
object - > set ( property , * p_inputs [ 0 ] , & valid ) ;
}
2016-08-06 01:46:45 +00:00
if ( ! valid ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Invalid set value ' " + String ( * p_inputs [ 0 ] ) + " ' on property ' " + String ( property ) + " ' of type " + object - > get_class ( ) ;
2016-08-06 01:46:45 +00:00
}
} break ;
case VisualScriptPropertySet : : CALL_MODE_NODE_PATH : {
2017-08-24 20:58:51 +00:00
Node * node = Object : : cast_to < Node > ( instance - > get_owner_ptr ( ) ) ;
2016-08-06 01:46:45 +00:00
if ( ! node ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Base object is not a Node! " ;
2016-08-06 01:46:45 +00:00
return 0 ;
}
2017-03-05 15:44:50 +00:00
Node * another = node - > get_node ( node_path ) ;
2017-08-25 15:14:33 +00:00
if ( ! another ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Path does not lead Node! " ;
2016-08-06 01:46:45 +00:00
return 0 ;
}
bool valid ;
2017-07-01 00:30:17 +00:00
if ( needs_get ) {
Variant value = another - > get ( property , & valid ) ;
_process_get ( value , * p_inputs [ 0 ] , valid ) ;
another - > set ( property , value , & valid ) ;
} else {
another - > set ( property , * p_inputs [ 0 ] , & valid ) ;
}
2016-08-06 01:46:45 +00:00
if ( ! valid ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Invalid set value ' " + String ( * p_inputs [ 0 ] ) + " ' on property ' " + String ( property ) + " ' of type " + another - > get_class ( ) ;
2016-08-06 01:46:45 +00:00
}
} break ;
case VisualScriptPropertySet : : CALL_MODE_INSTANCE :
case VisualScriptPropertySet : : CALL_MODE_BASIC_TYPE : {
Variant v = * p_inputs [ 0 ] ;
bool valid ;
2017-07-01 00:30:17 +00:00
if ( needs_get ) {
2020-11-07 01:29:22 +00:00
Variant value = v . get_named ( property , valid ) ;
2017-07-01 00:30:17 +00:00
_process_get ( value , * p_inputs [ 1 ] , valid ) ;
2020-11-07 01:29:22 +00:00
v . set_named ( property , value , valid ) ;
2017-07-01 00:30:17 +00:00
} else {
2020-11-07 01:29:22 +00:00
v . set_named ( property , * p_inputs [ 1 ] , valid ) ;
2017-07-01 00:30:17 +00:00
}
2016-08-06 01:46:45 +00:00
if ( ! valid ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = " Invalid set value ' " + String ( * p_inputs [ 1 ] ) + " ' ( " + Variant : : get_type_name ( p_inputs [ 1 ] - > get_type ( ) ) + " ) on property ' " + String ( property ) + " ' of type " + Variant : : get_type_name ( v . get_type ( ) ) ;
2016-08-06 01:46:45 +00:00
}
2017-03-05 15:44:50 +00:00
* p_outputs [ 0 ] = v ;
2016-08-07 22:22:33 +00:00
2016-08-06 01:46:45 +00:00
} break ;
}
return 0 ;
}
} ;
2021-06-17 22:03:09 +00:00
VisualScriptNodeInstance * VisualScriptPropertySet : : instantiate ( VisualScriptInstance * p_instance ) {
2017-03-05 15:44:50 +00:00
VisualScriptNodeInstancePropertySet * instance = memnew ( VisualScriptNodeInstancePropertySet ) ;
instance - > node = this ;
instance - > instance = p_instance ;
instance - > property = property ;
instance - > call_mode = call_mode ;
instance - > node_path = base_path ;
2017-07-01 00:30:17 +00:00
instance - > assign_op = assign_op ;
instance - > index = index ;
instance - > needs_get = index ! = StringName ( ) | | assign_op ! = ASSIGN_OP_NONE ;
2016-08-06 01:46:45 +00:00
return instance ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
VisualScriptPropertySet : : TypeGuess VisualScriptPropertySet : : guess_output_type ( TypeGuess * p_inputs , int p_output ) const {
if ( p_output = = 0 & & call_mode = = CALL_MODE_INSTANCE ) {
2016-09-03 17:58:23 +00:00
return p_inputs [ 0 ] ;
}
2017-03-05 15:44:50 +00:00
return VisualScriptNode : : guess_output_type ( p_inputs , p_output ) ;
2016-09-03 17:58:23 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
VisualScriptPropertySet : : VisualScriptPropertySet ( ) {
2017-07-01 00:30:17 +00:00
assign_op = ASSIGN_OP_NONE ;
2017-03-05 15:44:50 +00:00
call_mode = CALL_MODE_SELF ;
base_type = " Object " ;
basic_type = Variant : : NIL ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
template < VisualScriptPropertySet : : CallMode cmode >
static Ref < VisualScriptNode > create_property_set_node ( const String & p_name ) {
2016-08-02 22:11:05 +00:00
Ref < VisualScriptPropertySet > node ;
2021-06-17 22:03:09 +00:00
node . instantiate ( ) ;
2016-08-02 22:11:05 +00:00
node - > set_call_mode ( cmode ) ;
return node ;
}
//////////////////////////////////////////
2016-08-03 14:28:20 +00:00
////////////////GET//////////////////////
2016-08-02 22:11:05 +00:00
//////////////////////////////////////////
int VisualScriptPropertyGet : : get_output_sequence_port_count ( ) const {
2017-03-05 15:44:50 +00:00
return 0 ; // (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
bool VisualScriptPropertyGet : : has_input_sequence_port ( ) const {
return false ; //(call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-04 01:06:39 +00:00
void VisualScriptPropertyGet : : _update_base_type ( ) {
//cache it because this information may not be available on load
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_NODE_PATH ) {
Node * node = _get_base_node ( ) ;
2016-08-04 01:06:39 +00:00
if ( node ) {
2017-03-05 15:44:50 +00:00
base_type = node - > get_class ( ) ;
2016-08-04 01:06:39 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF ) {
2016-08-04 01:06:39 +00:00
if ( get_visual_script ( ) . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
base_type = get_visual_script ( ) - > get_instance_base_type ( ) ;
2016-08-04 01:06:39 +00:00
}
}
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
Node * VisualScriptPropertyGet : : _get_base_node ( ) const {
# ifdef TOOLS_ENABLED
Ref < Script > script = get_visual_script ( ) ;
2020-05-14 14:41:43 +00:00
if ( ! script . is_valid ( ) ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
MainLoop * main_loop = OS : : get_singleton ( ) - > get_main_loop ( ) ;
2016-08-02 22:11:05 +00:00
2017-08-24 20:58:51 +00:00
SceneTree * scene_tree = Object : : cast_to < SceneTree > ( main_loop ) ;
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! scene_tree ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
Node * edited_scene = scene_tree - > get_edited_scene_root ( ) ;
2020-05-14 14:41:43 +00:00
if ( ! edited_scene ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
Node * script_node = _find_script_node ( edited_scene , edited_scene , script ) ;
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! script_node ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2020-05-14 14:41:43 +00:00
if ( ! script_node - > has_node ( base_path ) ) {
2020-04-01 23:20:12 +00:00
return nullptr ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
Node * path_to = script_node - > get_node ( base_path ) ;
return path_to ;
# else
2020-04-01 23:20:12 +00:00
return nullptr ;
2016-08-02 22:11:05 +00:00
# endif
}
StringName VisualScriptPropertyGet : : _get_base_type ( ) const {
2020-05-14 14:41:43 +00:00
if ( call_mode = = CALL_MODE_SELF & & get_visual_script ( ) . is_valid ( ) ) {
2016-08-02 22:11:05 +00:00
return get_visual_script ( ) - > get_instance_base_type ( ) ;
2020-05-14 14:41:43 +00:00
} else if ( call_mode = = CALL_MODE_NODE_PATH & & get_visual_script ( ) . is_valid ( ) ) {
2016-08-02 22:11:05 +00:00
Node * path = _get_base_node ( ) ;
2020-05-14 14:41:43 +00:00
if ( path ) {
2017-01-03 02:03:46 +00:00
return path - > get_class ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
}
return base_type ;
}
2017-03-05 15:44:50 +00:00
int VisualScriptPropertyGet : : get_input_value_port_count ( ) const {
return ( call_mode = = CALL_MODE_BASIC_TYPE | | call_mode = = CALL_MODE_INSTANCE ) ? 1 : 0 ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2017-03-05 15:44:50 +00:00
int VisualScriptPropertyGet : : get_output_value_port_count ( ) const {
2016-08-02 22:11:05 +00:00
return 1 ;
}
String VisualScriptPropertyGet : : get_output_sequence_port_text ( int p_port ) const {
return String ( ) ;
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptPropertyGet : : get_input_value_port_info ( int p_idx ) const {
if ( call_mode = = CALL_MODE_INSTANCE | | call_mode = = CALL_MODE_BASIC_TYPE ) {
if ( p_idx = = 0 ) {
2016-08-02 22:11:05 +00:00
PropertyInfo pi ;
2017-03-05 15:44:50 +00:00
pi . type = ( call_mode = = CALL_MODE_INSTANCE ? Variant : : OBJECT : basic_type ) ;
pi . name = ( call_mode = = CALL_MODE_INSTANCE ? String ( " instance " ) : Variant : : get_type_name ( basic_type ) . to_lower ( ) ) ;
2016-08-02 22:11:05 +00:00
return pi ;
}
}
return PropertyInfo ( ) ;
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptPropertyGet : : get_output_value_port_info ( int p_idx ) const {
2019-05-25 22:29:21 +00:00
List < PropertyInfo > props ;
2019-10-09 05:47:05 +00:00
ClassDB : : get_property_list ( _get_base_type ( ) , & props , false ) ;
2019-05-25 22:29:21 +00:00
for ( List < PropertyInfo > : : Element * E = props . front ( ) ; E ; E = E - > next ( ) ) {
if ( E - > get ( ) . name = = property ) {
return PropertyInfo ( E - > get ( ) . type , " value. " + String ( index ) ) ;
}
2017-07-01 00:30:17 +00:00
}
2017-03-05 15:44:50 +00:00
return PropertyInfo ( type_cache , " value " ) ;
2016-08-25 20:45:20 +00:00
}
2016-08-02 22:11:05 +00:00
2016-08-25 20:45:20 +00:00
String VisualScriptPropertyGet : : get_caption ( ) const {
2018-04-30 22:39:28 +00:00
return String ( " Get " ) + property ;
2016-08-25 20:45:20 +00:00
}
String VisualScriptPropertyGet : : get_text ( ) const {
2018-04-30 22:39:28 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
return String ( " On " ) + Variant : : get_type_name ( basic_type ) ;
}
2016-08-25 20:45:20 +00:00
2018-04-30 22:39:28 +00:00
static const char * cname [ 3 ] = {
" Self " ,
" Scene Node " ,
" Instance "
} ;
2016-08-25 20:45:20 +00:00
2018-04-30 22:39:28 +00:00
return String ( " On " ) + cname [ call_mode ] ;
2016-08-25 20:45:20 +00:00
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertyGet : : set_base_type ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( base_type = = p_type ) {
2016-08-25 20:45:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
base_type = p_type ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-25 20:45:20 +00:00
ports_changed_notify ( ) ;
}
2017-03-05 15:44:50 +00:00
StringName VisualScriptPropertyGet : : get_base_type ( ) const {
2016-08-25 20:45:20 +00:00
return base_type ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertyGet : : set_base_script ( const String & p_path ) {
2020-05-14 14:41:43 +00:00
if ( base_script = = p_path ) {
2016-08-25 20:45:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
base_script = p_path ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-25 20:45:20 +00:00
ports_changed_notify ( ) ;
}
String VisualScriptPropertyGet : : get_base_script ( ) const {
return base_script ;
}
void VisualScriptPropertyGet : : _update_cache ( ) {
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
2016-08-25 20:45:20 +00:00
//not super efficient..
2016-08-03 14:28:20 +00:00
2016-08-07 22:22:33 +00:00
Variant v ;
2020-02-19 19:27:19 +00:00
Callable : : CallError ce ;
2020-11-09 03:19:09 +00:00
Variant : : construct ( basic_type , v , nullptr , 0 , ce ) ;
2016-08-25 20:45:20 +00:00
List < PropertyInfo > pinfo ;
2016-08-03 14:28:20 +00:00
v . get_property_list ( & pinfo ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
for ( List < PropertyInfo > : : Element * E = pinfo . front ( ) ; E ; E = E - > next ( ) ) {
if ( E - > get ( ) . name = = property ) {
type_cache = E - > get ( ) . type ;
2016-08-25 20:45:20 +00:00
return ;
}
2016-08-02 22:11:05 +00:00
}
2016-08-25 20:45:20 +00:00
2016-08-02 22:11:05 +00:00
} else {
2016-08-25 20:45:20 +00:00
StringName type ;
Ref < Script > script ;
2020-04-01 23:20:12 +00:00
Node * node = nullptr ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_NODE_PATH ) {
node = _get_base_node ( ) ;
2016-08-25 20:45:20 +00:00
if ( node ) {
2017-03-05 15:44:50 +00:00
type = node - > get_class ( ) ;
base_type = type ; //cache, too
2016-08-25 20:45:20 +00:00
script = node - > get_script ( ) ;
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF ) {
2016-08-25 20:45:20 +00:00
if ( get_visual_script ( ) . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
type = get_visual_script ( ) - > get_instance_base_type ( ) ;
base_type = type ; //cache, too
script = get_visual_script ( ) ;
2016-08-25 20:45:20 +00:00
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_INSTANCE ) {
type = base_type ;
if ( base_script ! = String ( ) ) {
2016-08-25 20:45:20 +00:00
if ( ! ResourceCache : : has ( base_script ) & & ScriptServer : : edit_request_func ) {
ScriptServer : : edit_request_func ( base_script ) ; //make sure it's loaded
}
2016-08-02 22:11:05 +00:00
2016-08-25 20:45:20 +00:00
if ( ResourceCache : : has ( base_script ) ) {
2017-03-05 15:44:50 +00:00
script = Ref < Resource > ( ResourceCache : : get ( base_script ) ) ;
2016-08-25 20:45:20 +00:00
} else {
return ;
}
}
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
bool valid = false ;
2016-08-03 14:28:20 +00:00
2016-08-25 20:45:20 +00:00
Variant : : Type type_ret ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
type_ret = ClassDB : : get_property_type ( base_type , property , & valid ) ;
2016-08-02 22:11:05 +00:00
2016-08-25 20:45:20 +00:00
if ( valid ) {
2017-03-05 15:44:50 +00:00
type_cache = type_ret ;
2016-08-25 20:45:20 +00:00
return ; //all dandy
}
2016-08-02 22:11:05 +00:00
2016-08-25 20:45:20 +00:00
if ( node ) {
2017-03-05 15:44:50 +00:00
Variant prop = node - > get ( property , & valid ) ;
2016-08-25 20:45:20 +00:00
if ( valid ) {
2017-03-05 15:44:50 +00:00
type_cache = prop . get_type ( ) ;
2016-08-25 20:45:20 +00:00
return ; //all dandy again
}
}
2016-08-02 22:11:05 +00:00
2016-08-25 20:45:20 +00:00
if ( script . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
type_ret = script - > get_static_property_type ( property , & valid ) ;
2016-08-25 20:45:20 +00:00
if ( valid ) {
2017-03-05 15:44:50 +00:00
type_cache = type_ret ;
2016-08-25 20:45:20 +00:00
return ; //all dandy
}
}
}
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertyGet : : set_property ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( property = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
property = p_type ;
2016-08-25 20:45:20 +00:00
_update_cache ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
StringName VisualScriptPropertyGet : : get_property ( ) const {
return property ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertyGet : : set_base_path ( const NodePath & p_type ) {
2020-05-14 14:41:43 +00:00
if ( base_path = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
base_path = p_type ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
_update_base_type ( ) ;
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
NodePath VisualScriptPropertyGet : : get_base_path ( ) const {
return base_path ;
}
void VisualScriptPropertyGet : : set_call_mode ( CallMode p_mode ) {
2020-05-14 14:41:43 +00:00
if ( call_mode = = p_mode ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
call_mode = p_mode ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
_update_base_type ( ) ;
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
VisualScriptPropertyGet : : CallMode VisualScriptPropertyGet : : get_call_mode ( ) const {
return call_mode ;
}
2016-08-03 14:28:20 +00:00
void VisualScriptPropertyGet : : set_basic_type ( Variant : : Type p_type ) {
2020-05-14 14:41:43 +00:00
if ( basic_type = = p_type ) {
2016-08-03 14:28:20 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
basic_type = p_type ;
2016-08-03 14:28:20 +00:00
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-03 14:28:20 +00:00
}
2017-03-05 15:44:50 +00:00
Variant : : Type VisualScriptPropertyGet : : get_basic_type ( ) const {
2016-08-03 14:28:20 +00:00
return basic_type ;
}
2016-08-25 20:45:20 +00:00
void VisualScriptPropertyGet : : _set_type_cache ( Variant : : Type p_type ) {
2017-03-05 15:44:50 +00:00
type_cache = p_type ;
2016-08-25 20:45:20 +00:00
}
Variant : : Type VisualScriptPropertyGet : : _get_type_cache ( ) const {
return type_cache ;
}
2017-07-01 00:30:17 +00:00
void VisualScriptPropertyGet : : set_index ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( index = = p_type ) {
2017-07-01 00:30:17 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2017-07-01 00:30:17 +00:00
index = p_type ;
_update_cache ( ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2017-07-01 00:30:17 +00:00
ports_changed_notify ( ) ;
}
StringName VisualScriptPropertyGet : : get_index ( ) const {
return index ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptPropertyGet : : _validate_property ( PropertyInfo & property ) const {
2017-07-01 00:30:17 +00:00
if ( property . name = = " base_type " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_INSTANCE ) {
2018-01-11 22:35:12 +00:00
property . usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ;
2016-08-02 22:11:05 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " base_script " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_INSTANCE ) {
property . usage = 0 ;
2016-08-25 20:45:20 +00:00
}
}
2016-08-02 22:11:05 +00:00
2017-07-01 00:30:17 +00:00
if ( property . name = = " basic_type " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_BASIC_TYPE ) {
property . usage = 0 ;
2016-08-03 14:28:20 +00:00
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " node_path " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode ! = CALL_MODE_NODE_PATH ) {
property . usage = 0 ;
2016-08-02 22:11:05 +00:00
} else {
Node * bnode = _get_base_node ( ) ;
if ( bnode ) {
2021-03-12 13:35:16 +00:00
property . hint_string = bnode - > get_path ( ) ; //convert to long string
2016-08-02 22:11:05 +00:00
}
}
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " property " ) {
2017-03-05 15:44:50 +00:00
if ( call_mode = = CALL_MODE_BASIC_TYPE ) {
property . hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE ;
property . hint_string = Variant : : get_type_name ( basic_type ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_SELF & & get_visual_script ( ) . is_valid ( ) ) {
property . hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( get_visual_script ( ) - > get_instance_id ( ) ) ;
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_INSTANCE ) {
property . hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE ;
property . hint_string = base_type ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
if ( base_script ! = String ( ) ) {
2016-08-25 20:45:20 +00:00
if ( ! ResourceCache : : has ( base_script ) & & ScriptServer : : edit_request_func ) {
ScriptServer : : edit_request_func ( base_script ) ; //make sure it's loaded
}
if ( ResourceCache : : has ( base_script ) ) {
2017-03-05 15:44:50 +00:00
Ref < Script > script = Ref < Resource > ( ResourceCache : : get ( base_script ) ) ;
2016-08-25 20:45:20 +00:00
if ( script . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( script - > get_instance_id ( ) ) ;
2016-08-25 20:45:20 +00:00
}
}
}
2017-03-05 15:44:50 +00:00
} else if ( call_mode = = CALL_MODE_NODE_PATH ) {
2016-08-23 22:29:07 +00:00
Node * node = _get_base_node ( ) ;
if ( node ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE ;
2017-08-07 10:17:31 +00:00
property . hint_string = itos ( node - > get_instance_id ( ) ) ;
2016-08-02 22:11:05 +00:00
} else {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE ;
property . hint_string = get_base_type ( ) ;
2016-08-02 22:11:05 +00:00
}
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
}
2017-07-01 00:30:17 +00:00
if ( property . name = = " index " ) {
2020-02-19 19:27:19 +00:00
Callable : : CallError ce ;
2020-11-09 03:19:09 +00:00
Variant v ;
Variant : : construct ( type_cache , v , nullptr , 0 , ce ) ;
2017-07-01 00:30:17 +00:00
List < PropertyInfo > plist ;
v . get_property_list ( & plist ) ;
String options = " " ;
for ( List < PropertyInfo > : : Element * E = plist . front ( ) ; E ; E = E - > next ( ) ) {
options + = " , " + E - > get ( ) . name ;
}
property . hint = PROPERTY_HINT_ENUM ;
property . hint_string = options ;
property . type = Variant : : STRING ;
2020-05-14 14:41:43 +00:00
if ( options = = " " ) {
2017-07-01 00:30:17 +00:00
property . usage = 0 ; //hide if type has no usable index
2020-05-14 14:41:43 +00:00
}
2017-07-01 00:30:17 +00:00
}
2016-08-02 22:11:05 +00:00
}
void VisualScriptPropertyGet : : _bind_methods ( ) {
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_type " , " base_type " ) , & VisualScriptPropertyGet : : set_base_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_type " ) , & VisualScriptPropertyGet : : get_base_type ) ;
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_script " , " base_script " ) , & VisualScriptPropertyGet : : set_base_script ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_script " ) , & VisualScriptPropertyGet : : get_base_script ) ;
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_basic_type " , " basic_type " ) , & VisualScriptPropertyGet : : set_basic_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_basic_type " ) , & VisualScriptPropertyGet : : get_basic_type ) ;
2016-08-25 20:45:20 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " _set_type_cache " , " type_cache " ) , & VisualScriptPropertyGet : : _set_type_cache ) ;
ClassDB : : bind_method ( D_METHOD ( " _get_type_cache " ) , & VisualScriptPropertyGet : : _get_type_cache ) ;
2016-08-07 22:22:33 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_property " , " property " ) , & VisualScriptPropertyGet : : set_property ) ;
ClassDB : : bind_method ( D_METHOD ( " get_property " ) , & VisualScriptPropertyGet : : get_property ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_call_mode " , " mode " ) , & VisualScriptPropertyGet : : set_call_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_call_mode " ) , & VisualScriptPropertyGet : : get_call_mode ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_base_path " , " base_path " ) , & VisualScriptPropertyGet : : set_base_path ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base_path " ) , & VisualScriptPropertyGet : : get_base_path ) ;
2016-08-02 22:11:05 +00:00
2017-07-01 00:30:17 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_index " , " index " ) , & VisualScriptPropertyGet : : set_index ) ;
ClassDB : : bind_method ( D_METHOD ( " get_index " ) , & VisualScriptPropertyGet : : get_index ) ;
2016-08-03 14:28:20 +00:00
String bt ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < Variant : : VARIANT_MAX ; i + + ) {
2020-05-14 14:41:43 +00:00
if ( i > 0 ) {
2017-03-05 15:44:50 +00:00
bt + = " , " ;
2020-05-14 14:41:43 +00:00
}
2016-08-03 14:28:20 +00:00
2017-03-05 15:44:50 +00:00
bt + = Variant : : get_type_name ( Variant : : Type ( i ) ) ;
2016-08-03 14:28:20 +00:00
}
2016-08-02 22:11:05 +00:00
2016-08-25 20:45:20 +00:00
List < String > script_extensions ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < ScriptServer : : get_language_count ( ) ; i + + ) {
2016-08-25 20:45:20 +00:00
ScriptServer : : get_language ( i ) - > get_recognized_extensions ( & script_extensions ) ;
}
String script_ext_hint ;
2017-03-05 15:44:50 +00:00
for ( List < String > : : Element * E = script_extensions . front ( ) ; E ; E = E - > next ( ) ) {
2020-05-14 14:41:43 +00:00
if ( script_ext_hint ! = String ( ) ) {
2017-03-05 15:44:50 +00:00
script_ext_hint + = " , " ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
script_ext_hint + = " . " + E - > get ( ) ;
2016-08-25 20:45:20 +00:00
}
2016-08-02 22:11:05 +00:00
2017-07-01 00:30:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " set_mode " , PROPERTY_HINT_ENUM , " Self,Node Path,Instance,Basic Type " ) , " set_call_mode " , " get_call_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " base_type " , PROPERTY_HINT_TYPE_STRING , " Object " ) , " set_base_type " , " get_base_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " base_script " , PROPERTY_HINT_FILE , script_ext_hint ) , " set_base_script " , " get_base_script " ) ;
2018-01-11 22:35:12 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " type_cache " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ) , " _set_type_cache " , " _get_type_cache " ) ;
2017-07-01 00:30:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " basic_type " , PROPERTY_HINT_ENUM , bt ) , " set_basic_type " , " get_basic_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : NODE_PATH , " node_path " , PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE ) , " set_base_path " , " get_base_path " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " property " ) , " set_property " , " get_property " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " index " , PROPERTY_HINT_ENUM ) , " set_index " , " get_index " ) ;
2016-08-02 22:11:05 +00:00
2017-08-20 15:45:01 +00:00
BIND_ENUM_CONSTANT ( CALL_MODE_SELF ) ;
BIND_ENUM_CONSTANT ( CALL_MODE_NODE_PATH ) ;
BIND_ENUM_CONSTANT ( CALL_MODE_INSTANCE ) ;
2020-10-12 17:39:15 +00:00
BIND_ENUM_CONSTANT ( CALL_MODE_BASIC_TYPE ) ;
2016-08-02 22:11:05 +00:00
}
2016-08-06 01:46:45 +00:00
class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance {
public :
VisualScriptPropertyGet : : CallMode call_mode ;
NodePath node_path ;
StringName property ;
2017-07-01 00:30:17 +00:00
StringName index ;
2016-08-06 01:46:45 +00:00
VisualScriptPropertyGet * node ;
VisualScriptInstance * instance ;
2020-02-19 19:27:19 +00:00
virtual int step ( const Variant * * p_inputs , Variant * * p_outputs , StartMode p_start_mode , Variant * p_working_mem , Callable : : CallError & r_error , String & r_error_str ) {
2017-03-05 15:44:50 +00:00
switch ( call_mode ) {
2016-08-06 01:46:45 +00:00
case VisualScriptPropertyGet : : CALL_MODE_SELF : {
2017-03-05 15:44:50 +00:00
Object * object = instance - > get_owner_ptr ( ) ;
2016-08-06 01:46:45 +00:00
bool valid ;
2017-03-05 15:44:50 +00:00
* p_outputs [ 0 ] = object - > get ( property , & valid ) ;
2016-08-06 01:46:45 +00:00
2017-07-01 00:30:17 +00:00
if ( index ! = StringName ( ) ) {
2020-11-07 01:29:22 +00:00
* p_outputs [ 0 ] = p_outputs [ 0 ] - > get_named ( index , valid ) ;
2017-07-01 00:30:17 +00:00
}
2016-08-06 01:46:45 +00:00
if ( ! valid ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = RTR ( " Invalid index property name. " ) ;
2016-08-31 02:44:14 +00:00
return 0 ;
2016-08-06 01:46:45 +00:00
}
} break ;
case VisualScriptPropertyGet : : CALL_MODE_NODE_PATH : {
2017-08-24 20:58:51 +00:00
Node * node = Object : : cast_to < Node > ( instance - > get_owner_ptr ( ) ) ;
2016-08-06 01:46:45 +00:00
if ( ! node ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = RTR ( " Base object is not a Node! " ) ;
2016-08-31 02:44:14 +00:00
return 0 ;
2016-08-06 01:46:45 +00:00
}
2017-03-05 15:44:50 +00:00
Node * another = node - > get_node ( node_path ) ;
2017-08-25 15:14:33 +00:00
if ( ! another ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = RTR ( " Path does not lead Node! " ) ;
2016-08-31 02:44:14 +00:00
return 0 ;
2016-08-06 01:46:45 +00:00
}
bool valid ;
2017-03-05 15:44:50 +00:00
* p_outputs [ 0 ] = another - > get ( property , & valid ) ;
2016-08-06 01:46:45 +00:00
2017-07-01 00:30:17 +00:00
if ( index ! = StringName ( ) ) {
2020-11-07 01:29:22 +00:00
* p_outputs [ 0 ] = p_outputs [ 0 ] - > get_named ( index , valid ) ;
2017-07-01 00:30:17 +00:00
}
2016-08-06 01:46:45 +00:00
if ( ! valid ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = vformat ( RTR ( " Invalid index property name '%s' in node %s. " ) , String ( property ) , another - > get_name ( ) ) ;
2016-08-31 02:44:14 +00:00
return 0 ;
2016-08-06 01:46:45 +00:00
}
} break ;
2016-08-31 02:44:14 +00:00
default : {
bool valid ;
Variant v = * p_inputs [ 0 ] ;
2016-08-06 01:46:45 +00:00
2017-03-05 15:44:50 +00:00
* p_outputs [ 0 ] = v . get ( property , & valid ) ;
2017-07-01 00:30:17 +00:00
if ( index ! = StringName ( ) ) {
2020-11-07 01:29:22 +00:00
* p_outputs [ 0 ] = p_outputs [ 0 ] - > get_named ( index , valid ) ;
2017-07-01 00:30:17 +00:00
}
2016-08-06 01:46:45 +00:00
2016-08-31 02:44:14 +00:00
if ( ! valid ) {
2020-02-19 19:27:19 +00:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_METHOD ;
2017-03-05 15:44:50 +00:00
r_error_str = RTR ( " Invalid index property name. " ) ;
2016-08-31 02:44:14 +00:00
}
} ;
2016-08-06 01:46:45 +00:00
}
return 0 ;
}
} ;
2021-06-17 22:03:09 +00:00
VisualScriptNodeInstance * VisualScriptPropertyGet : : instantiate ( VisualScriptInstance * p_instance ) {
2017-03-05 15:44:50 +00:00
VisualScriptNodeInstancePropertyGet * instance = memnew ( VisualScriptNodeInstancePropertyGet ) ;
instance - > node = this ;
instance - > instance = p_instance ;
instance - > property = property ;
instance - > call_mode = call_mode ;
instance - > node_path = base_path ;
2017-07-01 00:30:17 +00:00
instance - > index = index ;
2016-08-06 01:46:45 +00:00
return instance ;
2016-08-02 22:11:05 +00:00
}
VisualScriptPropertyGet : : VisualScriptPropertyGet ( ) {
2017-03-05 15:44:50 +00:00
call_mode = CALL_MODE_SELF ;
base_type = " Object " ;
basic_type = Variant : : NIL ;
type_cache = Variant : : NIL ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
template < VisualScriptPropertyGet : : CallMode cmode >
static Ref < VisualScriptNode > create_property_get_node ( const String & p_name ) {
2016-08-02 22:11:05 +00:00
Ref < VisualScriptPropertyGet > node ;
2021-06-17 22:03:09 +00:00
node . instantiate ( ) ;
2016-08-02 22:11:05 +00:00
node - > set_call_mode ( cmode ) ;
return node ;
}
//////////////////////////////////////////
2016-08-06 01:46:45 +00:00
////////////////EMIT//////////////////////
2016-08-02 22:11:05 +00:00
//////////////////////////////////////////
int VisualScriptEmitSignal : : get_output_sequence_port_count ( ) const {
return 1 ;
}
2017-03-05 15:44:50 +00:00
bool VisualScriptEmitSignal : : has_input_sequence_port ( ) const {
2016-08-02 22:11:05 +00:00
return true ;
}
2017-03-05 15:44:50 +00:00
int VisualScriptEmitSignal : : get_input_value_port_count ( ) const {
2016-08-02 22:11:05 +00:00
Ref < VisualScript > vs = get_visual_script ( ) ;
if ( vs . is_valid ( ) ) {
2020-05-14 14:41:43 +00:00
if ( ! vs - > has_custom_signal ( name ) ) {
2016-08-02 22:11:05 +00:00
return 0 ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
return vs - > custom_signal_get_argument_count ( name ) ;
}
return 0 ;
}
2020-05-14 12:29:06 +00:00
2017-03-05 15:44:50 +00:00
int VisualScriptEmitSignal : : get_output_value_port_count ( ) const {
2016-08-02 22:11:05 +00:00
return 0 ;
}
String VisualScriptEmitSignal : : get_output_sequence_port_text ( int p_port ) const {
return String ( ) ;
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptEmitSignal : : get_input_value_port_info ( int p_idx ) const {
2016-08-02 22:11:05 +00:00
Ref < VisualScript > vs = get_visual_script ( ) ;
if ( vs . is_valid ( ) ) {
2020-05-14 14:41:43 +00:00
if ( ! vs - > has_custom_signal ( name ) ) {
2016-08-02 22:11:05 +00:00
return PropertyInfo ( ) ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
return PropertyInfo ( vs - > custom_signal_get_argument_type ( name , p_idx ) , vs - > custom_signal_get_argument_name ( name , p_idx ) ) ;
2016-08-02 22:11:05 +00:00
}
return PropertyInfo ( ) ;
}
2017-03-05 15:44:50 +00:00
PropertyInfo VisualScriptEmitSignal : : get_output_value_port_info ( int p_idx ) const {
2016-08-02 22:11:05 +00:00
return PropertyInfo ( ) ;
}
2018-04-29 23:28:31 +00:00
String VisualScriptEmitSignal : : get_caption ( ) const {
2018-04-30 22:39:28 +00:00
return " Emit " + String ( name ) ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
void VisualScriptEmitSignal : : set_signal ( const StringName & p_type ) {
2020-05-14 14:41:43 +00:00
if ( name = = p_type ) {
2016-08-02 22:11:05 +00:00
return ;
2020-05-14 14:41:43 +00:00
}
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
name = p_type ;
2016-08-02 22:11:05 +00:00
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2016-08-04 01:06:39 +00:00
ports_changed_notify ( ) ;
2016-08-02 22:11:05 +00:00
}
2020-05-14 12:29:06 +00:00
2016-08-02 22:11:05 +00:00
StringName VisualScriptEmitSignal : : get_signal ( ) const {
return name ;
}
2017-03-05 15:44:50 +00:00
void VisualScriptEmitSignal : : _validate_property ( PropertyInfo & property ) const {
2017-07-01 00:30:17 +00:00
if ( property . name = = " signal " ) {
2017-03-05 15:44:50 +00:00
property . hint = PROPERTY_HINT_ENUM ;
2016-08-02 22:11:05 +00:00
List < StringName > sigs ;
Ref < VisualScript > vs = get_visual_script ( ) ;
if ( vs . is_valid ( ) ) {
vs - > get_custom_signal_list ( & sigs ) ;
}
String ml ;
2017-03-05 15:44:50 +00:00
for ( List < StringName > : : Element * E = sigs . front ( ) ; E ; E = E - > next ( ) ) {
2020-05-14 14:41:43 +00:00
if ( ml ! = String ( ) ) {
2017-03-05 15:44:50 +00:00
ml + = " , " ;
2020-05-14 14:41:43 +00:00
}
2017-03-05 15:44:50 +00:00
ml + = E - > get ( ) ;
2016-08-02 22:11:05 +00:00
}
2017-03-05 15:44:50 +00:00
property . hint_string = ml ;
2016-08-02 22:11:05 +00:00
}
}
void VisualScriptEmitSignal : : _bind_methods ( ) {
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_signal " , " name " ) , & VisualScriptEmitSignal : : set_signal ) ;
ClassDB : : bind_method ( D_METHOD ( " get_signal " ) , & VisualScriptEmitSignal : : get_signal ) ;
2016-08-02 22:11:05 +00:00
2017-07-01 00:30:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " signal " ) , " set_signal " , " get_signal " ) ;
2016-08-02 22:11:05 +00:00
}
2016-08-06 01:46:45 +00:00
class VisualScriptNodeInstanceEmitSignal : public VisualScriptNodeInstance {
public :
VisualScriptEmitSignal * node ;
VisualScriptInstance * instance ;
int argcount ;
StringName name ;
//virtual int get_working_memory_size() const { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
2020-02-19 19:27:19 +00:00
virtual int step ( const Variant * * p_inputs , Variant * * p_outputs , StartMode p_start_mode , Variant * p_working_mem , Callable : : CallError & r_error , String & r_error_str ) {
2016-08-06 01:46:45 +00:00
Object * obj = instance - > get_owner_ptr ( ) ;
2017-03-05 15:44:50 +00:00
obj - > emit_signal ( name , p_inputs , argcount ) ;
2016-08-06 01:46:45 +00:00
return 0 ;
}
} ;
2021-06-17 22:03:09 +00:00
VisualScriptNodeInstance * VisualScriptEmitSignal : : instantiate ( VisualScriptInstance * p_instance ) {
2017-03-05 15:44:50 +00:00
VisualScriptNodeInstanceEmitSignal * instance = memnew ( VisualScriptNodeInstanceEmitSignal ) ;
instance - > node = this ;
instance - > instance = p_instance ;
instance - > name = name ;
instance - > argcount = get_input_value_port_count ( ) ;
2016-08-06 01:46:45 +00:00
return instance ;
2016-08-02 22:11:05 +00:00
}
VisualScriptEmitSignal : : VisualScriptEmitSignal ( ) {
}
2017-03-05 15:44:50 +00:00
static Ref < VisualScriptNode > create_basic_type_call_node ( const String & p_name ) {
2016-08-06 01:46:45 +00:00
Vector < String > path = p_name . split ( " / " ) ;
2017-03-05 15:44:50 +00:00
ERR_FAIL_COND_V ( path . size ( ) < 4 , Ref < VisualScriptNode > ( ) ) ;
2016-08-06 01:46:45 +00:00
String base_type = path [ 2 ] ;
String method = path [ 3 ] ;
Ref < VisualScriptFunctionCall > node ;
2021-06-17 22:03:09 +00:00
node . instantiate ( ) ;
2016-08-06 01:46:45 +00:00
2017-03-05 15:44:50 +00:00
Variant : : Type type = Variant : : VARIANT_MAX ;
2016-08-06 01:46:45 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < Variant : : VARIANT_MAX ; i + + ) {
if ( Variant : : get_type_name ( Variant : : Type ( i ) ) = = base_type ) {
type = Variant : : Type ( i ) ;
2016-08-06 01:46:45 +00:00
break ;
}
}
2017-03-05 15:44:50 +00:00
ERR_FAIL_COND_V ( type = = Variant : : VARIANT_MAX , Ref < VisualScriptNode > ( ) ) ;
2016-08-06 01:46:45 +00:00
node - > set_call_mode ( VisualScriptFunctionCall : : CALL_MODE_BASIC_TYPE ) ;
node - > set_basic_type ( type ) ;
node - > set_function ( method ) ;
return node ;
}
2016-08-02 22:11:05 +00:00
void register_visual_script_func_nodes ( ) {
2017-03-05 15:44:50 +00:00
VisualScriptLanguage : : singleton - > add_register_func ( " functions/call " , create_node_generic < VisualScriptFunctionCall > ) ;
VisualScriptLanguage : : singleton - > add_register_func ( " functions/set " , create_node_generic < VisualScriptPropertySet > ) ;
VisualScriptLanguage : : singleton - > add_register_func ( " functions/get " , create_node_generic < VisualScriptPropertyGet > ) ;
2016-08-02 22:11:05 +00:00
2016-08-23 22:29:07 +00:00
//VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>);
2017-01-14 11:26:56 +00:00
//VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>);
2017-03-05 15:44:50 +00:00
VisualScriptLanguage : : singleton - > add_register_func ( " functions/emit_signal " , create_node_generic < VisualScriptEmitSignal > ) ;
2016-08-02 22:11:05 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < Variant : : VARIANT_MAX ; i + + ) {
2016-08-06 01:46:45 +00:00
Variant : : Type t = Variant : : Type ( i ) ;
String type_name = Variant : : get_type_name ( t ) ;
2020-02-19 19:27:19 +00:00
Callable : : CallError ce ;
2020-11-09 03:19:09 +00:00
Variant vt ;
Variant : : construct ( t , vt , nullptr , 0 , ce ) ;
2016-08-06 01:46:45 +00:00
List < MethodInfo > ml ;
vt . get_method_list ( & ml ) ;
2017-03-05 15:44:50 +00:00
for ( List < MethodInfo > : : Element * E = ml . front ( ) ; E ; E = E - > next ( ) ) {
VisualScriptLanguage : : singleton - > add_register_func ( " functions/by_type/ " + type_name + " / " + E - > get ( ) . name , create_basic_type_call_node ) ;
2016-08-06 01:46:45 +00:00
}
}
2016-08-02 22:11:05 +00:00
}