visual_script_func_nodes.cpp 69 KB

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