aboutsummaryrefslogtreecommitdiff
path: root/modules/visual_script/visual_script_func_nodes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/visual_script/visual_script_func_nodes.cpp')
-rw-r--r--modules/visual_script/visual_script_func_nodes.cpp1163
1 files changed, 862 insertions, 301 deletions
diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp
index 12bc39547..5a21cb40e 100644
--- a/modules/visual_script/visual_script_func_nodes.cpp
+++ b/modules/visual_script/visual_script_func_nodes.cpp
@@ -3,6 +3,8 @@
#include "os/os.h"
#include "scene/main/node.h"
#include "visual_script_nodes.h"
+#include "io/resource_loader.h"
+#include "globals.h"
//////////////////////////////////////////
////////////////CALL//////////////////////
@@ -10,12 +12,18 @@
int VisualScriptFunctionCall::get_output_sequence_port_count() const {
- return 1;
+ if (method_cache.flags&METHOD_FLAG_CONST || call_mode==CALL_MODE_BASIC_TYPE)
+ return 0;
+ else
+ return 1;
}
bool VisualScriptFunctionCall::has_input_sequence_port() const{
- return true;
+ if (method_cache.flags&METHOD_FLAG_CONST || call_mode==CALL_MODE_BASIC_TYPE)
+ return false;
+ else
+ return true;
}
#ifdef TOOLS_ENABLED
@@ -91,20 +99,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;
}
}
@@ -117,11 +128,18 @@ int VisualScriptFunctionCall::get_output_value_port_count() const{
return returns?1:0;
} else {
+ int ret;
MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
- if (!mb)
- return 0;
+ if (mb) {
+ ret = mb->has_return() ? 1 : 0;
+ } else
+ ret = 1; //it is assumed that script always returns something
+
+ if (call_mode==CALL_MODE_INSTANCE) {
+ ret++;
+ }
- return mb->has_return() ? 1 : 0;
+ return ret;
}
}
@@ -143,6 +161,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 +183,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();
@@ -177,13 +210,34 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con
return PropertyInfo(Variant::get_method_return_type(basic_type,function),"");
} else {
- MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
- if (!mb)
- return PropertyInfo();
+ if (call_mode==CALL_MODE_INSTANCE) {
+ if (p_idx==0) {
+ return PropertyInfo(Variant::OBJECT,"pass");
+ } else {
+ p_idx--;
+ }
+ }
+
+ PropertyInfo ret;
+
+ /*MethodBind *mb = ObjectTypeDB::get_method(_get_base_type(),function);
+ if (mb) {
+
+ ret = mb->get_argument_info(-1);
+ } else {*/
+
+ ret = method_cache.return_val;
+
+ //}
+
+ if (call_mode==CALL_MODE_INSTANCE) {
+ ret.name="return";
+ } else {
+ ret.name="";
+ }
+ return ret;
+
- PropertyInfo pi = mb->get_argument_info(-1);
- pi.name="";
- return pi;
}
#else
return PropertyInfo();
@@ -193,59 +247,38 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con
String VisualScriptFunctionCall::get_caption() const {
- static const char*cname[4]= {
+ static const char*cname[5]= {
"CallSelf",
"CallNode",
"CallInstance",
- "CallBasic"
+ "CallBasic",
+ "CallSingleton"
};
- return cname[call_mode];
+ String caption = cname[call_mode];
+
+ if (rpc_call_mode) {
+ caption+=" (RPC)";
+ }
+
+ return caption;
}
String VisualScriptFunctionCall::get_text() const {
if (call_mode==CALL_MODE_SELF)
return " "+String(function)+"()";
+ if (call_mode==CALL_MODE_SINGLETON)
+ return String(singleton)+":"+String(function)+"()";
else if (call_mode==CALL_MODE_BASIC_TYPE)
return Variant::get_type_name(basic_type)+"."+String(function)+"()";
+ else if (call_mode==CALL_MODE_NODE_PATH)
+ return " ["+String(base_path.simplified())+"]."+String(function)+"()";
else
return " "+base_type+"."+String(function)+"()";
}
-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 +286,7 @@ void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) {
return;
basic_type=p_type;
- _update_defargs();
+
_change_notify();
ports_changed_notify();
}
@@ -269,7 +302,6 @@ void VisualScriptFunctionCall::set_base_type(const StringName& p_type) {
return;
base_type=p_type;
- _update_defargs();
_change_notify();
ports_changed_notify();
}
@@ -279,13 +311,144 @@ 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::set_singleton(const StringName& p_path) {
+
+ if (singleton==p_path)
+ return;
+
+ singleton=p_path;
+ Object *obj = Globals::get_singleton()->get_singleton_object(singleton);
+ if (obj) {
+ base_type=obj->get_type();
+ }
+
+ _change_notify();
+ ports_changed_notify();
+}
+
+StringName VisualScriptFunctionCall::get_singleton() const {
+
+ return singleton;
+}
+
+
+
+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_SINGLETON) {
+
+ Object *obj = Globals::get_singleton()->get_singleton_object(singleton);
+ if (obj) {
+ type=obj->get_type();
+ script=obj->get_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
+ }
+
+ if (mb->is_const()) {
+ method_cache.flags|=METHOD_FLAG_CONST;
+ }
+
+#ifdef DEBUG_METHODS_ENABLED
+
+ method_cache.return_val = mb->get_argument_info(-1);
+#endif
+
+ if (mb->is_vararg()) {
+ //for vararg just give it 10 arguments (should be enough for most use cases)
+ for(int i=0;i<10;i++) {
+ method_cache.arguments.push_back(PropertyInfo(Variant::NIL,"arg"+itos(i)));
+ use_default_args++;
+ }
+ }
+ } 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 +464,6 @@ void VisualScriptFunctionCall::set_base_path(const NodePath& p_type) {
return;
base_path=p_type;
- _update_defargs();
_change_notify();
ports_changed_notify();
}
@@ -318,7 +480,6 @@ void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) {
return;
call_mode=p_mode;
- _update_defargs();
_change_notify();
ports_changed_notify();
@@ -339,10 +500,49 @@ 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_validate(bool p_amount) {
+
+ validate=p_amount;
+}
+
+bool VisualScriptFunctionCall::get_validate() const {
+
+ return validate;
+}
+
+
+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,12 +551,36 @@ 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;
}
}
+ if (property.name=="function/singleton") {
+ if (call_mode!=CALL_MODE_SINGLETON) {
+ property.usage=0;
+ } else {
+ List<Globals::Singleton> names;
+ Globals::get_singleton()->get_singletons(&names);
+ property.hint=PROPERTY_HINT_ENUM;
+ String sl;
+ for (List<Globals::Singleton>::Element *E=names.front();E;E=E->next()) {
+ if (sl!=String())
+ sl+=",";
+ sl+=E->get().name;
+ }
+ property.hint_string=sl;
+
+ }
+ }
+
if (property.name=="function/node_path") {
if (call_mode!=CALL_MODE_NODE_PATH) {
property.usage=0;
@@ -381,9 +605,38 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo& property) const
} 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_SINGLETON) {
+
+ Object *obj = Globals::get_singleton()->get_singleton_object(singleton);
+ if (obj) {
+ property.hint=PROPERTY_HINT_METHOD_OF_INSTANCE;
+ property.hint_string=itos(obj->get_instance_ID());
+ } else {
+
+ property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE;
+ property.hint_string=base_type;//should be cached
+ }
} else if (call_mode==CALL_MODE_INSTANCE) {
property.hint=PROPERTY_HINT_METHOD_OF_BASE_TYPE;
property.hint_string=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)) {
+
+ Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) );
+ if (script.is_valid()) {
+
+ property.hint=PROPERTY_HINT_METHOD_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) {
@@ -422,6 +675,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;
+ }
+ }
+
}
@@ -430,9 +690,15 @@ 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);
+ ObjectTypeDB::bind_method(_MD("set_singleton","singleton"),&VisualScriptFunctionCall::set_singleton);
+ ObjectTypeDB::bind_method(_MD("get_singleton"),&VisualScriptFunctionCall::get_singleton);
+
ObjectTypeDB::bind_method(_MD("set_function","function"),&VisualScriptFunctionCall::set_function);
ObjectTypeDB::bind_method(_MD("get_function"),&VisualScriptFunctionCall::get_function);
@@ -445,6 +711,14 @@ 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);
+
+ ObjectTypeDB::bind_method(_MD("set_validate","enable"),&VisualScriptFunctionCall::set_validate);
+ ObjectTypeDB::bind_method(_MD("get_validate"),&VisualScriptFunctionCall::get_validate);
String bt;
for(int i=0;i<Variant::VARIANT_MAX;i++) {
@@ -454,12 +728,32 @@ 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"),_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,Singleton"),_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::STRING,"function/singleton"),_SCS("set_singleton"),_SCS("get_singleton"));
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::BOOL,"function/validate"),_SCS("set_validate"),_SCS("get_validate"));
+ 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);
@@ -474,8 +768,11 @@ public:
VisualScriptFunctionCall::CallMode call_mode;
NodePath node_path;
int input_args;
+ bool validate;
bool returns;
+ VisualScriptFunctionCall::RPCCallMode rpc_mode;
StringName function;
+ StringName singleton;
VisualScriptFunctionCall *node;
VisualScriptInstance *instance;
@@ -486,6 +783,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) {
@@ -495,7 +821,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);
@@ -517,7 +845,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);
@@ -529,15 +859,53 @@ public:
Variant v = *p_inputs[0];
- if (returns) {
- *p_outputs[0] = v.call(function,p_inputs+1,input_args,r_error);
+ if (rpc_mode) {
+ Object *obj = v;
+ if (obj) {
+ call_rpc(obj,p_inputs+1,input_args-1);
+ }
+ } else if (returns) {
+ if (call_mode==VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
+ *p_outputs[1] = v.call(function,p_inputs+1,input_args,r_error);
+ } else {
+ *p_outputs[0] = v.call(function,p_inputs+1,input_args,r_error);
+ }
} else {
v.call(function,p_inputs+1,input_args,r_error);
}
+ if (call_mode==VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
+ *p_outputs[0]=*p_inputs[0];
+ }
+
+ } break;
+ case VisualScriptFunctionCall::CALL_MODE_SINGLETON: {
+
+ Object *object=Globals::get_singleton()->get_singleton_object(singleton);
+ if (!object) {
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str="Invalid singleton name: '"+String(singleton)+"'";
+ return 0;
+ }
+
+ 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);
+ }
} break;
}
+
+ if (!validate) {
+
+ //ignore call errors if validation is disabled
+ r_error.error=Variant::CallError::CALL_OK;
+ r_error_str=String();
+ }
+
return 0;
}
@@ -550,19 +918,37 @@ VisualScriptNodeInstance* VisualScriptFunctionCall::instance(VisualScriptInstanc
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;
return instance;
}
+
+
+VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type(TypeGuess* p_inputs, int p_output) const {
+
+ if (p_output==0 && call_mode==CALL_MODE_INSTANCE) {
+ return p_inputs[0];
+ }
+
+ return VisualScriptNode::guess_output_type(p_inputs,p_output);
+
+}
+
VisualScriptFunctionCall::VisualScriptFunctionCall() {
+ validate=true;
call_mode=CALL_MODE_SELF;
basic_type=Variant::NIL;
use_default_args=0;
base_type="Object";
+ rpc_call_mode=RPC_DISABLED;
+
}
@@ -595,12 +981,12 @@ static const char* event_type_names[InputEvent::TYPE_MAX]={
int VisualScriptPropertySet::get_output_sequence_port_count() const {
- return 1;
+ return call_mode!=CALL_MODE_BASIC_TYPE ? 1 : 0;
}
bool VisualScriptPropertySet::has_input_sequence_port() const{
- return true;
+ return call_mode!=CALL_MODE_BASIC_TYPE ? true : false;
}
Node *VisualScriptPropertySet::_get_base_node() const {
@@ -657,16 +1043,13 @@ StringName VisualScriptPropertySet::_get_base_type() const {
int VisualScriptPropertySet::get_input_value_port_count() const{
- int pc = (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?1:0;
-
- if (!use_builtin_value)
- pc++;
+ int pc = (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE)?2:1;
return pc;
}
int VisualScriptPropertySet::get_output_value_port_count() const{
- return call_mode==CALL_MODE_BASIC_TYPE? 1 : 0;
+ return (call_mode==CALL_MODE_BASIC_TYPE || call_mode==CALL_MODE_INSTANCE) ? 1 : 0;
}
String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const {
@@ -687,60 +1070,16 @@ 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{
if (call_mode==CALL_MODE_BASIC_TYPE) {
return PropertyInfo(basic_type,"out");
+ } else if (call_mode==CALL_MODE_INSTANCE) {
+ return PropertyInfo(Variant::OBJECT,"pass");
} else {
return PropertyInfo();
}
@@ -766,18 +1105,12 @@ String VisualScriptPropertySet::get_text() const {
if (call_mode==CALL_MODE_BASIC_TYPE)
prop=Variant::get_type_name(basic_type)+"."+property;
- else
+ else if (call_mode==CALL_MODE_NODE_PATH)
+ prop=String(base_path)+":"+property;
+ else if (call_mode==CALL_MODE_SELF)
prop=property;
-
- if (use_builtin_value) {
- String bit = builtin_value.get_construct_string();
- if (bit.length()>40) {
- bit=bit.substr(0,40);
- bit+="...";
- }
-
- prop+="\n "+bit;
- }
+ else if (call_mode==CALL_MODE_INSTANCE)
+ prop=String(base_type)+":"+property;
return prop;
@@ -821,6 +1154,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();
@@ -847,12 +1183,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();
}
@@ -896,34 +1353,17 @@ VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const
}
-void VisualScriptPropertySet::set_use_builtin_value(bool p_use) {
- if (use_builtin_value==p_use)
- return;
-
- use_builtin_value=p_use;
- _change_notify();
- ports_changed_notify();
+void VisualScriptPropertySet::_set_type_cache(const Dictionary &p_type) {
+ type_cache=PropertyInfo::from_dict(p_type);
}
-bool VisualScriptPropertySet::is_using_builtin_value() const{
+Dictionary VisualScriptPropertySet::_get_type_cache() const {
- return use_builtin_value;
+ return type_cache;
}
-void VisualScriptPropertySet::set_builtin_value(const Variant& p_value){
-
- if (builtin_value==p_value)
- return;
-
- builtin_value=p_value;
-
-}
-Variant VisualScriptPropertySet::get_builtin_value() const{
-
- return builtin_value;
-}
void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const {
if (property.name=="property/base_type") {
@@ -932,6 +1372,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) {
@@ -972,6 +1417,24 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const {
} else if (call_mode==CALL_MODE_INSTANCE) {
property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
property.hint_string=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)) {
+
+ Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) );
+ if (script.is_valid()) {
+
+ 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) {
@@ -986,42 +1449,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo& property) const {
}
- if (property.name=="value/builtin") {
-
- 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;
- }
- }
- }
-
- }
}
void VisualScriptPropertySet::_bind_methods() {
@@ -1029,10 +1456,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);
@@ -1045,11 +1477,7 @@ void VisualScriptPropertySet::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_base_path","base_path"),&VisualScriptPropertySet::set_base_path);
ObjectTypeDB::bind_method(_MD("get_base_path"),&VisualScriptPropertySet::get_base_path);
- ObjectTypeDB::bind_method(_MD("set_builtin_value","value"),&VisualScriptPropertySet::set_builtin_value);
- ObjectTypeDB::bind_method(_MD("get_builtin_value"),&VisualScriptPropertySet::get_builtin_value);
- ObjectTypeDB::bind_method(_MD("set_use_builtin_value","enable"),&VisualScriptPropertySet::set_use_builtin_value);
- ObjectTypeDB::bind_method(_MD("is_using_builtin_value"),&VisualScriptPropertySet::is_using_builtin_value);
String bt;
for(int i=0;i<Variant::VARIANT_MAX;i++) {
@@ -1067,15 +1495,26 @@ 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"),_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"));
ADD_PROPERTY(PropertyInfo(Variant::STRING,"property/property"),_SCS("set_property"),_SCS("get_property"));
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"value/use_builtin"),_SCS("set_use_builtin_value"),_SCS("is_using_builtin_value"));
- ADD_PROPERTY(PropertyInfo(Variant::NIL,"value/builtin"),_SCS("set_builtin_value"),_SCS("get_builtin_value"));
BIND_CONSTANT( CALL_MODE_SELF );
BIND_CONSTANT( CALL_MODE_NODE_PATH);
@@ -1090,8 +1529,6 @@ public:
VisualScriptPropertySet::CallMode call_mode;
NodePath node_path;
StringName property;
- bool use_builtin;
- Variant builtin_val;
VisualScriptPropertySet *node;
VisualScriptInstance *instance;
@@ -1113,15 +1550,11 @@ public:
bool valid;
- if (use_builtin) {
- object->set(property,builtin_val,&valid);
- } else {
- object->set(property,*p_inputs[0],&valid);
- }
+ object->set(property,*p_inputs[0],&valid);
if (!valid) {
r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid index property name.";
+ r_error_str="Invalid set value '"+String(*p_inputs[0])+"' on property '"+String(property)+"' of type "+object->get_type();
}
} break;
case VisualScriptPropertySet::CALL_MODE_NODE_PATH: {
@@ -1142,15 +1575,11 @@ public:
bool valid;
- if (use_builtin) {
- another->set(property,builtin_val,&valid);
- } else {
- another->set(property,*p_inputs[0],&valid);
- }
+ another->set(property,*p_inputs[0],&valid);
if (!valid) {
r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid index property name.";
+ r_error_str="Invalid set value '"+String(*p_inputs[0])+"' on property '"+String(property)+"' of type "+another->get_type();
}
} break;
@@ -1161,20 +1590,14 @@ public:
bool valid;
- if (use_builtin) {
- v.set(property,builtin_val,&valid);
- } else {
- v.set(property,p_inputs[1],&valid);
- }
+ v.set(property,*p_inputs[1],&valid);
if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str="Invalid index property name.";
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ 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());
}
- if (call_mode==VisualScriptPropertySet::CALL_MODE_BASIC_TYPE) {
- *p_outputs[0]=v;
- }
+ *p_outputs[0]=v;
} break;
@@ -1194,11 +1617,20 @@ VisualScriptNodeInstance* VisualScriptPropertySet::instance(VisualScriptInstance
instance->property=property;
instance->call_mode=call_mode;
instance->node_path=base_path;
- instance->use_builtin=use_builtin_value;
- instance->builtin_val=builtin_value;
return instance;
}
+
+
+VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(TypeGuess* p_inputs, int p_output) const {
+
+ if (p_output==0 && call_mode==CALL_MODE_INSTANCE) {
+ return p_inputs[0];
+ }
+
+ return VisualScriptNode::guess_output_type(p_inputs,p_output);
+
+}
VisualScriptPropertySet::VisualScriptPropertySet() {
call_mode=CALL_MODE_SELF;
@@ -1224,12 +1656,12 @@ static Ref<VisualScriptNode> create_property_set_node(const String& p_name) {
int VisualScriptPropertyGet::get_output_sequence_port_count() const {
- return (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1;
+ return 0;// (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1;
}
bool VisualScriptPropertyGet::has_input_sequence_port() const{
- return (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true;
+ return false;//(call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true;
}
void VisualScriptPropertyGet::_update_base_type() {
//cache it because this information may not be available on load
@@ -1299,6 +1731,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;
@@ -1332,17 +1765,75 @@ 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 {
+
+ String prop;
+
+ if (call_mode==CALL_MODE_BASIC_TYPE)
+ prop=Variant::get_type_name(basic_type)+"."+property;
+ else if (call_mode==CALL_MODE_NODE_PATH)
+ prop=String(base_path)+":"+property;
+ else if (call_mode==CALL_MODE_SELF)
+ prop=property;
+ else if (call_mode==CALL_MODE_INSTANCE)
+ prop=String(base_type)+":"+property;
+
+ return prop;
+}
+
+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) {
@@ -1353,71 +1844,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){
@@ -1426,6 +1937,9 @@ void VisualScriptPropertyGet::set_property(const StringName& p_type){
return;
property=p_type;
+
+
+ _update_cache();
_change_notify();
ports_changed_notify();
}
@@ -1492,6 +2006,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();
@@ -1502,6 +2019,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") {
@@ -1510,6 +2038,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) {
@@ -1549,6 +2082,23 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo& property) const {
} else if (call_mode==CALL_MODE_INSTANCE) {
property.hint=PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
property.hint_string=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)) {
+
+ Ref<Script> script = Ref<Resource>( ResourceCache::get(base_script) );
+ if (script.is_valid()) {
+
+ 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) {
@@ -1570,10 +2120,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);
@@ -1603,9 +2158,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);
+ }
+
+ 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"),_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"));
@@ -1628,12 +2196,10 @@ public:
VisualScriptInstance *instance;
+ 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) {
+
- //virtual int get_working_memory_size() const { return 0; }
- virtual bool is_output_port_unsequenced(int p_idx) const { return (call_mode==VisualScriptPropertyGet::CALL_MODE_SELF || call_mode==VisualScriptPropertyGet::CALL_MODE_NODE_PATH); }
- virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const {
- //these two modes can be get directly, so they use unsequenced mode
switch(call_mode) {
case VisualScriptPropertyGet::CALL_MODE_SELF: {
@@ -1642,63 +2208,57 @@ public:
bool valid;
- *r_value = object->get(property,&valid);
+ *p_outputs[0] = object->get(property,&valid);
if (!valid) {
- //r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error=RTR("Invalid index property name.");
- return false;
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str=RTR("Invalid index property name.");
+ return 0;
}
} break;
case VisualScriptPropertyGet::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=RTR("Base object is not a Node!");
- return false;
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str=RTR("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=RTR("Path does not lead Node!");
- return false;
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str=RTR("Path does not lead Node!");
+ return 0;
}
bool valid;
- *r_value = another->get(property,&valid);
+ *p_outputs[0] = another->get(property,&valid);
if (!valid) {
- //r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error=vformat(RTR("Invalid index property name '%s' in node %s."),String(property),another->get_name());
- return false;
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str=vformat(RTR("Invalid index property name '%s' in node %s."),String(property),another->get_name());
+ return 0;
}
} break;
- default: {};
- }
- return true;
-
- }
+ default: {
- 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) {
-
-
- bool valid;
- Variant v = *p_inputs[0];
+ bool valid;
+ Variant v = *p_inputs[0];
- *p_outputs[0] = v.get(property,&valid);
+ *p_outputs[0] = v.get(property,&valid);
- if (!valid) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
- r_error_str=RTR("Invalid index property name.");
+ if (!valid) {
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error_str=RTR("Invalid index property name.");
+ }
+ };
}
-
return 0;
}
@@ -1725,6 +2285,7 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() {
base_type="Object";
basic_type=Variant::NIL;
event_type=InputEvent::NONE;
+ type_cache=Variant::NIL;
}