visual_script_func_nodes.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /**************************************************************************/
  2. /* visual_script_func_nodes.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #ifndef VISUAL_SCRIPT_FUNC_NODES_H
  31. #define VISUAL_SCRIPT_FUNC_NODES_H
  32. #include "visual_script.h"
  33. class VisualScriptFunctionCall : public VisualScriptNode {
  34. GDCLASS(VisualScriptFunctionCall, VisualScriptNode);
  35. public:
  36. enum CallMode {
  37. CALL_MODE_SELF,
  38. CALL_MODE_NODE_PATH,
  39. CALL_MODE_INSTANCE,
  40. CALL_MODE_BASIC_TYPE,
  41. CALL_MODE_SINGLETON,
  42. };
  43. enum RPCCallMode {
  44. RPC_DISABLED,
  45. RPC_RELIABLE,
  46. RPC_UNRELIABLE,
  47. RPC_RELIABLE_TO_ID,
  48. RPC_UNRELIABLE_TO_ID
  49. };
  50. private:
  51. CallMode call_mode;
  52. StringName base_type;
  53. String base_script;
  54. Variant::Type basic_type;
  55. NodePath base_path;
  56. StringName function;
  57. int use_default_args;
  58. RPCCallMode rpc_call_mode;
  59. StringName singleton;
  60. bool validate;
  61. Node *_get_base_node() const;
  62. StringName _get_base_type() const;
  63. MethodInfo method_cache;
  64. void _update_method_cache();
  65. void _set_argument_cache(const Dictionary &p_cache);
  66. Dictionary _get_argument_cache() const;
  67. protected:
  68. virtual void _validate_property(PropertyInfo &property) const;
  69. static void _bind_methods();
  70. public:
  71. virtual int get_output_sequence_port_count() const;
  72. virtual bool has_input_sequence_port() const;
  73. virtual String get_output_sequence_port_text(int p_port) const;
  74. virtual int get_input_value_port_count() const;
  75. virtual int get_output_value_port_count() const;
  76. virtual PropertyInfo get_input_value_port_info(int p_idx) const;
  77. virtual PropertyInfo get_output_value_port_info(int p_idx) const;
  78. virtual String get_caption() const;
  79. virtual String get_text() const;
  80. virtual String get_category() const { return "functions"; }
  81. void set_basic_type(Variant::Type p_type);
  82. Variant::Type get_basic_type() const;
  83. void set_base_type(const StringName &p_type);
  84. StringName get_base_type() const;
  85. void set_base_script(const String &p_path);
  86. String get_base_script() const;
  87. void set_singleton(const StringName &p_type);
  88. StringName get_singleton() const;
  89. void set_function(const StringName &p_type);
  90. StringName get_function() const;
  91. void set_base_path(const NodePath &p_type);
  92. NodePath get_base_path() const;
  93. void set_call_mode(CallMode p_mode);
  94. CallMode get_call_mode() const;
  95. void set_use_default_args(int p_amount);
  96. int get_use_default_args() const;
  97. void set_validate(bool p_amount);
  98. bool get_validate() const;
  99. void set_rpc_call_mode(RPCCallMode p_mode);
  100. RPCCallMode get_rpc_call_mode() const;
  101. virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
  102. virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
  103. VisualScriptFunctionCall();
  104. };
  105. VARIANT_ENUM_CAST(VisualScriptFunctionCall::CallMode);
  106. VARIANT_ENUM_CAST(VisualScriptFunctionCall::RPCCallMode);
  107. class VisualScriptPropertySet : public VisualScriptNode {
  108. GDCLASS(VisualScriptPropertySet, VisualScriptNode);
  109. public:
  110. enum CallMode {
  111. CALL_MODE_SELF,
  112. CALL_MODE_NODE_PATH,
  113. CALL_MODE_INSTANCE,
  114. CALL_MODE_BASIC_TYPE,
  115. };
  116. enum AssignOp {
  117. ASSIGN_OP_NONE,
  118. ASSIGN_OP_ADD,
  119. ASSIGN_OP_SUB,
  120. ASSIGN_OP_MUL,
  121. ASSIGN_OP_DIV,
  122. ASSIGN_OP_MOD,
  123. ASSIGN_OP_SHIFT_LEFT,
  124. ASSIGN_OP_SHIFT_RIGHT,
  125. ASSIGN_OP_BIT_AND,
  126. ASSIGN_OP_BIT_OR,
  127. ASSIGN_OP_BIT_XOR,
  128. ASSIGN_OP_MAX
  129. };
  130. private:
  131. PropertyInfo type_cache;
  132. CallMode call_mode;
  133. Variant::Type basic_type;
  134. StringName base_type;
  135. String base_script;
  136. NodePath base_path;
  137. StringName property;
  138. StringName index;
  139. AssignOp assign_op;
  140. Node *_get_base_node() const;
  141. StringName _get_base_type() const;
  142. void _update_base_type();
  143. void _update_cache();
  144. void _set_type_cache(const Dictionary &p_type);
  145. Dictionary _get_type_cache() const;
  146. void _adjust_input_index(PropertyInfo &pinfo) const;
  147. protected:
  148. virtual void _validate_property(PropertyInfo &property) const;
  149. static void _bind_methods();
  150. public:
  151. virtual int get_output_sequence_port_count() const;
  152. virtual bool has_input_sequence_port() const;
  153. virtual String get_output_sequence_port_text(int p_port) const;
  154. virtual int get_input_value_port_count() const;
  155. virtual int get_output_value_port_count() const;
  156. virtual PropertyInfo get_input_value_port_info(int p_idx) const;
  157. virtual PropertyInfo get_output_value_port_info(int p_idx) const;
  158. virtual String get_caption() const;
  159. virtual String get_text() const;
  160. virtual String get_category() const { return "functions"; }
  161. void set_base_type(const StringName &p_type);
  162. StringName get_base_type() const;
  163. void set_base_script(const String &p_path);
  164. String get_base_script() const;
  165. void set_basic_type(Variant::Type p_type);
  166. Variant::Type get_basic_type() const;
  167. void set_property(const StringName &p_type);
  168. StringName get_property() const;
  169. void set_base_path(const NodePath &p_type);
  170. NodePath get_base_path() const;
  171. void set_call_mode(CallMode p_mode);
  172. CallMode get_call_mode() const;
  173. void set_index(const StringName &p_type);
  174. StringName get_index() const;
  175. void set_assign_op(AssignOp p_op);
  176. AssignOp get_assign_op() const;
  177. virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
  178. virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const;
  179. VisualScriptPropertySet();
  180. };
  181. VARIANT_ENUM_CAST(VisualScriptPropertySet::CallMode);
  182. VARIANT_ENUM_CAST(VisualScriptPropertySet::AssignOp);
  183. class VisualScriptPropertyGet : public VisualScriptNode {
  184. GDCLASS(VisualScriptPropertyGet, VisualScriptNode);
  185. public:
  186. enum CallMode {
  187. CALL_MODE_SELF,
  188. CALL_MODE_NODE_PATH,
  189. CALL_MODE_INSTANCE,
  190. CALL_MODE_BASIC_TYPE,
  191. };
  192. private:
  193. Variant::Type type_cache;
  194. CallMode call_mode;
  195. Variant::Type basic_type;
  196. StringName base_type;
  197. String base_script;
  198. NodePath base_path;
  199. StringName property;
  200. StringName index;
  201. void _update_base_type();
  202. Node *_get_base_node() const;
  203. StringName _get_base_type() const;
  204. void _update_cache();
  205. void _set_type_cache(Variant::Type p_type);
  206. Variant::Type _get_type_cache() const;
  207. void _adjust_input_index(PropertyInfo &pinfo) const;
  208. protected:
  209. virtual void _validate_property(PropertyInfo &property) const;
  210. static void _bind_methods();
  211. public:
  212. virtual int get_output_sequence_port_count() const;
  213. virtual bool has_input_sequence_port() const;
  214. virtual String get_output_sequence_port_text(int p_port) const;
  215. virtual int get_input_value_port_count() const;
  216. virtual int get_output_value_port_count() const;
  217. virtual PropertyInfo get_input_value_port_info(int p_idx) const;
  218. virtual PropertyInfo get_output_value_port_info(int p_idx) const;
  219. virtual String get_caption() const;
  220. virtual String get_text() const;
  221. virtual String get_category() const { return "functions"; }
  222. void set_base_type(const StringName &p_type);
  223. StringName get_base_type() const;
  224. void set_base_script(const String &p_path);
  225. String get_base_script() const;
  226. void set_basic_type(Variant::Type p_type);
  227. Variant::Type get_basic_type() const;
  228. void set_property(const StringName &p_type);
  229. StringName get_property() const;
  230. void set_base_path(const NodePath &p_type);
  231. NodePath get_base_path() const;
  232. void set_call_mode(CallMode p_mode);
  233. CallMode get_call_mode() const;
  234. void set_index(const StringName &p_type);
  235. StringName get_index() const;
  236. virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
  237. VisualScriptPropertyGet();
  238. };
  239. VARIANT_ENUM_CAST(VisualScriptPropertyGet::CallMode);
  240. class VisualScriptEmitSignal : public VisualScriptNode {
  241. GDCLASS(VisualScriptEmitSignal, VisualScriptNode);
  242. private:
  243. StringName name;
  244. protected:
  245. virtual void _validate_property(PropertyInfo &property) const;
  246. static void _bind_methods();
  247. public:
  248. virtual int get_output_sequence_port_count() const;
  249. virtual bool has_input_sequence_port() const;
  250. virtual String get_output_sequence_port_text(int p_port) const;
  251. virtual int get_input_value_port_count() const;
  252. virtual int get_output_value_port_count() const;
  253. virtual PropertyInfo get_input_value_port_info(int p_idx) const;
  254. virtual PropertyInfo get_output_value_port_info(int p_idx) const;
  255. virtual String get_caption() const;
  256. //virtual String get_text() const;
  257. virtual String get_category() const { return "functions"; }
  258. void set_signal(const StringName &p_type);
  259. StringName get_signal() const;
  260. virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
  261. VisualScriptEmitSignal();
  262. };
  263. void register_visual_script_func_nodes();
  264. #endif // VISUAL_SCRIPT_FUNC_NODES_H