visual_script_func_nodes.cpp 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523
  1. /*************************************************************************/
  2. /* visual_script_func_nodes.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "visual_script_func_nodes.h"
  31. #include "io/resource_loader.h"
  32. #include "os/os.h"
  33. #include "project_settings.h"
  34. #include "scene/main/node.h"
  35. #include "scene/main/scene_tree.h"
  36. #include "visual_script_nodes.h"
  37. //////////////////////////////////////////
  38. ////////////////CALL//////////////////////
  39. //////////////////////////////////////////
  40. int VisualScriptFunctionCall::get_output_sequence_port_count() const {
  41. if (method_cache.flags & METHOD_FLAG_CONST || call_mode == CALL_MODE_BASIC_TYPE)
  42. return 0;
  43. else
  44. return 1;
  45. }
  46. bool VisualScriptFunctionCall::has_input_sequence_port() const {
  47. if (method_cache.flags & METHOD_FLAG_CONST || call_mode == CALL_MODE_BASIC_TYPE)
  48. return false;
  49. else
  50. return true;
  51. }
  52. #ifdef TOOLS_ENABLED
  53. static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
  54. if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
  55. return NULL;
  56. Ref<Script> scr = p_current_node->get_script();
  57. if (scr.is_valid() && scr == script)
  58. return p_current_node;
  59. for (int i = 0; i < p_current_node->get_child_count(); i++) {
  60. Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
  61. if (n)
  62. return n;
  63. }
  64. return NULL;
  65. }
  66. #endif
  67. Node *VisualScriptFunctionCall::_get_base_node() const {
  68. #ifdef TOOLS_ENABLED
  69. Ref<Script> script = get_visual_script();
  70. if (!script.is_valid())
  71. return NULL;
  72. MainLoop *main_loop = OS::get_singleton()->get_main_loop();
  73. if (!main_loop)
  74. return NULL;
  75. SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
  76. if (!scene_tree)
  77. return NULL;
  78. Node *edited_scene = scene_tree->get_edited_scene_root();
  79. if (!edited_scene)
  80. return NULL;
  81. Node *script_node = _find_script_node(edited_scene, edited_scene, script);
  82. if (!script_node)
  83. return NULL;
  84. if (!script_node->has_node(base_path))
  85. return NULL;
  86. Node *path_to = script_node->get_node(base_path);
  87. return path_to;
  88. #else
  89. return NULL;
  90. #endif
  91. }
  92. StringName VisualScriptFunctionCall::_get_base_type() const {
  93. if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
  94. return get_visual_script()->get_instance_base_type();
  95. else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
  96. Node *path = _get_base_node();
  97. if (path)
  98. return path->get_class();
  99. }
  100. return base_type;
  101. }
  102. int VisualScriptFunctionCall::get_input_value_port_count() const {
  103. if (call_mode == CALL_MODE_BASIC_TYPE) {
  104. Vector<StringName> names = Variant::get_method_argument_names(basic_type, function);
  105. return names.size() + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) + 1;
  106. } else {
  107. MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
  108. if (mb) {
  109. return mb->get_argument_count() + (call_mode == CALL_MODE_INSTANCE ? 1 : 0) + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) - use_default_args;
  110. }
  111. return method_cache.arguments.size() + (call_mode == CALL_MODE_INSTANCE ? 1 : 0) + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) - use_default_args;
  112. }
  113. }
  114. int VisualScriptFunctionCall::get_output_value_port_count() const {
  115. if (call_mode == CALL_MODE_BASIC_TYPE) {
  116. bool returns = false;
  117. Variant::get_method_return_type(basic_type, function, &returns);
  118. return returns ? 1 : 0;
  119. } else {
  120. int ret;
  121. MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
  122. if (mb) {
  123. ret = mb->has_return() ? 1 : 0;
  124. } else
  125. ret = 1; //it is assumed that script always returns something
  126. if (call_mode == CALL_MODE_INSTANCE) {
  127. ret++;
  128. }
  129. return ret;
  130. }
  131. }
  132. String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const {
  133. return String();
  134. }
  135. PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const {
  136. if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) {
  137. if (p_idx == 0) {
  138. PropertyInfo pi;
  139. pi.type = (call_mode == CALL_MODE_INSTANCE ? Variant::OBJECT : basic_type);
  140. pi.name = (call_mode == CALL_MODE_INSTANCE ? String("instance") : Variant::get_type_name(basic_type).to_lower());
  141. return pi;
  142. } else {
  143. p_idx--;
  144. }
  145. }
  146. if (rpc_call_mode >= RPC_RELIABLE_TO_ID) {
  147. if (p_idx == 0) {
  148. return PropertyInfo(Variant::INT, "peer_id");
  149. } else {
  150. p_idx--;
  151. }
  152. }
  153. #ifdef DEBUG_METHODS_ENABLED
  154. if (call_mode == CALL_MODE_BASIC_TYPE) {
  155. Vector<StringName> names = Variant::get_method_argument_names(basic_type, function);
  156. Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type, function);
  157. return PropertyInfo(types[p_idx], names[p_idx]);
  158. } else {
  159. MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
  160. if (mb) {
  161. return mb->get_argument_info(p_idx);
  162. }
  163. if (p_idx >= 0 && p_idx < method_cache.arguments.size()) {
  164. return method_cache.arguments[p_idx];
  165. }
  166. return PropertyInfo();
  167. }
  168. #else
  169. return PropertyInfo();
  170. #endif
  171. }
  172. PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) const {
  173. #ifdef DEBUG_METHODS_ENABLED
  174. if (call_mode == CALL_MODE_BASIC_TYPE) {
  175. return PropertyInfo(Variant::get_method_return_type(basic_type, function), "");
  176. } else {
  177. if (call_mode == CALL_MODE_INSTANCE) {
  178. if (p_idx == 0) {
  179. return PropertyInfo(Variant::OBJECT, "pass");
  180. } else {
  181. p_idx--;
  182. }
  183. }
  184. PropertyInfo ret;
  185. /*MethodBind *mb = ClassDB::get_method(_get_base_type(),function);
  186. if (mb) {
  187. ret = mb->get_argument_info(-1);
  188. } else {*/
  189. ret = method_cache.return_val;
  190. //}
  191. if (call_mode == CALL_MODE_INSTANCE) {
  192. ret.name = "return";
  193. } else {
  194. ret.name = "";
  195. }
  196. return ret;
  197. }
  198. #else
  199. return PropertyInfo();
  200. #endif
  201. }
  202. String VisualScriptFunctionCall::get_caption() const {
  203. static const char *cname[5] = {
  204. "CallSelf",
  205. "CallNode",
  206. "CallInstance",
  207. "CallBasic",
  208. "CallSingleton"
  209. };
  210. String caption = cname[call_mode];
  211. if (rpc_call_mode) {
  212. caption += " (RPC)";
  213. }
  214. return caption;
  215. }
  216. String VisualScriptFunctionCall::get_text() const {
  217. if (call_mode == CALL_MODE_SELF)
  218. return " " + String(function) + "()";
  219. if (call_mode == CALL_MODE_SINGLETON)
  220. return String(singleton) + ":" + String(function) + "()";
  221. else if (call_mode == CALL_MODE_BASIC_TYPE)
  222. return Variant::get_type_name(basic_type) + "." + String(function) + "()";
  223. else if (call_mode == CALL_MODE_NODE_PATH)
  224. return " [" + String(base_path.simplified()) + "]." + String(function) + "()";
  225. else
  226. return " " + base_type + "." + String(function) + "()";
  227. }
  228. void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) {
  229. if (basic_type == p_type)
  230. return;
  231. basic_type = p_type;
  232. _change_notify();
  233. ports_changed_notify();
  234. }
  235. Variant::Type VisualScriptFunctionCall::get_basic_type() const {
  236. return basic_type;
  237. }
  238. void VisualScriptFunctionCall::set_base_type(const StringName &p_type) {
  239. if (base_type == p_type)
  240. return;
  241. base_type = p_type;
  242. _change_notify();
  243. ports_changed_notify();
  244. }
  245. StringName VisualScriptFunctionCall::get_base_type() const {
  246. return base_type;
  247. }
  248. void VisualScriptFunctionCall::set_base_script(const String &p_path) {
  249. if (base_script == p_path)
  250. return;
  251. base_script = p_path;
  252. _change_notify();
  253. ports_changed_notify();
  254. }
  255. String VisualScriptFunctionCall::get_base_script() const {
  256. return base_script;
  257. }
  258. void VisualScriptFunctionCall::set_singleton(const StringName &p_path) {
  259. if (singleton == p_path)
  260. return;
  261. singleton = p_path;
  262. Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton);
  263. if (obj) {
  264. base_type = obj->get_class();
  265. }
  266. _change_notify();
  267. ports_changed_notify();
  268. }
  269. StringName VisualScriptFunctionCall::get_singleton() const {
  270. return singleton;
  271. }
  272. void VisualScriptFunctionCall::_update_method_cache() {
  273. StringName type;
  274. Ref<Script> script;
  275. if (call_mode == CALL_MODE_NODE_PATH) {
  276. Node *node = _get_base_node();
  277. if (node) {
  278. type = node->get_class();
  279. base_type = type; //cache, too
  280. script = node->get_script();
  281. }
  282. } else if (call_mode == CALL_MODE_SELF) {
  283. if (get_visual_script().is_valid()) {
  284. type = get_visual_script()->get_instance_base_type();
  285. base_type = type; //cache, too
  286. script = get_visual_script();
  287. }
  288. } else if (call_mode == CALL_MODE_SINGLETON) {
  289. Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton);
  290. if (obj) {
  291. type = obj->get_class();
  292. script = obj->get_script();
  293. }
  294. } else if (call_mode == CALL_MODE_INSTANCE) {
  295. type = base_type;
  296. if (base_script != String()) {
  297. if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
  298. ScriptServer::edit_request_func(base_script); //make sure it's loaded
  299. }
  300. if (ResourceCache::has(base_script)) {
  301. script = Ref<Resource>(ResourceCache::get(base_script));
  302. } else {
  303. return;
  304. }
  305. }
  306. }
  307. //print_line("BASE: "+String(type)+" FUNC: "+String(function));
  308. MethodBind *mb = ClassDB::get_method(type, function);
  309. if (mb) {
  310. use_default_args = mb->get_default_argument_count();
  311. method_cache = MethodInfo();
  312. for (int i = 0; i < mb->get_argument_count(); i++) {
  313. #ifdef DEBUG_METHODS_ENABLED
  314. method_cache.arguments.push_back(mb->get_argument_info(i));
  315. #else
  316. method_cache.arguments.push_back(PropertyInfo());
  317. #endif
  318. }
  319. if (mb->is_const()) {
  320. method_cache.flags |= METHOD_FLAG_CONST;
  321. }
  322. #ifdef DEBUG_METHODS_ENABLED
  323. method_cache.return_val = mb->get_argument_info(-1);
  324. #endif
  325. if (mb->is_vararg()) {
  326. //for vararg just give it 10 arguments (should be enough for most use cases)
  327. for (int i = 0; i < 10; i++) {
  328. method_cache.arguments.push_back(PropertyInfo(Variant::NIL, "arg" + itos(i)));
  329. use_default_args++;
  330. }
  331. }
  332. } else if (script.is_valid() && script->has_method(function)) {
  333. method_cache = script->get_method_info(function);
  334. use_default_args = method_cache.default_arguments.size();
  335. }
  336. }
  337. void VisualScriptFunctionCall::set_function(const StringName &p_type) {
  338. if (function == p_type)
  339. return;
  340. function = p_type;
  341. if (call_mode == CALL_MODE_BASIC_TYPE) {
  342. use_default_args = Variant::get_method_default_arguments(basic_type, function).size();
  343. } else {
  344. //update all caches
  345. _update_method_cache();
  346. }
  347. _change_notify();
  348. ports_changed_notify();
  349. }
  350. StringName VisualScriptFunctionCall::get_function() const {
  351. return function;
  352. }
  353. void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) {
  354. if (base_path == p_type)
  355. return;
  356. base_path = p_type;
  357. _change_notify();
  358. ports_changed_notify();
  359. }
  360. NodePath VisualScriptFunctionCall::get_base_path() const {
  361. return base_path;
  362. }
  363. void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) {
  364. if (call_mode == p_mode)
  365. return;
  366. call_mode = p_mode;
  367. _change_notify();
  368. ports_changed_notify();
  369. }
  370. VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() const {
  371. return call_mode;
  372. }
  373. void VisualScriptFunctionCall::set_use_default_args(int p_amount) {
  374. if (use_default_args == p_amount)
  375. return;
  376. use_default_args = p_amount;
  377. ports_changed_notify();
  378. }
  379. void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCallMode p_mode) {
  380. if (rpc_call_mode == p_mode)
  381. return;
  382. rpc_call_mode = p_mode;
  383. ports_changed_notify();
  384. _change_notify();
  385. }
  386. VisualScriptFunctionCall::RPCCallMode VisualScriptFunctionCall::get_rpc_call_mode() const {
  387. return rpc_call_mode;
  388. }
  389. int VisualScriptFunctionCall::get_use_default_args() const {
  390. return use_default_args;
  391. }
  392. void VisualScriptFunctionCall::set_validate(bool p_amount) {
  393. validate = p_amount;
  394. }
  395. bool VisualScriptFunctionCall::get_validate() const {
  396. return validate;
  397. }
  398. void VisualScriptFunctionCall::_set_argument_cache(const Dictionary &p_cache) {
  399. //so everything works in case all else fails
  400. method_cache = MethodInfo::from_dict(p_cache);
  401. }
  402. Dictionary VisualScriptFunctionCall::_get_argument_cache() const {
  403. return method_cache;
  404. }
  405. void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const {
  406. if (property.name == "base_type") {
  407. if (call_mode != CALL_MODE_INSTANCE) {
  408. property.usage = PROPERTY_USAGE_NOEDITOR;
  409. }
  410. }
  411. if (property.name == "base_script") {
  412. if (call_mode != CALL_MODE_INSTANCE) {
  413. property.usage = 0;
  414. }
  415. }
  416. if (property.name == "basic_type") {
  417. if (call_mode != CALL_MODE_BASIC_TYPE) {
  418. property.usage = 0;
  419. }
  420. }
  421. if (property.name == "singleton") {
  422. if (call_mode != CALL_MODE_SINGLETON) {
  423. property.usage = 0;
  424. } else {
  425. List<ProjectSettings::Singleton> names;
  426. ProjectSettings::get_singleton()->get_singletons(&names);
  427. property.hint = PROPERTY_HINT_ENUM;
  428. String sl;
  429. for (List<ProjectSettings::Singleton>::Element *E = names.front(); E; E = E->next()) {
  430. if (sl != String())
  431. sl += ",";
  432. sl += E->get().name;
  433. }
  434. property.hint_string = sl;
  435. }
  436. }
  437. if (property.name == "node_path") {
  438. if (call_mode != CALL_MODE_NODE_PATH) {
  439. property.usage = 0;
  440. } else {
  441. Node *bnode = _get_base_node();
  442. if (bnode) {
  443. property.hint_string = bnode->get_path(); //convert to loong string
  444. } else {
  445. }
  446. }
  447. }
  448. if (property.name == "function") {
  449. if (call_mode == CALL_MODE_BASIC_TYPE) {
  450. property.hint = PROPERTY_HINT_METHOD_OF_VARIANT_TYPE;
  451. property.hint_string = Variant::get_type_name(basic_type);
  452. } else if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) {
  453. property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT;
  454. property.hint_string = itos(get_visual_script()->get_instance_id());
  455. } else if (call_mode == CALL_MODE_SINGLETON) {
  456. Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton);
  457. if (obj) {
  458. property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE;
  459. property.hint_string = itos(obj->get_instance_id());
  460. } else {
  461. property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE;
  462. property.hint_string = base_type; //should be cached
  463. }
  464. } else if (call_mode == CALL_MODE_INSTANCE) {
  465. property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE;
  466. property.hint_string = base_type;
  467. if (base_script != String()) {
  468. if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
  469. ScriptServer::edit_request_func(base_script); //make sure it's loaded
  470. }
  471. if (ResourceCache::has(base_script)) {
  472. Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script));
  473. if (script.is_valid()) {
  474. property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT;
  475. property.hint_string = itos(script->get_instance_id());
  476. }
  477. }
  478. }
  479. } else if (call_mode == CALL_MODE_NODE_PATH) {
  480. Node *node = _get_base_node();
  481. if (node) {
  482. property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE;
  483. property.hint_string = itos(node->get_instance_id());
  484. } else {
  485. property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE;
  486. property.hint_string = get_base_type();
  487. }
  488. }
  489. }
  490. if (property.name == "use_default_args") {
  491. property.hint = PROPERTY_HINT_RANGE;
  492. int mc = 0;
  493. if (call_mode == CALL_MODE_BASIC_TYPE) {
  494. mc = Variant::get_method_default_arguments(basic_type, function).size();
  495. } else {
  496. MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
  497. if (mb) {
  498. mc = mb->get_default_argument_count();
  499. }
  500. }
  501. if (mc == 0) {
  502. property.usage = 0; //do not show
  503. } else {
  504. property.hint_string = "0," + itos(mc) + ",1";
  505. }
  506. }
  507. if (property.name == "rpc_call_mode") {
  508. if (call_mode == CALL_MODE_BASIC_TYPE) {
  509. property.usage = 0;
  510. }
  511. }
  512. }
  513. void VisualScriptFunctionCall::_bind_methods() {
  514. ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptFunctionCall::set_base_type);
  515. ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptFunctionCall::get_base_type);
  516. ClassDB::bind_method(D_METHOD("set_base_script", "base_script"), &VisualScriptFunctionCall::set_base_script);
  517. ClassDB::bind_method(D_METHOD("get_base_script"), &VisualScriptFunctionCall::get_base_script);
  518. ClassDB::bind_method(D_METHOD("set_basic_type", "basic_type"), &VisualScriptFunctionCall::set_basic_type);
  519. ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptFunctionCall::get_basic_type);
  520. ClassDB::bind_method(D_METHOD("set_singleton", "singleton"), &VisualScriptFunctionCall::set_singleton);
  521. ClassDB::bind_method(D_METHOD("get_singleton"), &VisualScriptFunctionCall::get_singleton);
  522. ClassDB::bind_method(D_METHOD("set_function", "function"), &VisualScriptFunctionCall::set_function);
  523. ClassDB::bind_method(D_METHOD("get_function"), &VisualScriptFunctionCall::get_function);
  524. ClassDB::bind_method(D_METHOD("set_call_mode", "mode"), &VisualScriptFunctionCall::set_call_mode);
  525. ClassDB::bind_method(D_METHOD("get_call_mode"), &VisualScriptFunctionCall::get_call_mode);
  526. ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &VisualScriptFunctionCall::set_base_path);
  527. ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptFunctionCall::get_base_path);
  528. ClassDB::bind_method(D_METHOD("set_use_default_args", "amount"), &VisualScriptFunctionCall::set_use_default_args);
  529. ClassDB::bind_method(D_METHOD("get_use_default_args"), &VisualScriptFunctionCall::get_use_default_args);
  530. ClassDB::bind_method(D_METHOD("_set_argument_cache", "argument_cache"), &VisualScriptFunctionCall::_set_argument_cache);
  531. ClassDB::bind_method(D_METHOD("_get_argument_cache"), &VisualScriptFunctionCall::_get_argument_cache);
  532. ClassDB::bind_method(D_METHOD("set_rpc_call_mode", "mode"), &VisualScriptFunctionCall::set_rpc_call_mode);
  533. ClassDB::bind_method(D_METHOD("get_rpc_call_mode"), &VisualScriptFunctionCall::get_rpc_call_mode);
  534. ClassDB::bind_method(D_METHOD("set_validate", "enable"), &VisualScriptFunctionCall::set_validate);
  535. ClassDB::bind_method(D_METHOD("get_validate"), &VisualScriptFunctionCall::get_validate);
  536. String bt;
  537. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  538. if (i > 0)
  539. bt += ",";
  540. bt += Variant::get_type_name(Variant::Type(i));
  541. }
  542. List<String> script_extensions;
  543. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  544. ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
  545. }
  546. String script_ext_hint;
  547. for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
  548. if (script_ext_hint != String())
  549. script_ext_hint += ",";
  550. script_ext_hint += "*." + E->get();
  551. }
  552. ADD_PROPERTY(PropertyInfo(Variant::INT, "call_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type,Singleton"), "set_call_mode", "get_call_mode");
  553. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type");
  554. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script");
  555. ADD_PROPERTY(PropertyInfo(Variant::STRING, "singleton"), "set_singleton", "get_singleton");
  556. ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
  557. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
  558. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "argument_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_argument_cache", "_get_argument_cache");
  559. ADD_PROPERTY(PropertyInfo(Variant::STRING, "function"), "set_function", "get_function"); //when set, if loaded properly, will override argument count.
  560. ADD_PROPERTY(PropertyInfo(Variant::INT, "use_default_args"), "set_use_default_args", "get_use_default_args");
  561. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "validate"), "set_validate", "get_validate");
  562. ADD_PROPERTY(PropertyInfo(Variant::INT, "rpc_call_mode", PROPERTY_HINT_ENUM, "Disabled,Reliable,Unreliable,ReliableToID,UnreliableToID"), "set_rpc_call_mode", "get_rpc_call_mode"); //when set, if loaded properly, will override argument count.
  563. BIND_CONSTANT(CALL_MODE_SELF);
  564. BIND_CONSTANT(CALL_MODE_NODE_PATH);
  565. BIND_CONSTANT(CALL_MODE_INSTANCE);
  566. BIND_CONSTANT(CALL_MODE_BASIC_TYPE);
  567. }
  568. class VisualScriptNodeInstanceFunctionCall : public VisualScriptNodeInstance {
  569. public:
  570. VisualScriptFunctionCall::CallMode call_mode;
  571. NodePath node_path;
  572. int input_args;
  573. bool validate;
  574. bool returns;
  575. VisualScriptFunctionCall::RPCCallMode rpc_mode;
  576. StringName function;
  577. StringName singleton;
  578. VisualScriptFunctionCall *node;
  579. VisualScriptInstance *instance;
  580. //virtual int get_working_memory_size() const { return 0; }
  581. //virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
  582. //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
  583. _FORCE_INLINE_ bool call_rpc(Object *p_base, const Variant **p_args, int p_argcount) {
  584. if (!p_base)
  585. return false;
  586. Node *node = p_base->cast_to<Node>();
  587. if (!node)
  588. return false;
  589. int to_id = 0;
  590. bool reliable = true;
  591. if (rpc_mode >= VisualScriptFunctionCall::RPC_RELIABLE_TO_ID) {
  592. to_id = *p_args[0];
  593. p_args += 1;
  594. p_argcount -= 1;
  595. if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE_TO_ID) {
  596. reliable = false;
  597. }
  598. } else if (rpc_mode == VisualScriptFunctionCall::RPC_UNRELIABLE) {
  599. reliable = false;
  600. }
  601. node->rpcp(to_id, !reliable, function, p_args, p_argcount);
  602. return true;
  603. }
  604. 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) {
  605. switch (call_mode) {
  606. case VisualScriptFunctionCall::CALL_MODE_SELF: {
  607. Object *object = instance->get_owner_ptr();
  608. if (rpc_mode) {
  609. call_rpc(object, p_inputs, input_args);
  610. } else if (returns) {
  611. *p_outputs[0] = object->call(function, p_inputs, input_args, r_error);
  612. } else {
  613. object->call(function, p_inputs, input_args, r_error);
  614. }
  615. } break;
  616. case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: {
  617. Node *node = instance->get_owner_ptr()->cast_to<Node>();
  618. if (!node) {
  619. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  620. r_error_str = "Base object is not a Node!";
  621. return 0;
  622. }
  623. Node *another = node->get_node(node_path);
  624. if (!node) {
  625. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  626. r_error_str = "Path does not lead Node!";
  627. return 0;
  628. }
  629. if (rpc_mode) {
  630. call_rpc(node, p_inputs, input_args);
  631. } else if (returns) {
  632. *p_outputs[0] = another->call(function, p_inputs, input_args, r_error);
  633. } else {
  634. another->call(function, p_inputs, input_args, r_error);
  635. }
  636. } break;
  637. case VisualScriptFunctionCall::CALL_MODE_INSTANCE:
  638. case VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE: {
  639. Variant v = *p_inputs[0];
  640. if (rpc_mode) {
  641. Object *obj = v;
  642. if (obj) {
  643. call_rpc(obj, p_inputs + 1, input_args - 1);
  644. }
  645. } else if (returns) {
  646. if (call_mode == VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
  647. *p_outputs[1] = v.call(function, p_inputs + 1, input_args, r_error);
  648. } else {
  649. *p_outputs[0] = v.call(function, p_inputs + 1, input_args, r_error);
  650. }
  651. } else {
  652. v.call(function, p_inputs + 1, input_args, r_error);
  653. }
  654. if (call_mode == VisualScriptFunctionCall::CALL_MODE_INSTANCE) {
  655. *p_outputs[0] = *p_inputs[0];
  656. }
  657. } break;
  658. case VisualScriptFunctionCall::CALL_MODE_SINGLETON: {
  659. Object *object = ProjectSettings::get_singleton()->get_singleton_object(singleton);
  660. if (!object) {
  661. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  662. r_error_str = "Invalid singleton name: '" + String(singleton) + "'";
  663. return 0;
  664. }
  665. if (rpc_mode) {
  666. call_rpc(object, p_inputs, input_args);
  667. } else if (returns) {
  668. *p_outputs[0] = object->call(function, p_inputs, input_args, r_error);
  669. } else {
  670. object->call(function, p_inputs, input_args, r_error);
  671. }
  672. } break;
  673. }
  674. if (!validate) {
  675. //ignore call errors if validation is disabled
  676. r_error.error = Variant::CallError::CALL_OK;
  677. r_error_str = String();
  678. }
  679. return 0;
  680. }
  681. };
  682. VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstance *p_instance) {
  683. VisualScriptNodeInstanceFunctionCall *instance = memnew(VisualScriptNodeInstanceFunctionCall);
  684. instance->node = this;
  685. instance->instance = p_instance;
  686. instance->singleton = singleton;
  687. instance->function = function;
  688. instance->call_mode = call_mode;
  689. instance->returns = get_output_value_port_count();
  690. instance->node_path = base_path;
  691. instance->input_args = get_input_value_port_count() - ((call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0);
  692. instance->rpc_mode = rpc_call_mode;
  693. instance->validate = validate;
  694. return instance;
  695. }
  696. VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type(TypeGuess *p_inputs, int p_output) const {
  697. if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) {
  698. return p_inputs[0];
  699. }
  700. return VisualScriptNode::guess_output_type(p_inputs, p_output);
  701. }
  702. VisualScriptFunctionCall::VisualScriptFunctionCall() {
  703. validate = true;
  704. call_mode = CALL_MODE_SELF;
  705. basic_type = Variant::NIL;
  706. use_default_args = 0;
  707. base_type = "Object";
  708. rpc_call_mode = RPC_DISABLED;
  709. }
  710. template <VisualScriptFunctionCall::CallMode cmode>
  711. static Ref<VisualScriptNode> create_function_call_node(const String &p_name) {
  712. Ref<VisualScriptFunctionCall> node;
  713. node.instance();
  714. node->set_call_mode(cmode);
  715. return node;
  716. }
  717. //////////////////////////////////////////
  718. ////////////////SET//////////////////////
  719. //////////////////////////////////////////
  720. int VisualScriptPropertySet::get_output_sequence_port_count() const {
  721. return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0;
  722. }
  723. bool VisualScriptPropertySet::has_input_sequence_port() const {
  724. return call_mode != CALL_MODE_BASIC_TYPE ? true : false;
  725. }
  726. Node *VisualScriptPropertySet::_get_base_node() const {
  727. #ifdef TOOLS_ENABLED
  728. Ref<Script> script = get_visual_script();
  729. if (!script.is_valid())
  730. return NULL;
  731. MainLoop *main_loop = OS::get_singleton()->get_main_loop();
  732. if (!main_loop)
  733. return NULL;
  734. SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
  735. if (!scene_tree)
  736. return NULL;
  737. Node *edited_scene = scene_tree->get_edited_scene_root();
  738. if (!edited_scene)
  739. return NULL;
  740. Node *script_node = _find_script_node(edited_scene, edited_scene, script);
  741. if (!script_node)
  742. return NULL;
  743. if (!script_node->has_node(base_path))
  744. return NULL;
  745. Node *path_to = script_node->get_node(base_path);
  746. return path_to;
  747. #else
  748. return NULL;
  749. #endif
  750. }
  751. StringName VisualScriptPropertySet::_get_base_type() const {
  752. if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
  753. return get_visual_script()->get_instance_base_type();
  754. else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
  755. Node *path = _get_base_node();
  756. if (path)
  757. return path->get_class();
  758. }
  759. return base_type;
  760. }
  761. int VisualScriptPropertySet::get_input_value_port_count() const {
  762. int pc = (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 2 : 1;
  763. return pc;
  764. }
  765. int VisualScriptPropertySet::get_output_value_port_count() const {
  766. return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0;
  767. }
  768. String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const {
  769. return String();
  770. }
  771. void VisualScriptPropertySet::_adjust_input_index(PropertyInfo &pinfo) const {
  772. if (index != StringName()) {
  773. Variant v;
  774. Variant::CallError ce;
  775. v = Variant::construct(pinfo.type, NULL, 0, ce);
  776. Variant i = v.get(index);
  777. pinfo.type = i.get_type();
  778. }
  779. }
  780. PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const {
  781. if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) {
  782. if (p_idx == 0) {
  783. PropertyInfo pi;
  784. pi.type = (call_mode == CALL_MODE_INSTANCE ? Variant::OBJECT : basic_type);
  785. pi.name = (call_mode == CALL_MODE_INSTANCE ? String("instance") : Variant::get_type_name(basic_type).to_lower());
  786. _adjust_input_index(pi);
  787. return pi;
  788. } else {
  789. p_idx--;
  790. }
  791. }
  792. PropertyInfo pinfo = type_cache;
  793. pinfo.name = "value";
  794. _adjust_input_index(pinfo);
  795. return pinfo;
  796. }
  797. PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const {
  798. if (call_mode == CALL_MODE_BASIC_TYPE) {
  799. return PropertyInfo(basic_type, "out");
  800. } else if (call_mode == CALL_MODE_INSTANCE) {
  801. return PropertyInfo(Variant::OBJECT, "pass");
  802. } else {
  803. return PropertyInfo();
  804. }
  805. }
  806. String VisualScriptPropertySet::get_caption() const {
  807. static const char *cname[4] = {
  808. "Self",
  809. "Node",
  810. "Instance",
  811. "Basic"
  812. };
  813. static const char *opname[ASSIGN_OP_MAX] = {
  814. "Set", "Add", "Sub", "Mul", "Div", "Mod", "ShiftLeft", "ShiftRight", "BitAnd", "BitOr", "BitXor"
  815. };
  816. return String(cname[call_mode]) + opname[assign_op];
  817. }
  818. String VisualScriptPropertySet::get_text() const {
  819. String prop;
  820. if (call_mode == CALL_MODE_BASIC_TYPE)
  821. prop = Variant::get_type_name(basic_type) + "." + property;
  822. else if (call_mode == CALL_MODE_NODE_PATH)
  823. prop = String(base_path) + ":" + property;
  824. else if (call_mode == CALL_MODE_SELF)
  825. prop = property;
  826. else if (call_mode == CALL_MODE_INSTANCE)
  827. prop = String(base_type) + ":" + property;
  828. if (index != StringName()) {
  829. prop += "." + String(index);
  830. }
  831. return prop;
  832. }
  833. void VisualScriptPropertySet::_update_base_type() {
  834. //cache it because this information may not be available on load
  835. if (call_mode == CALL_MODE_NODE_PATH) {
  836. Node *node = _get_base_node();
  837. if (node) {
  838. base_type = node->get_class();
  839. }
  840. } else if (call_mode == CALL_MODE_SELF) {
  841. if (get_visual_script().is_valid()) {
  842. base_type = get_visual_script()->get_instance_base_type();
  843. }
  844. }
  845. }
  846. void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) {
  847. if (basic_type == p_type)
  848. return;
  849. basic_type = p_type;
  850. _change_notify();
  851. _update_base_type();
  852. ports_changed_notify();
  853. }
  854. Variant::Type VisualScriptPropertySet::get_basic_type() const {
  855. return basic_type;
  856. }
  857. void VisualScriptPropertySet::set_base_type(const StringName &p_type) {
  858. if (base_type == p_type)
  859. return;
  860. base_type = p_type;
  861. _change_notify();
  862. ports_changed_notify();
  863. }
  864. StringName VisualScriptPropertySet::get_base_type() const {
  865. return base_type;
  866. }
  867. void VisualScriptPropertySet::set_base_script(const String &p_path) {
  868. if (base_script == p_path)
  869. return;
  870. base_script = p_path;
  871. _change_notify();
  872. ports_changed_notify();
  873. }
  874. String VisualScriptPropertySet::get_base_script() const {
  875. return base_script;
  876. }
  877. void VisualScriptPropertySet::_update_cache() {
  878. if (!OS::get_singleton()->get_main_loop())
  879. return;
  880. if (!OS::get_singleton()->get_main_loop()->cast_to<SceneTree>())
  881. return;
  882. if (!Engine::get_singleton()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise
  883. return;
  884. if (call_mode == CALL_MODE_BASIC_TYPE) {
  885. //not super efficient..
  886. Variant v;
  887. Variant::CallError ce;
  888. v = Variant::construct(basic_type, NULL, 0, ce);
  889. List<PropertyInfo> pinfo;
  890. v.get_property_list(&pinfo);
  891. for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
  892. if (E->get().name == property) {
  893. type_cache = E->get();
  894. }
  895. }
  896. } else {
  897. StringName type;
  898. Ref<Script> script;
  899. Node *node = NULL;
  900. if (call_mode == CALL_MODE_NODE_PATH) {
  901. node = _get_base_node();
  902. if (node) {
  903. type = node->get_class();
  904. base_type = type; //cache, too
  905. script = node->get_script();
  906. }
  907. } else if (call_mode == CALL_MODE_SELF) {
  908. if (get_visual_script().is_valid()) {
  909. type = get_visual_script()->get_instance_base_type();
  910. base_type = type; //cache, too
  911. script = get_visual_script();
  912. }
  913. } else if (call_mode == CALL_MODE_INSTANCE) {
  914. type = base_type;
  915. if (base_script != String()) {
  916. if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
  917. ScriptServer::edit_request_func(base_script); //make sure it's loaded
  918. }
  919. if (ResourceCache::has(base_script)) {
  920. script = Ref<Resource>(ResourceCache::get(base_script));
  921. } else {
  922. return;
  923. }
  924. }
  925. }
  926. List<PropertyInfo> pinfo;
  927. if (node) {
  928. node->get_property_list(&pinfo);
  929. } else {
  930. ClassDB::get_property_list(type, &pinfo);
  931. }
  932. if (script.is_valid()) {
  933. script->get_script_property_list(&pinfo);
  934. }
  935. for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
  936. if (E->get().name == property) {
  937. type_cache = E->get();
  938. return;
  939. }
  940. }
  941. }
  942. }
  943. void VisualScriptPropertySet::set_property(const StringName &p_type) {
  944. if (property == p_type)
  945. return;
  946. property = p_type;
  947. index = StringName();
  948. _update_cache();
  949. _change_notify();
  950. ports_changed_notify();
  951. }
  952. StringName VisualScriptPropertySet::get_property() const {
  953. return property;
  954. }
  955. void VisualScriptPropertySet::set_base_path(const NodePath &p_type) {
  956. if (base_path == p_type)
  957. return;
  958. base_path = p_type;
  959. _update_base_type();
  960. _change_notify();
  961. ports_changed_notify();
  962. }
  963. NodePath VisualScriptPropertySet::get_base_path() const {
  964. return base_path;
  965. }
  966. void VisualScriptPropertySet::set_call_mode(CallMode p_mode) {
  967. if (call_mode == p_mode)
  968. return;
  969. call_mode = p_mode;
  970. _update_base_type();
  971. _change_notify();
  972. ports_changed_notify();
  973. }
  974. VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const {
  975. return call_mode;
  976. }
  977. void VisualScriptPropertySet::_set_type_cache(const Dictionary &p_type) {
  978. type_cache = PropertyInfo::from_dict(p_type);
  979. }
  980. Dictionary VisualScriptPropertySet::_get_type_cache() const {
  981. return type_cache;
  982. }
  983. void VisualScriptPropertySet::set_index(const StringName &p_type) {
  984. if (index == p_type)
  985. return;
  986. index = p_type;
  987. _update_cache();
  988. _change_notify();
  989. ports_changed_notify();
  990. }
  991. StringName VisualScriptPropertySet::get_index() const {
  992. return index;
  993. }
  994. void VisualScriptPropertySet::set_assign_op(AssignOp p_op) {
  995. ERR_FAIL_INDEX(p_op, ASSIGN_OP_MAX);
  996. if (assign_op == p_op)
  997. return;
  998. assign_op = p_op;
  999. _update_cache();
  1000. _change_notify();
  1001. ports_changed_notify();
  1002. }
  1003. VisualScriptPropertySet::AssignOp VisualScriptPropertySet::get_assign_op() const {
  1004. return assign_op;
  1005. }
  1006. void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
  1007. if (property.name == "base_type") {
  1008. if (call_mode != CALL_MODE_INSTANCE) {
  1009. property.usage = PROPERTY_USAGE_NOEDITOR;
  1010. }
  1011. }
  1012. if (property.name == "base_script") {
  1013. if (call_mode != CALL_MODE_INSTANCE) {
  1014. property.usage = 0;
  1015. }
  1016. }
  1017. if (property.name == "basic_type") {
  1018. if (call_mode != CALL_MODE_BASIC_TYPE) {
  1019. property.usage = 0;
  1020. }
  1021. }
  1022. if (property.name == "node_path") {
  1023. if (call_mode != CALL_MODE_NODE_PATH) {
  1024. property.usage = 0;
  1025. } else {
  1026. Node *bnode = _get_base_node();
  1027. if (bnode) {
  1028. property.hint_string = bnode->get_path(); //convert to loong string
  1029. } else {
  1030. }
  1031. }
  1032. }
  1033. if (property.name == "property") {
  1034. if (call_mode == CALL_MODE_BASIC_TYPE) {
  1035. property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
  1036. property.hint_string = Variant::get_type_name(basic_type);
  1037. } else if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) {
  1038. property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT;
  1039. property.hint_string = itos(get_visual_script()->get_instance_id());
  1040. } else if (call_mode == CALL_MODE_INSTANCE) {
  1041. property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
  1042. property.hint_string = base_type;
  1043. if (base_script != String()) {
  1044. if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
  1045. ScriptServer::edit_request_func(base_script); //make sure it's loaded
  1046. }
  1047. if (ResourceCache::has(base_script)) {
  1048. Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script));
  1049. if (script.is_valid()) {
  1050. property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT;
  1051. property.hint_string = itos(script->get_instance_id());
  1052. }
  1053. }
  1054. }
  1055. } else if (call_mode == CALL_MODE_NODE_PATH) {
  1056. Node *node = _get_base_node();
  1057. if (node) {
  1058. property.hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE;
  1059. property.hint_string = itos(node->get_instance_id());
  1060. } else {
  1061. property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
  1062. property.hint_string = get_base_type();
  1063. }
  1064. }
  1065. }
  1066. if (property.name == "index") {
  1067. Variant::CallError ce;
  1068. Variant v = Variant::construct(type_cache.type, NULL, 0, ce);
  1069. List<PropertyInfo> plist;
  1070. v.get_property_list(&plist);
  1071. String options = "";
  1072. for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
  1073. options += "," + E->get().name;
  1074. }
  1075. property.hint = PROPERTY_HINT_ENUM;
  1076. property.hint_string = options;
  1077. property.type = Variant::STRING;
  1078. if (options == "")
  1079. property.usage = 0; //hide if type has no usable index
  1080. }
  1081. }
  1082. void VisualScriptPropertySet::_bind_methods() {
  1083. ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertySet::set_base_type);
  1084. ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertySet::get_base_type);
  1085. ClassDB::bind_method(D_METHOD("set_base_script", "base_script"), &VisualScriptPropertySet::set_base_script);
  1086. ClassDB::bind_method(D_METHOD("get_base_script"), &VisualScriptPropertySet::get_base_script);
  1087. ClassDB::bind_method(D_METHOD("set_basic_type", "basic_type"), &VisualScriptPropertySet::set_basic_type);
  1088. ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptPropertySet::get_basic_type);
  1089. ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertySet::_set_type_cache);
  1090. ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertySet::_get_type_cache);
  1091. ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertySet::set_property);
  1092. ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertySet::get_property);
  1093. ClassDB::bind_method(D_METHOD("set_call_mode", "mode"), &VisualScriptPropertySet::set_call_mode);
  1094. ClassDB::bind_method(D_METHOD("get_call_mode"), &VisualScriptPropertySet::get_call_mode);
  1095. ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &VisualScriptPropertySet::set_base_path);
  1096. ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptPropertySet::get_base_path);
  1097. ClassDB::bind_method(D_METHOD("set_index", "index"), &VisualScriptPropertySet::set_index);
  1098. ClassDB::bind_method(D_METHOD("get_index"), &VisualScriptPropertySet::get_index);
  1099. ClassDB::bind_method(D_METHOD("set_assign_op", "assign_op"), &VisualScriptPropertySet::set_assign_op);
  1100. ClassDB::bind_method(D_METHOD("get_assign_op"), &VisualScriptPropertySet::get_assign_op);
  1101. String bt;
  1102. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  1103. if (i > 0)
  1104. bt += ",";
  1105. bt += Variant::get_type_name(Variant::Type(i));
  1106. }
  1107. List<String> script_extensions;
  1108. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  1109. ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
  1110. }
  1111. String script_ext_hint;
  1112. for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
  1113. if (script_ext_hint != String())
  1114. script_ext_hint += ",";
  1115. script_ext_hint += "*." + E->get();
  1116. }
  1117. ADD_PROPERTY(PropertyInfo(Variant::INT, "set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode");
  1118. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type");
  1119. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script");
  1120. ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache");
  1121. ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
  1122. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
  1123. ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property");
  1124. ADD_PROPERTY(PropertyInfo(Variant::STRING, "index"), "set_index", "get_index");
  1125. ADD_PROPERTY(PropertyInfo(Variant::INT, "assign_op", PROPERTY_HINT_ENUM, "Assign,Add,Sub,Mul,Div,Mod,ShiftLeft,ShiftRight,BitAnd,BitOr,Bitxor"), "set_assign_op", "get_assign_op");
  1126. BIND_CONSTANT(CALL_MODE_SELF);
  1127. BIND_CONSTANT(CALL_MODE_NODE_PATH);
  1128. BIND_CONSTANT(CALL_MODE_INSTANCE);
  1129. }
  1130. class VisualScriptNodeInstancePropertySet : public VisualScriptNodeInstance {
  1131. public:
  1132. VisualScriptPropertySet::CallMode call_mode;
  1133. NodePath node_path;
  1134. StringName property;
  1135. VisualScriptPropertySet *node;
  1136. VisualScriptInstance *instance;
  1137. VisualScriptPropertySet::AssignOp assign_op;
  1138. StringName index;
  1139. bool needs_get;
  1140. //virtual int get_working_memory_size() const { return 0; }
  1141. //virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
  1142. //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
  1143. _FORCE_INLINE_ void _process_get(Variant &source, const Variant &p_argument, bool &valid) {
  1144. if (index != StringName() && assign_op == VisualScriptPropertySet::ASSIGN_OP_NONE) {
  1145. source.set_named(index, p_argument, &valid);
  1146. } else {
  1147. Variant value;
  1148. if (index != StringName()) {
  1149. value = source.get_named(index, &valid);
  1150. } else {
  1151. value = source;
  1152. }
  1153. switch (assign_op) {
  1154. case VisualScriptPropertySet::ASSIGN_OP_NONE: {
  1155. //should never get here
  1156. } break;
  1157. case VisualScriptPropertySet::ASSIGN_OP_ADD: {
  1158. value = Variant::evaluate(Variant::OP_ADD, value, p_argument);
  1159. } break;
  1160. case VisualScriptPropertySet::ASSIGN_OP_SUB: {
  1161. value = Variant::evaluate(Variant::OP_SUBSTRACT, value, p_argument);
  1162. } break;
  1163. case VisualScriptPropertySet::ASSIGN_OP_MUL: {
  1164. value = Variant::evaluate(Variant::OP_MULTIPLY, value, p_argument);
  1165. } break;
  1166. case VisualScriptPropertySet::ASSIGN_OP_DIV: {
  1167. value = Variant::evaluate(Variant::OP_DIVIDE, value, p_argument);
  1168. } break;
  1169. case VisualScriptPropertySet::ASSIGN_OP_MOD: {
  1170. value = Variant::evaluate(Variant::OP_MODULE, value, p_argument);
  1171. } break;
  1172. case VisualScriptPropertySet::ASSIGN_OP_SHIFT_LEFT: {
  1173. value = Variant::evaluate(Variant::OP_SHIFT_LEFT, value, p_argument);
  1174. } break;
  1175. case VisualScriptPropertySet::ASSIGN_OP_SHIFT_RIGHT: {
  1176. value = Variant::evaluate(Variant::OP_SHIFT_RIGHT, value, p_argument);
  1177. } break;
  1178. case VisualScriptPropertySet::ASSIGN_OP_BIT_AND: {
  1179. value = Variant::evaluate(Variant::OP_BIT_AND, value, p_argument);
  1180. } break;
  1181. case VisualScriptPropertySet::ASSIGN_OP_BIT_OR: {
  1182. value = Variant::evaluate(Variant::OP_BIT_OR, value, p_argument);
  1183. } break;
  1184. case VisualScriptPropertySet::ASSIGN_OP_BIT_XOR: {
  1185. value = Variant::evaluate(Variant::OP_BIT_XOR, value, p_argument);
  1186. } break;
  1187. default: {}
  1188. }
  1189. if (index != StringName()) {
  1190. source.set_named(index, value, &valid);
  1191. } else {
  1192. source = value;
  1193. }
  1194. }
  1195. }
  1196. 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) {
  1197. switch (call_mode) {
  1198. case VisualScriptPropertySet::CALL_MODE_SELF: {
  1199. Object *object = instance->get_owner_ptr();
  1200. bool valid;
  1201. if (needs_get) {
  1202. Variant value = object->get(property, &valid);
  1203. _process_get(value, *p_inputs[0], valid);
  1204. object->set(property, value, &valid);
  1205. } else {
  1206. object->set(property, *p_inputs[0], &valid);
  1207. }
  1208. if (!valid) {
  1209. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1210. r_error_str = "Invalid set value '" + String(*p_inputs[0]) + "' on property '" + String(property) + "' of type " + object->get_class();
  1211. }
  1212. } break;
  1213. case VisualScriptPropertySet::CALL_MODE_NODE_PATH: {
  1214. Node *node = instance->get_owner_ptr()->cast_to<Node>();
  1215. if (!node) {
  1216. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1217. r_error_str = "Base object is not a Node!";
  1218. return 0;
  1219. }
  1220. Node *another = node->get_node(node_path);
  1221. if (!node) {
  1222. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1223. r_error_str = "Path does not lead Node!";
  1224. return 0;
  1225. }
  1226. bool valid;
  1227. if (needs_get) {
  1228. Variant value = another->get(property, &valid);
  1229. _process_get(value, *p_inputs[0], valid);
  1230. another->set(property, value, &valid);
  1231. } else {
  1232. another->set(property, *p_inputs[0], &valid);
  1233. }
  1234. if (!valid) {
  1235. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1236. r_error_str = "Invalid set value '" + String(*p_inputs[0]) + "' on property '" + String(property) + "' of type " + another->get_class();
  1237. }
  1238. } break;
  1239. case VisualScriptPropertySet::CALL_MODE_INSTANCE:
  1240. case VisualScriptPropertySet::CALL_MODE_BASIC_TYPE: {
  1241. Variant v = *p_inputs[0];
  1242. bool valid;
  1243. if (needs_get) {
  1244. Variant value = v.get_named(property, &valid);
  1245. _process_get(value, *p_inputs[1], valid);
  1246. v.set_named(property, value, &valid);
  1247. } else {
  1248. v.set_named(property, *p_inputs[1], &valid);
  1249. }
  1250. if (!valid) {
  1251. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1252. 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());
  1253. }
  1254. *p_outputs[0] = v;
  1255. } break;
  1256. }
  1257. return 0;
  1258. }
  1259. };
  1260. VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance *p_instance) {
  1261. VisualScriptNodeInstancePropertySet *instance = memnew(VisualScriptNodeInstancePropertySet);
  1262. instance->node = this;
  1263. instance->instance = p_instance;
  1264. instance->property = property;
  1265. instance->call_mode = call_mode;
  1266. instance->node_path = base_path;
  1267. instance->assign_op = assign_op;
  1268. instance->index = index;
  1269. instance->needs_get = index != StringName() || assign_op != ASSIGN_OP_NONE;
  1270. return instance;
  1271. }
  1272. VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(TypeGuess *p_inputs, int p_output) const {
  1273. if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) {
  1274. return p_inputs[0];
  1275. }
  1276. return VisualScriptNode::guess_output_type(p_inputs, p_output);
  1277. }
  1278. VisualScriptPropertySet::VisualScriptPropertySet() {
  1279. assign_op = ASSIGN_OP_NONE;
  1280. call_mode = CALL_MODE_SELF;
  1281. base_type = "Object";
  1282. basic_type = Variant::NIL;
  1283. }
  1284. template <VisualScriptPropertySet::CallMode cmode>
  1285. static Ref<VisualScriptNode> create_property_set_node(const String &p_name) {
  1286. Ref<VisualScriptPropertySet> node;
  1287. node.instance();
  1288. node->set_call_mode(cmode);
  1289. return node;
  1290. }
  1291. //////////////////////////////////////////
  1292. ////////////////GET//////////////////////
  1293. //////////////////////////////////////////
  1294. int VisualScriptPropertyGet::get_output_sequence_port_count() const {
  1295. return 0; // (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1;
  1296. }
  1297. bool VisualScriptPropertyGet::has_input_sequence_port() const {
  1298. return false; //(call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true;
  1299. }
  1300. void VisualScriptPropertyGet::_update_base_type() {
  1301. //cache it because this information may not be available on load
  1302. if (call_mode == CALL_MODE_NODE_PATH) {
  1303. Node *node = _get_base_node();
  1304. if (node) {
  1305. base_type = node->get_class();
  1306. }
  1307. } else if (call_mode == CALL_MODE_SELF) {
  1308. if (get_visual_script().is_valid()) {
  1309. base_type = get_visual_script()->get_instance_base_type();
  1310. }
  1311. }
  1312. }
  1313. Node *VisualScriptPropertyGet::_get_base_node() const {
  1314. #ifdef TOOLS_ENABLED
  1315. Ref<Script> script = get_visual_script();
  1316. if (!script.is_valid())
  1317. return NULL;
  1318. MainLoop *main_loop = OS::get_singleton()->get_main_loop();
  1319. if (!main_loop)
  1320. return NULL;
  1321. SceneTree *scene_tree = main_loop->cast_to<SceneTree>();
  1322. if (!scene_tree)
  1323. return NULL;
  1324. Node *edited_scene = scene_tree->get_edited_scene_root();
  1325. if (!edited_scene)
  1326. return NULL;
  1327. Node *script_node = _find_script_node(edited_scene, edited_scene, script);
  1328. if (!script_node)
  1329. return NULL;
  1330. if (!script_node->has_node(base_path))
  1331. return NULL;
  1332. Node *path_to = script_node->get_node(base_path);
  1333. return path_to;
  1334. #else
  1335. return NULL;
  1336. #endif
  1337. }
  1338. StringName VisualScriptPropertyGet::_get_base_type() const {
  1339. if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
  1340. return get_visual_script()->get_instance_base_type();
  1341. else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
  1342. Node *path = _get_base_node();
  1343. if (path)
  1344. return path->get_class();
  1345. }
  1346. return base_type;
  1347. }
  1348. int VisualScriptPropertyGet::get_input_value_port_count() const {
  1349. return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0;
  1350. }
  1351. int VisualScriptPropertyGet::get_output_value_port_count() const {
  1352. return 1;
  1353. }
  1354. String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const {
  1355. return String();
  1356. }
  1357. PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const {
  1358. if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) {
  1359. if (p_idx == 0) {
  1360. PropertyInfo pi;
  1361. pi.type = (call_mode == CALL_MODE_INSTANCE ? Variant::OBJECT : basic_type);
  1362. pi.name = (call_mode == CALL_MODE_INSTANCE ? String("instance") : Variant::get_type_name(basic_type).to_lower());
  1363. return pi;
  1364. } else {
  1365. p_idx--;
  1366. }
  1367. }
  1368. return PropertyInfo();
  1369. }
  1370. PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const {
  1371. if (index != StringName()) {
  1372. Variant v;
  1373. Variant::CallError ce;
  1374. v = Variant::construct(type_cache, NULL, 0, ce);
  1375. Variant i = v.get(index);
  1376. return PropertyInfo(i.get_type(), "value." + String(index));
  1377. }
  1378. return PropertyInfo(type_cache, "value");
  1379. }
  1380. String VisualScriptPropertyGet::get_caption() const {
  1381. static const char *cname[4] = {
  1382. "SelfGet",
  1383. "NodeGet",
  1384. "InstanceGet",
  1385. "BasicGet"
  1386. };
  1387. return cname[call_mode];
  1388. }
  1389. String VisualScriptPropertyGet::get_text() const {
  1390. String prop;
  1391. if (call_mode == CALL_MODE_BASIC_TYPE)
  1392. prop = Variant::get_type_name(basic_type) + "." + property;
  1393. else if (call_mode == CALL_MODE_NODE_PATH)
  1394. prop = String(base_path) + ":" + property;
  1395. else if (call_mode == CALL_MODE_SELF)
  1396. prop = property;
  1397. else if (call_mode == CALL_MODE_INSTANCE)
  1398. prop = String(base_type) + ":" + property;
  1399. return prop;
  1400. }
  1401. void VisualScriptPropertyGet::set_base_type(const StringName &p_type) {
  1402. if (base_type == p_type)
  1403. return;
  1404. base_type = p_type;
  1405. _change_notify();
  1406. ports_changed_notify();
  1407. }
  1408. StringName VisualScriptPropertyGet::get_base_type() const {
  1409. return base_type;
  1410. }
  1411. void VisualScriptPropertyGet::set_base_script(const String &p_path) {
  1412. if (base_script == p_path)
  1413. return;
  1414. base_script = p_path;
  1415. _change_notify();
  1416. ports_changed_notify();
  1417. }
  1418. String VisualScriptPropertyGet::get_base_script() const {
  1419. return base_script;
  1420. }
  1421. void VisualScriptPropertyGet::_update_cache() {
  1422. if (call_mode == CALL_MODE_BASIC_TYPE) {
  1423. //not super efficient..
  1424. Variant v;
  1425. Variant::CallError ce;
  1426. v = Variant::construct(basic_type, NULL, 0, ce);
  1427. List<PropertyInfo> pinfo;
  1428. v.get_property_list(&pinfo);
  1429. for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
  1430. if (E->get().name == property) {
  1431. type_cache = E->get().type;
  1432. return;
  1433. }
  1434. }
  1435. } else {
  1436. StringName type;
  1437. Ref<Script> script;
  1438. Node *node = NULL;
  1439. if (call_mode == CALL_MODE_NODE_PATH) {
  1440. node = _get_base_node();
  1441. if (node) {
  1442. type = node->get_class();
  1443. base_type = type; //cache, too
  1444. script = node->get_script();
  1445. }
  1446. } else if (call_mode == CALL_MODE_SELF) {
  1447. if (get_visual_script().is_valid()) {
  1448. type = get_visual_script()->get_instance_base_type();
  1449. base_type = type; //cache, too
  1450. script = get_visual_script();
  1451. }
  1452. } else if (call_mode == CALL_MODE_INSTANCE) {
  1453. type = base_type;
  1454. if (base_script != String()) {
  1455. if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
  1456. ScriptServer::edit_request_func(base_script); //make sure it's loaded
  1457. }
  1458. if (ResourceCache::has(base_script)) {
  1459. script = Ref<Resource>(ResourceCache::get(base_script));
  1460. } else {
  1461. return;
  1462. }
  1463. }
  1464. }
  1465. bool valid = false;
  1466. Variant::Type type_ret;
  1467. type_ret = ClassDB::get_property_type(base_type, property, &valid);
  1468. if (valid) {
  1469. type_cache = type_ret;
  1470. return; //all dandy
  1471. }
  1472. if (node) {
  1473. Variant prop = node->get(property, &valid);
  1474. if (valid) {
  1475. type_cache = prop.get_type();
  1476. return; //all dandy again
  1477. }
  1478. }
  1479. if (script.is_valid()) {
  1480. type_ret = script->get_static_property_type(property, &valid);
  1481. if (valid) {
  1482. type_cache = type_ret;
  1483. return; //all dandy
  1484. }
  1485. }
  1486. }
  1487. }
  1488. void VisualScriptPropertyGet::set_property(const StringName &p_type) {
  1489. if (property == p_type)
  1490. return;
  1491. property = p_type;
  1492. _update_cache();
  1493. _change_notify();
  1494. ports_changed_notify();
  1495. }
  1496. StringName VisualScriptPropertyGet::get_property() const {
  1497. return property;
  1498. }
  1499. void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) {
  1500. if (base_path == p_type)
  1501. return;
  1502. base_path = p_type;
  1503. _change_notify();
  1504. _update_base_type();
  1505. ports_changed_notify();
  1506. }
  1507. NodePath VisualScriptPropertyGet::get_base_path() const {
  1508. return base_path;
  1509. }
  1510. void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) {
  1511. if (call_mode == p_mode)
  1512. return;
  1513. call_mode = p_mode;
  1514. _change_notify();
  1515. _update_base_type();
  1516. ports_changed_notify();
  1517. }
  1518. VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const {
  1519. return call_mode;
  1520. }
  1521. void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) {
  1522. if (basic_type == p_type)
  1523. return;
  1524. basic_type = p_type;
  1525. _change_notify();
  1526. ports_changed_notify();
  1527. }
  1528. Variant::Type VisualScriptPropertyGet::get_basic_type() const {
  1529. return basic_type;
  1530. }
  1531. void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) {
  1532. type_cache = p_type;
  1533. }
  1534. Variant::Type VisualScriptPropertyGet::_get_type_cache() const {
  1535. return type_cache;
  1536. }
  1537. void VisualScriptPropertyGet::set_index(const StringName &p_type) {
  1538. if (index == p_type)
  1539. return;
  1540. index = p_type;
  1541. _update_cache();
  1542. _change_notify();
  1543. ports_changed_notify();
  1544. }
  1545. StringName VisualScriptPropertyGet::get_index() const {
  1546. return index;
  1547. }
  1548. void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
  1549. if (property.name == "base_type") {
  1550. if (call_mode != CALL_MODE_INSTANCE) {
  1551. property.usage = PROPERTY_USAGE_NOEDITOR;
  1552. }
  1553. }
  1554. if (property.name == "base_script") {
  1555. if (call_mode != CALL_MODE_INSTANCE) {
  1556. property.usage = 0;
  1557. }
  1558. }
  1559. if (property.name == "basic_type") {
  1560. if (call_mode != CALL_MODE_BASIC_TYPE) {
  1561. property.usage = 0;
  1562. }
  1563. }
  1564. if (property.name == "node_path") {
  1565. if (call_mode != CALL_MODE_NODE_PATH) {
  1566. property.usage = 0;
  1567. } else {
  1568. Node *bnode = _get_base_node();
  1569. if (bnode) {
  1570. property.hint_string = bnode->get_path(); //convert to loong string
  1571. } else {
  1572. }
  1573. }
  1574. }
  1575. if (property.name == "property") {
  1576. if (call_mode == CALL_MODE_BASIC_TYPE) {
  1577. property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE;
  1578. property.hint_string = Variant::get_type_name(basic_type);
  1579. } else if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) {
  1580. property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT;
  1581. property.hint_string = itos(get_visual_script()->get_instance_id());
  1582. } else if (call_mode == CALL_MODE_INSTANCE) {
  1583. property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
  1584. property.hint_string = base_type;
  1585. if (base_script != String()) {
  1586. if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) {
  1587. ScriptServer::edit_request_func(base_script); //make sure it's loaded
  1588. }
  1589. if (ResourceCache::has(base_script)) {
  1590. Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script));
  1591. if (script.is_valid()) {
  1592. property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT;
  1593. property.hint_string = itos(script->get_instance_id());
  1594. }
  1595. }
  1596. }
  1597. } else if (call_mode == CALL_MODE_NODE_PATH) {
  1598. Node *node = _get_base_node();
  1599. if (node) {
  1600. property.hint = PROPERTY_HINT_PROPERTY_OF_INSTANCE;
  1601. property.hint_string = itos(node->get_instance_id());
  1602. } else {
  1603. property.hint = PROPERTY_HINT_PROPERTY_OF_BASE_TYPE;
  1604. property.hint_string = get_base_type();
  1605. }
  1606. }
  1607. }
  1608. if (property.name == "index") {
  1609. Variant::CallError ce;
  1610. Variant v = Variant::construct(type_cache, NULL, 0, ce);
  1611. List<PropertyInfo> plist;
  1612. v.get_property_list(&plist);
  1613. String options = "";
  1614. for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
  1615. options += "," + E->get().name;
  1616. }
  1617. property.hint = PROPERTY_HINT_ENUM;
  1618. property.hint_string = options;
  1619. property.type = Variant::STRING;
  1620. if (options == "")
  1621. property.usage = 0; //hide if type has no usable index
  1622. }
  1623. }
  1624. void VisualScriptPropertyGet::_bind_methods() {
  1625. ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertyGet::set_base_type);
  1626. ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertyGet::get_base_type);
  1627. ClassDB::bind_method(D_METHOD("set_base_script", "base_script"), &VisualScriptPropertyGet::set_base_script);
  1628. ClassDB::bind_method(D_METHOD("get_base_script"), &VisualScriptPropertyGet::get_base_script);
  1629. ClassDB::bind_method(D_METHOD("set_basic_type", "basic_type"), &VisualScriptPropertyGet::set_basic_type);
  1630. ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptPropertyGet::get_basic_type);
  1631. ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertyGet::_set_type_cache);
  1632. ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertyGet::_get_type_cache);
  1633. ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertyGet::set_property);
  1634. ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertyGet::get_property);
  1635. ClassDB::bind_method(D_METHOD("set_call_mode", "mode"), &VisualScriptPropertyGet::set_call_mode);
  1636. ClassDB::bind_method(D_METHOD("get_call_mode"), &VisualScriptPropertyGet::get_call_mode);
  1637. ClassDB::bind_method(D_METHOD("set_base_path", "base_path"), &VisualScriptPropertyGet::set_base_path);
  1638. ClassDB::bind_method(D_METHOD("get_base_path"), &VisualScriptPropertyGet::get_base_path);
  1639. ClassDB::bind_method(D_METHOD("set_index", "index"), &VisualScriptPropertyGet::set_index);
  1640. ClassDB::bind_method(D_METHOD("get_index"), &VisualScriptPropertyGet::get_index);
  1641. String bt;
  1642. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  1643. if (i > 0)
  1644. bt += ",";
  1645. bt += Variant::get_type_name(Variant::Type(i));
  1646. }
  1647. List<String> script_extensions;
  1648. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  1649. ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
  1650. }
  1651. String script_ext_hint;
  1652. for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
  1653. if (script_ext_hint != String())
  1654. script_ext_hint += ",";
  1655. script_ext_hint += "." + E->get();
  1656. }
  1657. ADD_PROPERTY(PropertyInfo(Variant::INT, "set_mode", PROPERTY_HINT_ENUM, "Self,Node Path,Instance,Basic Type"), "set_call_mode", "get_call_mode");
  1658. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type");
  1659. ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script");
  1660. ADD_PROPERTY(PropertyInfo(Variant::INT, "type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache");
  1661. ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
  1662. ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
  1663. ADD_PROPERTY(PropertyInfo(Variant::STRING, "property"), "set_property", "get_property");
  1664. ADD_PROPERTY(PropertyInfo(Variant::STRING, "index", PROPERTY_HINT_ENUM), "set_index", "get_index");
  1665. BIND_CONSTANT(CALL_MODE_SELF);
  1666. BIND_CONSTANT(CALL_MODE_NODE_PATH);
  1667. BIND_CONSTANT(CALL_MODE_INSTANCE);
  1668. }
  1669. class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance {
  1670. public:
  1671. VisualScriptPropertyGet::CallMode call_mode;
  1672. NodePath node_path;
  1673. StringName property;
  1674. StringName index;
  1675. VisualScriptPropertyGet *node;
  1676. VisualScriptInstance *instance;
  1677. 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) {
  1678. switch (call_mode) {
  1679. case VisualScriptPropertyGet::CALL_MODE_SELF: {
  1680. Object *object = instance->get_owner_ptr();
  1681. bool valid;
  1682. *p_outputs[0] = object->get(property, &valid);
  1683. if (index != StringName()) {
  1684. *p_outputs[0] = p_outputs[0]->get_named(index);
  1685. }
  1686. if (!valid) {
  1687. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1688. r_error_str = RTR("Invalid index property name.");
  1689. return 0;
  1690. }
  1691. } break;
  1692. case VisualScriptPropertyGet::CALL_MODE_NODE_PATH: {
  1693. Node *node = instance->get_owner_ptr()->cast_to<Node>();
  1694. if (!node) {
  1695. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1696. r_error_str = RTR("Base object is not a Node!");
  1697. return 0;
  1698. }
  1699. Node *another = node->get_node(node_path);
  1700. if (!node) {
  1701. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1702. r_error_str = RTR("Path does not lead Node!");
  1703. return 0;
  1704. }
  1705. bool valid;
  1706. *p_outputs[0] = another->get(property, &valid);
  1707. if (index != StringName()) {
  1708. *p_outputs[0] = p_outputs[0]->get_named(index);
  1709. }
  1710. if (!valid) {
  1711. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1712. r_error_str = vformat(RTR("Invalid index property name '%s' in node %s."), String(property), another->get_name());
  1713. return 0;
  1714. }
  1715. } break;
  1716. default: {
  1717. bool valid;
  1718. Variant v = *p_inputs[0];
  1719. *p_outputs[0] = v.get(property, &valid);
  1720. if (index != StringName()) {
  1721. *p_outputs[0] = p_outputs[0]->get_named(index);
  1722. }
  1723. if (!valid) {
  1724. r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
  1725. r_error_str = RTR("Invalid index property name.");
  1726. }
  1727. };
  1728. }
  1729. return 0;
  1730. }
  1731. };
  1732. VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance *p_instance) {
  1733. VisualScriptNodeInstancePropertyGet *instance = memnew(VisualScriptNodeInstancePropertyGet);
  1734. instance->node = this;
  1735. instance->instance = p_instance;
  1736. instance->property = property;
  1737. instance->call_mode = call_mode;
  1738. instance->node_path = base_path;
  1739. instance->index = index;
  1740. return instance;
  1741. }
  1742. VisualScriptPropertyGet::VisualScriptPropertyGet() {
  1743. call_mode = CALL_MODE_SELF;
  1744. base_type = "Object";
  1745. basic_type = Variant::NIL;
  1746. type_cache = Variant::NIL;
  1747. }
  1748. template <VisualScriptPropertyGet::CallMode cmode>
  1749. static Ref<VisualScriptNode> create_property_get_node(const String &p_name) {
  1750. Ref<VisualScriptPropertyGet> node;
  1751. node.instance();
  1752. node->set_call_mode(cmode);
  1753. return node;
  1754. }
  1755. //////////////////////////////////////////
  1756. ////////////////EMIT//////////////////////
  1757. //////////////////////////////////////////
  1758. int VisualScriptEmitSignal::get_output_sequence_port_count() const {
  1759. return 1;
  1760. }
  1761. bool VisualScriptEmitSignal::has_input_sequence_port() const {
  1762. return true;
  1763. }
  1764. int VisualScriptEmitSignal::get_input_value_port_count() const {
  1765. Ref<VisualScript> vs = get_visual_script();
  1766. if (vs.is_valid()) {
  1767. if (!vs->has_custom_signal(name))
  1768. return 0;
  1769. return vs->custom_signal_get_argument_count(name);
  1770. }
  1771. return 0;
  1772. }
  1773. int VisualScriptEmitSignal::get_output_value_port_count() const {
  1774. return 0;
  1775. }
  1776. String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const {
  1777. return String();
  1778. }
  1779. PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const {
  1780. Ref<VisualScript> vs = get_visual_script();
  1781. if (vs.is_valid()) {
  1782. if (!vs->has_custom_signal(name))
  1783. return PropertyInfo();
  1784. return PropertyInfo(vs->custom_signal_get_argument_type(name, p_idx), vs->custom_signal_get_argument_name(name, p_idx));
  1785. }
  1786. return PropertyInfo();
  1787. }
  1788. PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const {
  1789. return PropertyInfo();
  1790. }
  1791. String VisualScriptEmitSignal::get_caption() const {
  1792. return "EmitSignal";
  1793. }
  1794. String VisualScriptEmitSignal::get_text() const {
  1795. return "emit " + String(name);
  1796. }
  1797. void VisualScriptEmitSignal::set_signal(const StringName &p_type) {
  1798. if (name == p_type)
  1799. return;
  1800. name = p_type;
  1801. _change_notify();
  1802. ports_changed_notify();
  1803. }
  1804. StringName VisualScriptEmitSignal::get_signal() const {
  1805. return name;
  1806. }
  1807. void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const {
  1808. if (property.name == "signal") {
  1809. property.hint = PROPERTY_HINT_ENUM;
  1810. List<StringName> sigs;
  1811. Ref<VisualScript> vs = get_visual_script();
  1812. if (vs.is_valid()) {
  1813. vs->get_custom_signal_list(&sigs);
  1814. }
  1815. String ml;
  1816. for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) {
  1817. if (ml != String())
  1818. ml += ",";
  1819. ml += E->get();
  1820. }
  1821. property.hint_string = ml;
  1822. }
  1823. }
  1824. void VisualScriptEmitSignal::_bind_methods() {
  1825. ClassDB::bind_method(D_METHOD("set_signal", "name"), &VisualScriptEmitSignal::set_signal);
  1826. ClassDB::bind_method(D_METHOD("get_signal"), &VisualScriptEmitSignal::get_signal);
  1827. ADD_PROPERTY(PropertyInfo(Variant::STRING, "signal"), "set_signal", "get_signal");
  1828. }
  1829. class VisualScriptNodeInstanceEmitSignal : public VisualScriptNodeInstance {
  1830. public:
  1831. VisualScriptEmitSignal *node;
  1832. VisualScriptInstance *instance;
  1833. int argcount;
  1834. StringName name;
  1835. //virtual int get_working_memory_size() const { return 0; }
  1836. //virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
  1837. //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
  1838. 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) {
  1839. Object *obj = instance->get_owner_ptr();
  1840. obj->emit_signal(name, p_inputs, argcount);
  1841. return 0;
  1842. }
  1843. };
  1844. VisualScriptNodeInstance *VisualScriptEmitSignal::instance(VisualScriptInstance *p_instance) {
  1845. VisualScriptNodeInstanceEmitSignal *instance = memnew(VisualScriptNodeInstanceEmitSignal);
  1846. instance->node = this;
  1847. instance->instance = p_instance;
  1848. instance->name = name;
  1849. instance->argcount = get_input_value_port_count();
  1850. return instance;
  1851. }
  1852. VisualScriptEmitSignal::VisualScriptEmitSignal() {
  1853. }
  1854. static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) {
  1855. Vector<String> path = p_name.split("/");
  1856. ERR_FAIL_COND_V(path.size() < 4, Ref<VisualScriptNode>());
  1857. String base_type = path[2];
  1858. String method = path[3];
  1859. Ref<VisualScriptFunctionCall> node;
  1860. node.instance();
  1861. Variant::Type type = Variant::VARIANT_MAX;
  1862. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  1863. if (Variant::get_type_name(Variant::Type(i)) == base_type) {
  1864. type = Variant::Type(i);
  1865. break;
  1866. }
  1867. }
  1868. ERR_FAIL_COND_V(type == Variant::VARIANT_MAX, Ref<VisualScriptNode>());
  1869. node->set_call_mode(VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE);
  1870. node->set_basic_type(type);
  1871. node->set_function(method);
  1872. return node;
  1873. }
  1874. void register_visual_script_func_nodes() {
  1875. VisualScriptLanguage::singleton->add_register_func("functions/call", create_node_generic<VisualScriptFunctionCall>);
  1876. VisualScriptLanguage::singleton->add_register_func("functions/set", create_node_generic<VisualScriptPropertySet>);
  1877. VisualScriptLanguage::singleton->add_register_func("functions/get", create_node_generic<VisualScriptPropertyGet>);
  1878. //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>);
  1879. //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>);
  1880. VisualScriptLanguage::singleton->add_register_func("functions/emit_signal", create_node_generic<VisualScriptEmitSignal>);
  1881. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  1882. Variant::Type t = Variant::Type(i);
  1883. String type_name = Variant::get_type_name(t);
  1884. Variant::CallError ce;
  1885. Variant vt = Variant::construct(t, NULL, 0, ce);
  1886. List<MethodInfo> ml;
  1887. vt.get_method_list(&ml);
  1888. for (List<MethodInfo>::Element *E = ml.front(); E; E = E->next()) {
  1889. VisualScriptLanguage::singleton->add_register_func("functions/by_type/" + type_name + "/" + E->get().name, create_basic_type_call_node);
  1890. }
  1891. }
  1892. }