diff options
Diffstat (limited to 'modules/visual_script/visual_script_func_nodes.cpp')
-rw-r--r-- | modules/visual_script/visual_script_func_nodes.cpp | 1438 |
1 files changed, 670 insertions, 768 deletions
diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 4006dab4a5..7cd91c7d50 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -3,6 +3,7 @@ #include "os/os.h" #include "scene/main/node.h" #include "visual_script_nodes.h" +#include "io/resource_loader.h" ////////////////////////////////////////// ////////////////CALL////////////////////// @@ -91,20 +92,23 @@ StringName VisualScriptFunctionCall::_get_base_type() const { return base_type; } + int VisualScriptFunctionCall::get_input_value_port_count() const{ if (call_mode==CALL_MODE_BASIC_TYPE) { Vector<StringName> names = Variant::get_method_argument_names(basic_type,function); - return names.size()+1; + return names.size() + (rpc_call_mode>=RPC_RELIABLE_TO_ID?1:0) + 1; } else { + MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return 0; + if (mb) { + return mb->get_argument_count() + (call_mode==CALL_MODE_INSTANCE?1:0) + (rpc_call_mode>=RPC_RELIABLE_TO_ID?1:0) - use_default_args; + } - return mb->get_argument_count() + (call_mode==CALL_MODE_INSTANCE?1:0) - use_default_args; + return method_cache.arguments.size() + (call_mode==CALL_MODE_INSTANCE?1:0) + (rpc_call_mode>=RPC_RELIABLE_TO_ID?1:0) - use_default_args; } } @@ -118,10 +122,11 @@ int VisualScriptFunctionCall::get_output_value_port_count() const{ } else { MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return 0; + if (mb) { + return mb->has_return() ? 1 : 0; + } - return mb->has_return() ? 1 : 0; + return 1; //it is assumed that script always returns something } } @@ -143,6 +148,16 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons } } + if (rpc_call_mode>=RPC_RELIABLE_TO_ID) { + + if (p_idx==0) { + return PropertyInfo(Variant::INT,"peer_id"); + } else { + p_idx--; + } + + } + #ifdef DEBUG_METHODS_ENABLED if (call_mode==CALL_MODE_BASIC_TYPE) { @@ -155,10 +170,15 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons } else { MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return PropertyInfo(); + if (mb) { + return mb->get_argument_info(p_idx); + } + + if (p_idx>=0 && p_idx < method_cache.arguments.size()) { + return method_cache.arguments[p_idx]; + } - return mb->get_argument_info(p_idx); + return PropertyInfo(); } #else return PropertyInfo(); @@ -178,12 +198,14 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con } else { MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return PropertyInfo(); + if (mb) { - PropertyInfo pi = mb->get_argument_info(-1); - pi.name=""; - return pi; + PropertyInfo pi = mb->get_argument_info(-1); + pi.name=""; + return pi; + } + + return method_cache.return_val; } #else return PropertyInfo(); @@ -200,7 +222,13 @@ String VisualScriptFunctionCall::get_caption() const { "CallBasic" }; - return cname[call_mode]; + String caption = cname[call_mode]; + + if (rpc_call_mode) { + caption+=" (RPC)"; + } + + return caption; } String VisualScriptFunctionCall::get_text() const { @@ -214,38 +242,6 @@ String VisualScriptFunctionCall::get_text() const { } -void VisualScriptFunctionCall::_update_defargs() { - - //save base type if accessible - - if (call_mode==CALL_MODE_NODE_PATH) { - - Node* node=_get_base_node(); - if (node) { - base_type=node->get_type(); - } - } else if (call_mode==CALL_MODE_SELF) { - - if (get_visual_script().is_valid()) { - base_type=get_visual_script()->get_instance_base_type(); - } - } - - - if (call_mode==CALL_MODE_BASIC_TYPE) { - use_default_args = Variant::get_method_default_arguments(basic_type,function).size(); - } else { - if (!get_visual_script().is_valid()) - return; //do not change if not valid yet - - MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function); - if (!mb) - return; - - use_default_args=mb->get_default_argument_count(); - } - -} void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { @@ -253,7 +249,7 @@ void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { return; basic_type=p_type; - _update_defargs(); + _change_notify(); ports_changed_notify(); } @@ -269,7 +265,6 @@ void VisualScriptFunctionCall::set_base_type(const StringName& p_type) { return; base_type=p_type; - _update_defargs(); _change_notify(); ports_changed_notify(); } @@ -279,13 +274,102 @@ StringName VisualScriptFunctionCall::get_base_type() const{ return base_type; } +void VisualScriptFunctionCall::set_base_script(const String& p_path) { + + if (base_script==p_path) + return; + + base_script=p_path; + _change_notify(); + ports_changed_notify(); +} + +String VisualScriptFunctionCall::get_base_script() const { + + return base_script; +} + + +void VisualScriptFunctionCall::_update_method_cache() { + StringName type; + Ref<Script> script; + + if (call_mode==CALL_MODE_NODE_PATH) { + + Node* node=_get_base_node(); + if (node) { + type=node->get_type(); + base_type=type; //cache, too + script = node->get_script(); + } + } else if (call_mode==CALL_MODE_SELF) { + + if (get_visual_script().is_valid()) { + type=get_visual_script()->get_instance_base_type(); + base_type=type; //cache, too + script=get_visual_script(); + } + } else if (call_mode==CALL_MODE_INSTANCE) { + + type=base_type; + if (base_script!=String()) { + + 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)) { + + script = Ref<Resource>( ResourceCache::get(base_script) ); + } else { + return; + } + } + } + + +// print_line("BASE: "+String(type)+" FUNC: "+String(function)); + MethodBind *mb = ObjectTypeDB::get_method(type,function); + if (mb) { + use_default_args=mb->get_default_argument_count(); + method_cache = MethodInfo(); + for(int i=0;i<mb->get_argument_count();i++) { +#ifdef DEBUG_METHODS_ENABLED + method_cache.arguments.push_back(mb->get_argument_info(i)); +#else + method_cache.arguments.push_back(PropertyInfo()); +#endif + } + +#ifdef DEBUG_METHODS_ENABLED + + method_cache.return_val = mb->get_argument_info(-1); +#endif + } else if (script.is_valid() && script->has_method(function)) { + + method_cache = script->get_method_info(function); + use_default_args=method_cache.default_arguments.size(); + } +} + void VisualScriptFunctionCall::set_function(const StringName& p_type){ if (function==p_type) return; function=p_type; - _update_defargs(); + + if (call_mode==CALL_MODE_BASIC_TYPE) { + use_default_args = Variant::get_method_default_arguments(basic_type,function).size(); + } else { + //update all caches + + _update_method_cache(); + + } + + _change_notify(); ports_changed_notify(); } @@ -301,7 +385,6 @@ void VisualScriptFunctionCall::set_base_path(const NodePath& p_type) { return; base_path=p_type; - _update_defargs(); _change_notify(); ports_changed_notify(); } @@ -318,7 +401,6 @@ void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) { return; call_mode=p_mode; - _update_defargs(); _change_notify(); ports_changed_notify(); @@ -339,10 +421,40 @@ void VisualScriptFunctionCall::set_use_default_args(int p_amount) { } +void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCallMode p_mode) { + + if (rpc_call_mode==p_mode) + return; + rpc_call_mode=p_mode; + ports_changed_notify(); + _change_notify(); +} + +VisualScriptFunctionCall::RPCCallMode VisualScriptFunctionCall::get_rpc_call_mode() const{ + + return rpc_call_mode; +} + + int VisualScriptFunctionCall::get_use_default_args() const{ return use_default_args; } + + + + +void VisualScriptFunctionCall::_set_argument_cache(const Dictionary& p_cache) { + //so everything works in case all else fails + method_cache=MethodInfo::from_dict(p_cache); + +} + +Dictionary VisualScriptFunctionCall::_get_argument_cache() const { + + return method_cache; +} + void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const { if (property.name=="function/base_type") { @@ -351,6 +463,12 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const } } + if (property.name=="function/base_script") { + if (call_mode!=CALL_MODE_INSTANCE) { + property.usage=0; + } + } + if (property.name=="function/basic_type") { if (call_mode!=CALL_MODE_BASIC_TYPE) { property.usage=0; @@ -372,48 +490,48 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const } if (property.name=="function/function") { - property.hint=PROPERTY_HINT_ENUM; - - - List<MethodInfo> methods; if (call_mode==CALL_MODE_BASIC_TYPE) { - if (basic_type==Variant::NIL) { - property.usage=0; - return; //nothing for nil - } - Variant::CallError ce; - Variant v = Variant::construct(basic_type,NULL,0,ce); - v.get_method_list(&methods); - + property.hint=PROPERTY_HINT_METHOD_OF_VARIANT_TYPE; + property.hint_string=Variant::get_type_name(basic_type); - } else { + } else if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid()) { + property.hint=PROPERTY_HINT_METHOD_OF_SCRIPT; + property.hint_string=itos(get_visual_script()->get_instance_ID()); + } else if (call_mode==CALL_MODE_INSTANCE) { + property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE; + property.hint_string=base_type; - StringName base = _get_base_type(); - ObjectTypeDB::get_method_list(base,&methods); + if (base_script!=String()) { + 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)) { - List<String> mstring; - for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) { - if (E->get().name.begins_with("_")) - continue; - mstring.push_back(E->get().name.get_slice(":",0)); - } + Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) ); + if (script.is_valid()) { - mstring.sort(); + property.hint=PROPERTY_HINT_METHOD_OF_SCRIPT; + property.hint_string=itos(script->get_instance_ID()); + } + } + } - String ml; - for (List<String>::Element *E=mstring.front();E;E=E->next()) { + } else if (call_mode==CALL_MODE_NODE_PATH) { + Node *node = _get_base_node(); + if (node) { + property.hint=PROPERTY_HINT_METHOD_OF_INSTANCE; + property.hint_string=itos(node->get_instance_ID()); + } else { + property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE; + property.hint_string=get_base_type(); + } - if (ml!=String()) - ml+=","; - ml+=E->get(); } - property.hint_string=ml; } if (property.name=="function/use_default_args") { @@ -440,6 +558,13 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const property.hint_string="0,"+itos(mc)+",1"; } } + + if (property.name=="rpc/call_mode") { + if (call_mode==CALL_MODE_BASIC_TYPE) { + property.usage=0; + } + } + } @@ -448,6 +573,9 @@ void VisualScriptFunctionCall::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptFunctionCall::set_base_type); ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptFunctionCall::get_base_type); + ObjectTypeDB::bind_method(_MD("set_base_script","base_script"),&VisualScriptFunctionCall::set_base_script); + ObjectTypeDB::bind_method(_MD("get_base_script"),&VisualScriptFunctionCall::get_base_script); + ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptFunctionCall::set_basic_type); ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptFunctionCall::get_basic_type); @@ -463,6 +591,11 @@ void VisualScriptFunctionCall::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_use_default_args","amount"),&VisualScriptFunctionCall::set_use_default_args); ObjectTypeDB::bind_method(_MD("get_use_default_args"),&VisualScriptFunctionCall::get_use_default_args); + ObjectTypeDB::bind_method(_MD("_set_argument_cache","argument_cache"),&VisualScriptFunctionCall::_set_argument_cache); + ObjectTypeDB::bind_method(_MD("_get_argument_cache"),&VisualScriptFunctionCall::_get_argument_cache); + + ObjectTypeDB::bind_method(_MD("set_rpc_call_mode","mode"),&VisualScriptFunctionCall::set_rpc_call_mode); + ObjectTypeDB::bind_method(_MD("get_rpc_call_mode"),&VisualScriptFunctionCall::get_rpc_call_mode); String bt; for(int i=0;i<Variant::VARIANT_MAX;i++) { @@ -472,12 +605,28 @@ void VisualScriptFunctionCall::_bind_methods() { bt+=Variant::get_type_name(Variant::Type(i)); } - ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type",PROPERTY_USAGE_NOEDITOR),_SCS("set_call_mode"),_SCS("get_call_mode")); + + List<String> script_extensions; + for(int i=0;i<ScriptServer::get_language_count();i++) { + ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions); + } + + String script_ext_hint; + for (List<String>::Element *E=script_extensions.front();E;E=E->next()) { + if (script_ext_hint!=String()) + script_ext_hint+=","; + script_ext_hint+="*."+E->get(); + } + + ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),_SCS("set_call_mode"),_SCS("get_call_mode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/base_script",PROPERTY_HINT_FILE,script_ext_hint),_SCS("set_base_script"),_SCS("get_base_script")); ADD_PROPERTY(PropertyInfo(Variant::INT,"function/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"function/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function")); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"function/argument_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_argument_cache"),_SCS("_get_argument_cache")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function")); //when set, if loaded properly, will override argument count. ADD_PROPERTY(PropertyInfo(Variant::INT,"function/use_default_args"),_SCS("set_use_default_args"),_SCS("get_use_default_args")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"rpc/call_mode",PROPERTY_HINT_ENUM,"Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"),_SCS("set_rpc_call_mode"),_SCS("get_rpc_call_mode")); //when set, if loaded properly, will override argument count. BIND_CONSTANT( CALL_MODE_SELF ); BIND_CONSTANT( CALL_MODE_NODE_PATH); @@ -493,6 +642,7 @@ public: NodePath node_path; int input_args; bool returns; + VisualScriptFunctionCall::RPCCallMode rpc_mode; StringName function; VisualScriptFunctionCall *node; @@ -504,6 +654,35 @@ public: //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; } + + _FORCE_INLINE_ bool call_rpc(Object* p_base,const Variant** p_args,int p_argcount) { + + if (!p_base) + return false; + + Node * node = p_base->cast_to<Node>(); + if (!node) + return false; + + int to_id=0; + bool reliable=true; + + if (rpc_mode>=VisualScriptFunctionCall::RPC_RELIABLE_TO_ID) { + to_id = *p_args[0]; + p_args+=1; + p_argcount-=1; + if (rpc_mode==VisualScriptFunctionCall::RPC_UNRELIABLE_TO_ID) { + reliable=false; + } + } else if (rpc_mode==VisualScriptFunctionCall::RPC_UNRELIABLE) { + reliable=false; + } + + node->rpcp(to_id,!reliable,function,p_args,p_argcount); + + return true; + } + virtual int step(const Variant** p_inputs,Variant** p_outputs,StartMode p_start_mode,Variant* p_working_mem,Variant::CallError& r_error,String& r_error_str) { @@ -513,7 +692,9 @@ public: Object *object=instance->get_owner_ptr(); - if (returns) { + if (rpc_mode) { + call_rpc(object,p_inputs,input_args); + } else if (returns) { *p_outputs[0] = object->call(function,p_inputs,input_args,r_error); } else { object->call(function,p_inputs,input_args,r_error); @@ -535,7 +716,9 @@ public: return 0; } - if (returns) { + if (rpc_mode) { + call_rpc(node,p_inputs,input_args); + } else if (returns) { *p_outputs[0] = another->call(function,p_inputs,input_args,r_error); } else { another->call(function,p_inputs,input_args,r_error); @@ -547,7 +730,12 @@ public: Variant v = *p_inputs[0]; - if (returns) { + if (rpc_mode) { + Object *obj = v; + if (obj) { + call_rpc(obj,p_inputs+1,input_args-1); + } + } else if (returns) { *p_outputs[0] = v.call(function,p_inputs+1,input_args,r_error); } else { v.call(function,p_inputs+1,input_args,r_error); @@ -573,14 +761,17 @@ VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VisualScriptInstanc 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; return instance; } VisualScriptFunctionCall::VisualScriptFunctionCall() { - call_mode=CALL_MODE_INSTANCE; + call_mode=CALL_MODE_SELF; basic_type=Variant::NIL; use_default_args=0; base_type="Object"; + rpc_call_mode=RPC_DISABLED; + } @@ -705,55 +896,9 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const } } -#ifdef DEBUG_METHODS_ENABLED - - //not very efficient but.. - - - List<PropertyInfo> pinfo; - - if (call_mode==CALL_MODE_BASIC_TYPE) { - - - Variant v; - if (basic_type==Variant::INPUT_EVENT) { - InputEvent ev; - ev.type=event_type; - v=ev; - } else { - Variant::CallError ce; - v = Variant::construct(basic_type,NULL,0,ce); - } - v.get_property_list(&pinfo); - - } else if (call_mode==CALL_MODE_NODE_PATH) { - - Node *n = _get_base_node(); - if (n) { - n->get_property_list(&pinfo); - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } - - - for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { - - if (E->get().name==property) { - - PropertyInfo info=E->get(); - info.name="value"; - return info; - } - } - - -#endif - - return PropertyInfo(Variant::NIL,"value"); - + PropertyInfo pinfo=type_cache; + pinfo.name="value"; + return pinfo; } PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const{ @@ -839,6 +984,9 @@ void VisualScriptPropertySet::set_event_type(InputEvent::Type p_type) { if (event_type==p_type) return; event_type=p_type; + if (call_mode==CALL_MODE_BASIC_TYPE) { + _update_cache(); + } _change_notify(); _update_base_type(); ports_changed_notify(); @@ -865,12 +1013,133 @@ StringName VisualScriptPropertySet::get_base_type() const{ return base_type; } + +void VisualScriptPropertySet::set_base_script(const String& p_path) { + + if (base_script==p_path) + return; + + base_script=p_path; + _change_notify(); + ports_changed_notify(); +} + +String VisualScriptPropertySet::get_base_script() const { + + return base_script; +} + + +void VisualScriptPropertySet::_update_cache() { + + + if (!OS::get_singleton()->get_main_loop()) + return; + if (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>()) + return; + + if (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise + return; + + if (call_mode==CALL_MODE_BASIC_TYPE) { + + //not super efficient.. + + Variant v; + if (basic_type==Variant::INPUT_EVENT) { + InputEvent ev; + ev.type=event_type; + v=ev; + } else { + Variant::CallError ce; + v = Variant::construct(basic_type,NULL,0,ce); + } + + List<PropertyInfo> pinfo; + v.get_property_list(&pinfo); + + for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + + if (E->get().name==property) { + + type_cache=E->get(); + } + } + + } else { + + + StringName type; + Ref<Script> script; + Node *node=NULL; + + if (call_mode==CALL_MODE_NODE_PATH) { + + node=_get_base_node(); + if (node) { + type=node->get_type(); + base_type=type; //cache, too + script = node->get_script(); + } + } else if (call_mode==CALL_MODE_SELF) { + + if (get_visual_script().is_valid()) { + type=get_visual_script()->get_instance_base_type(); + base_type=type; //cache, too + script=get_visual_script(); + } + } else if (call_mode==CALL_MODE_INSTANCE) { + + type=base_type; + if (base_script!=String()) { + + 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)) { + + script = Ref<Resource>( ResourceCache::get(base_script) ); + } else { + return; + } + } + } + + List<PropertyInfo> pinfo; + + + if (node) { + + node->get_property_list(&pinfo); + } else { + ObjectTypeDB::get_property_list(type,&pinfo); + } + + if (script.is_valid()) { + + script->get_script_property_list(&pinfo); + } + + for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + + if (E->get().name==property) { + type_cache=E->get(); + return; + } + } + + } +} + void VisualScriptPropertySet::set_property(const StringName& p_type){ if (property==p_type) return; property=p_type; + _update_cache(); _change_notify(); ports_changed_notify(); } @@ -936,12 +1205,24 @@ void VisualScriptPropertySet::set_builtin_value(const Variant& p_value){ return; builtin_value=p_value; + ports_changed_notify(); } Variant VisualScriptPropertySet::get_builtin_value() const{ return builtin_value; } + + +void VisualScriptPropertySet::_set_type_cache(const Dictionary &p_type) { + type_cache=PropertyInfo::from_dict(p_type); +} + +Dictionary VisualScriptPropertySet::_get_type_cache() const { + + return type_cache; +} + void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { if (property.name=="property/base_type") { @@ -950,6 +1231,11 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { } } + if (property.name=="property/base_script") { + if (call_mode!=CALL_MODE_INSTANCE) { + property.usage=0; + } + } if (property.name=="property/basic_type") { if (call_mode!=CALL_MODE_BASIC_TYPE) { @@ -978,61 +1264,48 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { } if (property.name=="property/property") { - property.hint=PROPERTY_HINT_ENUM; - - - List<PropertyInfo> pinfo; - if (call_mode==CALL_MODE_BASIC_TYPE) { - Variant::CallError ce; - Variant v; - if (basic_type==Variant::INPUT_EVENT) { - InputEvent ev; - ev.type=event_type; - v=ev; - } else { - v = Variant::construct(basic_type,NULL,0,ce); - } - v.get_property_list(&pinfo); - } else if (call_mode==CALL_MODE_NODE_PATH) { - - Node *n = _get_base_node(); - if (n) { - n->get_property_list(&pinfo); - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } - } else { + property.hint=PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE; + property.hint_string=Variant::get_type_name(basic_type); + } else if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid()) { + property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT; + property.hint_string=itos(get_visual_script()->get_instance_ID()); + } else if (call_mode==CALL_MODE_INSTANCE) { + property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; + property.hint_string=base_type; - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); + if (base_script!=String()) { + if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - } + ScriptServer::edit_request_func(base_script); //make sure it's loaded + } - List<String> mstring; + if (ResourceCache::has(base_script)) { - for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) ); + if (script.is_valid()) { - if (E->get().usage&PROPERTY_USAGE_EDITOR) { - mstring.push_back(E->get().name); + property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT; + property.hint_string=itos(script->get_instance_ID()); + } + } } - } - String ml; - for (List<String>::Element *E=mstring.front();E;E=E->next()) { + } else if (call_mode==CALL_MODE_NODE_PATH) { + Node *node = _get_base_node(); + if (node) { + property.hint=PROPERTY_HINT_PROPERTY_OF_INSTANCE; + property.hint_string=itos(node->get_instance_ID()); + } else { + property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; + property.hint_string=get_base_type(); + } - if (ml!=String()) - ml+=","; - ml+=E->get(); } - if (ml==String()) { - property.usage=PROPERTY_USAGE_NOEDITOR; //do not show for editing if empty - } else { - property.hint_string=ml; - } } if (property.name=="value/builtin") { @@ -1040,34 +1313,9 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const { if (!use_builtin_value) { property.usage=0; } else { - List<PropertyInfo> pinfo; - - if (call_mode==CALL_MODE_BASIC_TYPE) { - Variant::CallError ce; - Variant v = Variant::construct(basic_type,NULL,0,ce); - v.get_property_list(&pinfo); - - } else if (call_mode==CALL_MODE_NODE_PATH) { - - Node *n = _get_base_node(); - if (n) { - n->get_property_list(&pinfo); - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } - - for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { - - if (E->get().name==this->property) { - - property.hint=E->get().hint; - property.type=E->get().type; - property.hint_string=E->get().hint_string; - } - } + property.type=type_cache.type; + property.hint=type_cache.hint; + property.hint_string=type_cache.hint_string; } } @@ -1078,10 +1326,15 @@ void VisualScriptPropertySet::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertySet::set_base_type); ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptPropertySet::get_base_type); + ObjectTypeDB::bind_method(_MD("set_base_script","base_script"),&VisualScriptPropertySet::set_base_script); + ObjectTypeDB::bind_method(_MD("get_base_script"),&VisualScriptPropertySet::get_base_script); ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertySet::set_basic_type); ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertySet::get_basic_type); + ObjectTypeDB::bind_method(_MD("_set_type_cache","type_cache"),&VisualScriptPropertySet::_set_type_cache); + ObjectTypeDB::bind_method(_MD("_get_type_cache"),&VisualScriptPropertySet::_get_type_cache); + ObjectTypeDB::bind_method(_MD("set_event_type","event_type"),&VisualScriptPropertySet::set_event_type); ObjectTypeDB::bind_method(_MD("get_event_type"),&VisualScriptPropertySet::get_event_type); @@ -1116,9 +1369,22 @@ void VisualScriptPropertySet::_bind_methods() { et+=event_type_names[i]; } + List<String> script_extensions; + for(int i=0;i<ScriptServer::get_language_count();i++) { + ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions); + } + + String script_ext_hint; + for (List<String>::Element *E=script_extensions.front();E;E=E->next()) { + if (script_ext_hint!=String()) + script_ext_hint+=","; + script_ext_hint+="*."+E->get(); + } - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type",PROPERTY_USAGE_NOEDITOR),_SCS("set_call_mode"),_SCS("get_call_mode")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),_SCS("set_call_mode"),_SCS("get_call_mode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),_SCS("set_base_script"),_SCS("get_base_script")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/type_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_type_cache"),_SCS("_get_type_cache")); ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); ADD_PROPERTY(PropertyInfo(Variant::INT,"property/event_type",PROPERTY_HINT_ENUM,et),_SCS("set_event_type"),_SCS("get_event_type")); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); @@ -1250,7 +1516,7 @@ VisualScriptNodeInstance* VisualScriptPropertySet::instance(VisualScriptInstance VisualScriptPropertySet::VisualScriptPropertySet() { - call_mode=CALL_MODE_INSTANCE; + call_mode=CALL_MODE_SELF; base_type="Object"; basic_type=Variant::NIL; event_type=InputEvent::NONE; @@ -1348,6 +1614,7 @@ StringName VisualScriptPropertyGet::_get_base_type() const { return base_type; } + int VisualScriptPropertyGet::get_input_value_port_count() const{ return (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0; @@ -1381,17 +1648,69 @@ PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const{ + return PropertyInfo(type_cache,"value"); +} -#ifdef DEBUG_METHODS_ENABLED +String VisualScriptPropertyGet::get_caption() const { - //not very efficient but.. + static const char*cname[4]= { + "SelfGet", + "NodeGet", + "InstanceGet", + "BasicGet" + }; + + return cname[call_mode]; +} + +String VisualScriptPropertyGet::get_text() const { + + + if (call_mode==CALL_MODE_BASIC_TYPE) + return Variant::get_type_name(basic_type)+"."+property; + else + return property; + +} +void VisualScriptPropertyGet::set_base_type(const StringName& p_type) { + + if (base_type==p_type) + return; + + base_type=p_type; + _change_notify(); + ports_changed_notify(); +} + +StringName VisualScriptPropertyGet::get_base_type() const{ + + return base_type; +} + +void VisualScriptPropertyGet::set_base_script(const String& p_path) { + + if (base_script==p_path) + return; + + base_script=p_path; + _change_notify(); + ports_changed_notify(); +} + +String VisualScriptPropertyGet::get_base_script() const { + + return base_script; +} + + +void VisualScriptPropertyGet::_update_cache() { - List<PropertyInfo> pinfo; if (call_mode==CALL_MODE_BASIC_TYPE) { + //not super efficient.. Variant v; if (basic_type==Variant::INPUT_EVENT) { @@ -1402,71 +1721,91 @@ PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) cons Variant::CallError ce; v = Variant::construct(basic_type,NULL,0,ce); } + + List<PropertyInfo> pinfo; v.get_property_list(&pinfo); - } else if (call_mode==CALL_MODE_NODE_PATH) { - Node *n = _get_base_node(); - if (n) { - n->get_property_list(&pinfo); - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); + for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + + if (E->get().name==property) { + + type_cache=E->get().type; + return; + } } + } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } - for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { - if (E->get().name==property) { + StringName type; + Ref<Script> script; + Node *node=NULL; - PropertyInfo info=E->get(); - info.name=""; - return info; - } - } + if (call_mode==CALL_MODE_NODE_PATH) { + node=_get_base_node(); + if (node) { + type=node->get_type(); + base_type=type; //cache, too + script = node->get_script(); + } + } else if (call_mode==CALL_MODE_SELF) { -#endif + if (get_visual_script().is_valid()) { + type=get_visual_script()->get_instance_base_type(); + base_type=type; //cache, too + script=get_visual_script(); + } + } else if (call_mode==CALL_MODE_INSTANCE) { - return PropertyInfo(Variant::NIL,""); -} + type=base_type; + if (base_script!=String()) { + if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { -String VisualScriptPropertyGet::get_caption() const { + ScriptServer::edit_request_func(base_script); //make sure it's loaded + } - static const char*cname[4]= { - "SelfGet", - "NodeGet", - "InstanceGet", - "BasicGet" - }; + if (ResourceCache::has(base_script)) { - return cname[call_mode]; -} + script = Ref<Resource>( ResourceCache::get(base_script) ); + } else { + return; + } + } + } -String VisualScriptPropertyGet::get_text() const { + bool valid=false; - if (call_mode==CALL_MODE_BASIC_TYPE) - return Variant::get_type_name(basic_type)+"."+property; - else - return property; + Variant::Type type_ret; -} + type_ret=ObjectTypeDB::get_property_type(base_type,property,&valid); -void VisualScriptPropertyGet::set_base_type(const StringName& p_type) { + if (valid) { + type_cache=type_ret; + return; //all dandy + } - if (base_type==p_type) - return; + if (node) { - base_type=p_type; - _change_notify(); - ports_changed_notify(); -} + Variant prop = node->get(property,&valid); + if (valid) { + type_cache=prop.get_type(); + return; //all dandy again + } + } -StringName VisualScriptPropertyGet::get_base_type() const{ + if (script.is_valid()) { - return base_type; + type_ret=script->get_static_property_type(property,&valid); + + if (valid) { + type_cache=type_ret; + return; //all dandy + } + } + } } void VisualScriptPropertyGet::set_property(const StringName& p_type){ @@ -1475,6 +1814,9 @@ void VisualScriptPropertyGet::set_property(const StringName& p_type){ return; property=p_type; + + + _update_cache(); _change_notify(); ports_changed_notify(); } @@ -1541,6 +1883,9 @@ void VisualScriptPropertyGet::set_event_type(InputEvent::Type p_type) { if (event_type==p_type) return; event_type=p_type; + if(call_mode==CALL_MODE_BASIC_TYPE) { + _update_cache(); + } _change_notify(); _update_base_type(); ports_changed_notify(); @@ -1551,6 +1896,17 @@ InputEvent::Type VisualScriptPropertyGet::get_event_type() const{ return event_type; } + +void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) { + type_cache=p_type; +} + +Variant::Type VisualScriptPropertyGet::_get_type_cache() const { + + return type_cache; +} + + void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { if (property.name=="property/base_type") { @@ -1559,6 +1915,11 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { } } + if (property.name=="property/base_script") { + if (call_mode!=CALL_MODE_INSTANCE) { + property.usage=0; + } + } if (property.name=="property/basic_type") { if (call_mode!=CALL_MODE_BASIC_TYPE) { @@ -1586,55 +1947,45 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const { } if (property.name=="property/property") { - property.hint=PROPERTY_HINT_ENUM; - - - List<PropertyInfo> pinfo; if (call_mode==CALL_MODE_BASIC_TYPE) { - Variant::CallError ce; - Variant v; - if (basic_type==Variant::INPUT_EVENT) { - InputEvent ev; - ev.type=event_type; - v=ev; - } else { - v = Variant::construct(basic_type,NULL,0,ce); - } - v.get_property_list(&pinfo); - } else if (call_mode==CALL_MODE_NODE_PATH) { + property.hint=PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE; + property.hint_string=Variant::get_type_name(basic_type); - Node *n = _get_base_node(); - if (n) { - n->get_property_list(&pinfo); - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } - } else { - ObjectTypeDB::get_property_list(_get_base_type(),&pinfo); - } + } else if (call_mode==CALL_MODE_SELF && get_visual_script().is_valid()) { + property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT; + property.hint_string=itos(get_visual_script()->get_instance_ID()); + } else if (call_mode==CALL_MODE_INSTANCE) { + property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; + property.hint_string=base_type; - List<String> mstring; + if (base_script!=String()) { + if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - for (List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) { + ScriptServer::edit_request_func(base_script); //make sure it's loaded + } - if (E->get().usage&PROPERTY_USAGE_EDITOR) - mstring.push_back(E->get().name); - } + if (ResourceCache::has(base_script)) { - String ml; - for (List<String>::Element *E=mstring.front();E;E=E->next()) { + Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) ); + if (script.is_valid()) { - if (ml!=String()) - ml+=","; - ml+=E->get(); - } + property.hint=PROPERTY_HINT_PROPERTY_OF_SCRIPT; + property.hint_string=itos(script->get_instance_ID()); + } + } + } + } else if (call_mode==CALL_MODE_NODE_PATH) { + Node *node = _get_base_node(); + if (node) { + property.hint=PROPERTY_HINT_PROPERTY_OF_INSTANCE; + property.hint_string=itos(node->get_instance_ID()); + } else { + property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE; + property.hint_string=get_base_type(); + } - if (ml==String()) { - property.usage=PROPERTY_USAGE_NOEDITOR; //do not show for editing if empty - } else { - property.hint_string=ml; } } @@ -1646,10 +1997,15 @@ void VisualScriptPropertyGet::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_base_type","base_type"),&VisualScriptPropertyGet::set_base_type); ObjectTypeDB::bind_method(_MD("get_base_type"),&VisualScriptPropertyGet::get_base_type); + ObjectTypeDB::bind_method(_MD("set_base_script","base_script"),&VisualScriptPropertyGet::set_base_script); + ObjectTypeDB::bind_method(_MD("get_base_script"),&VisualScriptPropertyGet::get_base_script); ObjectTypeDB::bind_method(_MD("set_basic_type","basic_type"),&VisualScriptPropertyGet::set_basic_type); ObjectTypeDB::bind_method(_MD("get_basic_type"),&VisualScriptPropertyGet::get_basic_type); + ObjectTypeDB::bind_method(_MD("_set_type_cache","type_cache"),&VisualScriptPropertyGet::_set_type_cache); + ObjectTypeDB::bind_method(_MD("_get_type_cache"),&VisualScriptPropertyGet::_get_type_cache); + ObjectTypeDB::bind_method(_MD("set_event_type","event_type"),&VisualScriptPropertyGet::set_event_type); ObjectTypeDB::bind_method(_MD("get_event_type"),&VisualScriptPropertyGet::get_event_type); @@ -1679,9 +2035,22 @@ void VisualScriptPropertyGet::_bind_methods() { et+=event_type_names[i]; } + List<String> script_extensions; + for(int i=0;i<ScriptServer::get_language_count();i++) { + ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions); + } - ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance",PROPERTY_USAGE_NOEDITOR),_SCS("set_call_mode"),_SCS("get_call_mode")); + String script_ext_hint; + for (List<String>::Element *E=script_extensions.front();E;E=E->next()) { + if (script_ext_hint!=String()) + script_ext_hint+=","; + script_ext_hint+="."+E->get(); + } + + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/set_mode",PROPERTY_HINT_ENUM,"Self,Node Path,Instance,Basic Type"),_SCS("set_call_mode"),_SCS("get_call_mode")); ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_type",PROPERTY_HINT_TYPE_STRING,"Object"),_SCS("set_base_type"),_SCS("get_base_type")); + ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/base_script",PROPERTY_HINT_FILE,script_ext_hint),_SCS("set_base_script"),_SCS("get_base_script")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"property/type_cache",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_type_cache"),_SCS("_get_type_cache")); ADD_PROPERTY(PropertyInfo(Variant::INT,"property/basic_type",PROPERTY_HINT_ENUM,bt),_SCS("set_basic_type"),_SCS("get_basic_type")); ADD_PROPERTY(PropertyInfo(Variant::INT,"property/event_type",PROPERTY_HINT_ENUM,et),_SCS("set_event_type"),_SCS("get_event_type")); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"property/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); @@ -1797,10 +2166,11 @@ VisualScriptNodeInstance* VisualScriptPropertyGet::instance(VisualScriptInstance VisualScriptPropertyGet::VisualScriptPropertyGet() { - call_mode=CALL_MODE_INSTANCE; + call_mode=CALL_MODE_SELF; base_type="Object"; basic_type=Variant::NIL; event_type=InputEvent::NONE; + type_cache=Variant::NIL; } @@ -1815,463 +2185,6 @@ static Ref<VisualScriptNode> create_property_get_node(const String& p_name) { ////////////////////////////////////////// -////////////////SCRIPT CALL////////////////////// -////////////////////////////////////////// - -int VisualScriptScriptCall::get_output_sequence_port_count() const { - - return 1; -} - -bool VisualScriptScriptCall::has_input_sequence_port() const{ - - return true; -} - -Node *VisualScriptScriptCall::_get_base_node() const { - -#ifdef TOOLS_ENABLED - Ref<Script> script = get_visual_script(); - if (!script.is_valid()) - return NULL; - - MainLoop * main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - - SceneTree *scene_tree = main_loop->cast_to<SceneTree>(); - - if (!scene_tree) - return NULL; - - Node *edited_scene = scene_tree->get_edited_scene_root(); - - if (!edited_scene) - return NULL; - - Node* script_node = _find_script_node(edited_scene,edited_scene,script); - - if (!script_node) - return NULL; - - if (!script_node->has_node(base_path)) - return NULL; - - Node *path_to = script_node->get_node(base_path); - - return path_to; -#else - - return NULL; -#endif -} - - -int VisualScriptScriptCall::get_input_value_port_count() const{ - -#if 1 - return argument_count; -#else - if (call_mode==CALL_MODE_SELF) { - - Ref<VisualScript> vs = get_visual_script(); - if (vs.is_valid()) { - - if (!vs->has_function(function)) - return 0; - - int id = vs->get_function_node_id(function); - if (id<0) - return 0; - - Ref<VisualScriptFunction> func = vs->get_node(function,id); - - return func->get_argument_count(); - } - } else { - - Node*base = _get_base_node(); - if (!base) - return 0; - Ref<Script> script = base->get_script(); - if (!script.is_valid()) - return 0; - - List<MethodInfo> functions; - script->get_method_list(&functions); - for (List<MethodInfo>::Element *E=functions.front();E;E=E->next()) { - if (E->get().name==function) { - return E->get().arguments.size(); - } - } - - } - - - return 0; -#endif - -} -int VisualScriptScriptCall::get_output_value_port_count() const{ - return 1; -} - -String VisualScriptScriptCall::get_output_sequence_port_text(int p_port) const { - - return String(); -} - -PropertyInfo VisualScriptScriptCall::get_input_value_port_info(int p_idx) const{ - - if (call_mode==CALL_MODE_SELF) { - - Ref<VisualScript> vs = get_visual_script(); - if (vs.is_valid()) { - - if (!vs->has_function(function)) - return PropertyInfo(); - - int id = vs->get_function_node_id(function); - if (id<0) - return PropertyInfo(); - - Ref<VisualScriptFunction> func = vs->get_node(function,id); - - if (p_idx>=func->get_argument_count()) - return PropertyInfo(); - return PropertyInfo(func->get_argument_type(p_idx),func->get_argument_name(p_idx)); - } - } else { - - Node*base = _get_base_node(); - if (!base) - return PropertyInfo(); - Ref<Script> script = base->get_script(); - if (!script.is_valid()) - return PropertyInfo(); - - List<MethodInfo> functions; - script->get_method_list(&functions); - for (List<MethodInfo>::Element *E=functions.front();E;E=E->next()) { - if (E->get().name==function) { - if (p_idx<0 || p_idx>=E->get().arguments.size()) - return PropertyInfo(); - return E->get().arguments[p_idx]; - } - } - - } - - return PropertyInfo(); - -} - -PropertyInfo VisualScriptScriptCall::get_output_value_port_info(int p_idx) const{ - - return PropertyInfo(); -} - - -String VisualScriptScriptCall::get_caption() const { - - return "ScriptCall"; -} - -String VisualScriptScriptCall::get_text() const { - - return " "+String(function)+"()"; -} - -void VisualScriptScriptCall::_update_argument_count() { - - //try to remember the amount of arguments in the function, because if loaded from scratch - //this information will not be available - - if (call_mode==CALL_MODE_SELF) { - - Ref<VisualScript> vs = get_visual_script(); - if (vs.is_valid()) { - - if (!vs->has_function(function)) - return ; - - int id = vs->get_function_node_id(function); - if (id<0) - return; - - Ref<VisualScriptFunction> func = vs->get_node(function,id); - - argument_count=func->get_argument_count(); - } - } else { - - Node*base = _get_base_node(); - if (!base) - return; - - Ref<Script> script = base->get_script(); - if (!script.is_valid()) - return ; - - List<MethodInfo> functions; - script->get_method_list(&functions); - for (List<MethodInfo>::Element *E=functions.front();E;E=E->next()) { - if (E->get().name==function) { - argument_count=E->get().arguments.size(); - return; - } - } - - } -} - - -void VisualScriptScriptCall::set_function(const StringName& p_type){ - - if (function==p_type) - return; - - function=p_type; - _update_argument_count(); - _change_notify(); - ports_changed_notify(); -} -StringName VisualScriptScriptCall::get_function() const { - - - return function; -} - -void VisualScriptScriptCall::set_base_path(const NodePath& p_type) { - - if (base_path==p_type) - return; - - base_path=p_type; - _update_argument_count(); - _change_notify(); - ports_changed_notify(); -} - -NodePath VisualScriptScriptCall::get_base_path() const { - - return base_path; -} - - -void VisualScriptScriptCall::set_call_mode(CallMode p_mode) { - - if (call_mode==p_mode) - return; - - call_mode=p_mode; - _update_argument_count(); - _change_notify(); - ports_changed_notify(); - -} - -void VisualScriptScriptCall::set_argument_count(int p_count) { - - argument_count=p_count; - _change_notify(); - ports_changed_notify(); - -} - -int VisualScriptScriptCall::get_argument_count() const { - - return argument_count; -} - -VisualScriptScriptCall::CallMode VisualScriptScriptCall::get_call_mode() const { - - return call_mode; -} - -void VisualScriptScriptCall::_validate_property(PropertyInfo& property) const { - - - - if (property.name=="function/node_path") { - if (call_mode!=CALL_MODE_NODE_PATH) { - property.usage=0; - } else { - - Node *bnode = _get_base_node(); - if (bnode) { - property.hint_string=bnode->get_path(); //convert to loong string - } else { - - } - } - } - - if (property.name=="function/function") { - property.hint=PROPERTY_HINT_ENUM; - - - List<MethodInfo> methods; - - if (call_mode==CALL_MODE_SELF) { - - Ref<VisualScript> vs = get_visual_script(); - if (vs.is_valid()) { - - vs->get_method_list(&methods); - - } - } else { - - Node*base = _get_base_node(); - if (!base) - return; - Ref<Script> script = base->get_script(); - if (!script.is_valid()) - return; - - script->get_method_list(&methods); - - } - - List<String> mstring; - for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) { - if (E->get().name.begins_with("_")) - continue; - mstring.push_back(E->get().name.get_slice(":",0)); - } - - mstring.sort(); - - String ml; - for (List<String>::Element *E=mstring.front();E;E=E->next()) { - - if (ml!=String()) - ml+=","; - ml+=E->get(); - } - - property.hint_string=ml; - } - -} - - -void VisualScriptScriptCall::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_function","function"),&VisualScriptScriptCall::set_function); - ObjectTypeDB::bind_method(_MD("get_function"),&VisualScriptScriptCall::get_function); - - ObjectTypeDB::bind_method(_MD("set_call_mode","mode"),&VisualScriptScriptCall::set_call_mode); - ObjectTypeDB::bind_method(_MD("get_call_mode"),&VisualScriptScriptCall::get_call_mode); - - ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptScriptCall::set_base_path); - ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptScriptCall::get_base_path); - - ObjectTypeDB::bind_method(_MD("set_argument_count","argument_count"),&VisualScriptScriptCall::set_argument_count); - ObjectTypeDB::bind_method(_MD("get_argument_count"),&VisualScriptScriptCall::get_argument_count); - - ADD_PROPERTY(PropertyInfo(Variant::INT,"function/call_mode",PROPERTY_HINT_ENUM,"Self,Node Path"),_SCS("set_call_mode"),_SCS("get_call_mode")); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"function/node_path",PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE),_SCS("set_base_path"),_SCS("get_base_path")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/function"),_SCS("set_function"),_SCS("get_function")); - ADD_PROPERTY(PropertyInfo(Variant::STRING,"function/argument_count"),_SCS("set_argument_count"),_SCS("get_argument_count")); - - BIND_CONSTANT( CALL_MODE_SELF ); - BIND_CONSTANT( CALL_MODE_NODE_PATH); - -} - -class VisualScriptNodeInstanceScriptCall : public VisualScriptNodeInstance { -public: - - - VisualScriptScriptCall::CallMode call_mode; - NodePath node_path; - int input_args; - bool returns; - StringName function; - - VisualScriptScriptCall *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; } - - virtual int step(const Variant** p_inputs,Variant** p_outputs,StartMode p_start_mode,Variant* p_working_mem,Variant::CallError& r_error,String& r_error_str) { - - - switch(call_mode) { - - case VisualScriptScriptCall::CALL_MODE_SELF: { - - Object *object=instance->get_owner_ptr(); - - *p_outputs[0] = object->call(function,p_inputs,input_args,r_error); - - } break; - case VisualScriptScriptCall::CALL_MODE_NODE_PATH: { - - Node* node = instance->get_owner_ptr()->cast_to<Node>(); - if (!node) { - r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; - r_error_str="Base object is not a Node!"; - return 0; - } - - Node* another = node->get_node(node_path); - if (!node) { - r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; - r_error_str="Path does not lead Node!"; - return 0; - } - - - *p_outputs[0] = another->call(function,p_inputs,input_args,r_error); - - } break; - - } - return 0; - - } - - -}; - -VisualScriptNodeInstance* VisualScriptScriptCall::instance(VisualScriptInstance* p_instance) { - - VisualScriptNodeInstanceScriptCall * instance = memnew(VisualScriptNodeInstanceScriptCall ); - instance->node=this; - instance->instance=p_instance; - instance->function=function; - instance->call_mode=call_mode; - instance->node_path=base_path; - instance->input_args = argument_count; - return instance; -} - -VisualScriptScriptCall::VisualScriptScriptCall() { - - call_mode=CALL_MODE_SELF; - argument_count=0; - - -} - -template<VisualScriptScriptCall::CallMode cmode> -static Ref<VisualScriptNode> create_script_call_node(const String& p_name) { - - Ref<VisualScriptScriptCall> node; - node.instance(); - node->set_call_mode(cmode); - return node; -} - - -////////////////////////////////////////// ////////////////EMIT////////////////////// ////////////////////////////////////////// @@ -2475,24 +2388,13 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String& p_name) { void register_visual_script_func_nodes() { - VisualScriptLanguage::singleton->add_register_func("functions/call_method/call_instance",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_INSTANCE>); - VisualScriptLanguage::singleton->add_register_func("functions/call_method/call_basic_type",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE>); - VisualScriptLanguage::singleton->add_register_func("functions/call_method/call_self",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_SELF>); - VisualScriptLanguage::singleton->add_register_func("functions/call_method/call_node",create_function_call_node<VisualScriptFunctionCall::CALL_MODE_NODE_PATH>); - - VisualScriptLanguage::singleton->add_register_func("functions/property_set/instace_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_INSTANCE>); - VisualScriptLanguage::singleton->add_register_func("functions/property_set/basic_type_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_BASIC_TYPE>); - VisualScriptLanguage::singleton->add_register_func("functions/property_set/self_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_SELF>); - VisualScriptLanguage::singleton->add_register_func("functions/property_set/node_set",create_property_set_node<VisualScriptPropertySet::CALL_MODE_NODE_PATH>); - - VisualScriptLanguage::singleton->add_register_func("functions/property_get/instance_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_INSTANCE>); - VisualScriptLanguage::singleton->add_register_func("functions/property_get/basic_type_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_BASIC_TYPE>); - VisualScriptLanguage::singleton->add_register_func("functions/property_get/self_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_SELF>); - VisualScriptLanguage::singleton->add_register_func("functions/property_get/node_get",create_property_get_node<VisualScriptPropertyGet::CALL_MODE_NODE_PATH>); + 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>); - VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>); - VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>); - VisualScriptLanguage::singleton->add_register_func("functions/call_script/emit_signal",create_node_generic<VisualScriptEmitSignal>); + //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>); +// VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>); + VisualScriptLanguage::singleton->add_register_func("functions/emit_signal",create_node_generic<VisualScriptEmitSignal>); for(int i=0;i<Variant::VARIANT_MAX;i++) { |