1 /** 2 A script implemented in the Visual Script programming environment. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.visualscript; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.script; 25 import godot.resource; 26 import godot.reference; 27 import godot.visualscriptnode; 28 /** 29 A script implemented in the Visual Script programming environment. 30 31 A script implemented in the Visual Script programming environment. The script extends the functionality of all objects that instance it. 32 $(D GodotObject.setScript) extends an existing object, if that object's class matches one of the script's base classes. 33 You are most likely to use this class via the Visual Script editor or when writing plugins for it. 34 */ 35 @GodotBaseClass struct VisualScript 36 { 37 package(godot) enum string _GODOT_internal_name = "VisualScript"; 38 public: 39 @nogc nothrow: 40 union { /** */ godot_object _godot_object; /** */ Script _GODOT_base; } 41 alias _GODOT_base this; 42 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 43 package(godot) __gshared bool _classBindingInitialized = false; 44 package(godot) static struct GDNativeClassBinding 45 { 46 __gshared: 47 @GodotName("_get_data") GodotMethod!(Dictionary) _getData; 48 @GodotName("_node_ports_changed") GodotMethod!(void, long) _nodePortsChanged; 49 @GodotName("_set_data") GodotMethod!(void, Dictionary) _setData; 50 @GodotName("add_custom_signal") GodotMethod!(void, String) addCustomSignal; 51 @GodotName("add_function") GodotMethod!(void, String) addFunction; 52 @GodotName("add_node") GodotMethod!(void, String, long, VisualScriptNode, Vector2) addNode; 53 @GodotName("add_variable") GodotMethod!(void, String, Variant, bool) addVariable; 54 @GodotName("custom_signal_add_argument") GodotMethod!(void, String, long, String, long) customSignalAddArgument; 55 @GodotName("custom_signal_get_argument_count") GodotMethod!(long, String) customSignalGetArgumentCount; 56 @GodotName("custom_signal_get_argument_name") GodotMethod!(String, String, long) customSignalGetArgumentName; 57 @GodotName("custom_signal_get_argument_type") GodotMethod!(Variant.Type, String, long) customSignalGetArgumentType; 58 @GodotName("custom_signal_remove_argument") GodotMethod!(void, String, long) customSignalRemoveArgument; 59 @GodotName("custom_signal_set_argument_name") GodotMethod!(void, String, long, String) customSignalSetArgumentName; 60 @GodotName("custom_signal_set_argument_type") GodotMethod!(void, String, long, long) customSignalSetArgumentType; 61 @GodotName("custom_signal_swap_argument") GodotMethod!(void, String, long, long) customSignalSwapArgument; 62 @GodotName("data_connect") GodotMethod!(void, String, long, long, long, long) dataConnect; 63 @GodotName("data_disconnect") GodotMethod!(void, String, long, long, long, long) dataDisconnect; 64 @GodotName("get_function_node_id") GodotMethod!(long, String) getFunctionNodeId; 65 @GodotName("get_function_scroll") GodotMethod!(Vector2, String) getFunctionScroll; 66 @GodotName("get_node") GodotMethod!(VisualScriptNode, String, long) getNode; 67 @GodotName("get_node_position") GodotMethod!(Vector2, String, long) getNodePosition; 68 @GodotName("get_variable_default_value") GodotMethod!(Variant, String) getVariableDefaultValue; 69 @GodotName("get_variable_export") GodotMethod!(bool, String) getVariableExport; 70 @GodotName("get_variable_info") GodotMethod!(Dictionary, String) getVariableInfo; 71 @GodotName("has_custom_signal") GodotMethod!(bool, String) hasCustomSignal; 72 @GodotName("has_data_connection") GodotMethod!(bool, String, long, long, long, long) hasDataConnection; 73 @GodotName("has_function") GodotMethod!(bool, String) hasFunction; 74 @GodotName("has_node") GodotMethod!(bool, String, long) hasNode; 75 @GodotName("has_sequence_connection") GodotMethod!(bool, String, long, long, long) hasSequenceConnection; 76 @GodotName("has_variable") GodotMethod!(bool, String) hasVariable; 77 @GodotName("remove_custom_signal") GodotMethod!(void, String) removeCustomSignal; 78 @GodotName("remove_function") GodotMethod!(void, String) removeFunction; 79 @GodotName("remove_node") GodotMethod!(void, String, long) removeNode; 80 @GodotName("remove_variable") GodotMethod!(void, String) removeVariable; 81 @GodotName("rename_custom_signal") GodotMethod!(void, String, String) renameCustomSignal; 82 @GodotName("rename_function") GodotMethod!(void, String, String) renameFunction; 83 @GodotName("rename_variable") GodotMethod!(void, String, String) renameVariable; 84 @GodotName("sequence_connect") GodotMethod!(void, String, long, long, long) sequenceConnect; 85 @GodotName("sequence_disconnect") GodotMethod!(void, String, long, long, long) sequenceDisconnect; 86 @GodotName("set_function_scroll") GodotMethod!(void, String, Vector2) setFunctionScroll; 87 @GodotName("set_instance_base_type") GodotMethod!(void, String) setInstanceBaseType; 88 @GodotName("set_node_position") GodotMethod!(void, String, long, Vector2) setNodePosition; 89 @GodotName("set_variable_default_value") GodotMethod!(void, String, Variant) setVariableDefaultValue; 90 @GodotName("set_variable_export") GodotMethod!(void, String, bool) setVariableExport; 91 @GodotName("set_variable_info") GodotMethod!(void, String, Dictionary) setVariableInfo; 92 } 93 /// 94 pragma(inline, true) bool opEquals(in VisualScript other) const 95 { return _godot_object.ptr is other._godot_object.ptr; } 96 /// 97 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 98 { _godot_object.ptr = n; return null; } 99 /// 100 pragma(inline, true) bool opEquals(typeof(null) n) const 101 { return _godot_object.ptr is n; } 102 /// 103 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 104 mixin baseCasts; 105 /// Construct a new instance of VisualScript. 106 /// Note: use `memnew!VisualScript` instead. 107 static VisualScript _new() 108 { 109 static godot_class_constructor constructor; 110 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisualScript"); 111 if(constructor is null) return typeof(this).init; 112 return cast(VisualScript)(constructor()); 113 } 114 @disable new(size_t s); 115 /** 116 117 */ 118 Dictionary _getData() const 119 { 120 Array _GODOT_args = Array.make(); 121 String _GODOT_method_name = String("_get_data"); 122 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary); 123 } 124 /** 125 126 */ 127 void _nodePortsChanged(in long arg0) 128 { 129 Array _GODOT_args = Array.make(); 130 _GODOT_args.append(arg0); 131 String _GODOT_method_name = String("_node_ports_changed"); 132 this.callv(_GODOT_method_name, _GODOT_args); 133 } 134 /** 135 136 */ 137 void _setData(in Dictionary data) 138 { 139 Array _GODOT_args = Array.make(); 140 _GODOT_args.append(data); 141 String _GODOT_method_name = String("_set_data"); 142 this.callv(_GODOT_method_name, _GODOT_args); 143 } 144 /** 145 Add a custom signal with the specified name to the VisualScript. 146 */ 147 void addCustomSignal(in String name) 148 { 149 checkClassBinding!(typeof(this))(); 150 ptrcall!(void)(GDNativeClassBinding.addCustomSignal, _godot_object, name); 151 } 152 /** 153 Add a function with the specified name to the VisualScript. 154 */ 155 void addFunction(in String name) 156 { 157 checkClassBinding!(typeof(this))(); 158 ptrcall!(void)(GDNativeClassBinding.addFunction, _godot_object, name); 159 } 160 /** 161 Add a node to a function of the VisualScript. 162 */ 163 void addNode(in String func, in long id, VisualScriptNode node, in Vector2 position = Vector2(0, 0)) 164 { 165 checkClassBinding!(typeof(this))(); 166 ptrcall!(void)(GDNativeClassBinding.addNode, _godot_object, func, id, node, position); 167 } 168 /** 169 Add a variable to the VisualScript, optionally giving it a default value or marking it as exported. 170 */ 171 void addVariable(VariantArg1)(in String name, in VariantArg1 default_value = Variant.nil, in bool _export = false) 172 { 173 checkClassBinding!(typeof(this))(); 174 ptrcall!(void)(GDNativeClassBinding.addVariable, _godot_object, name, default_value, _export); 175 } 176 /** 177 Add an argument to a custom signal added with $(D addCustomSignal). 178 */ 179 void customSignalAddArgument(in String name, in long type, in String argname, in long index = -1) 180 { 181 checkClassBinding!(typeof(this))(); 182 ptrcall!(void)(GDNativeClassBinding.customSignalAddArgument, _godot_object, name, type, argname, index); 183 } 184 /** 185 Get the count of a custom signal's arguments. 186 */ 187 long customSignalGetArgumentCount(in String name) const 188 { 189 checkClassBinding!(typeof(this))(); 190 return ptrcall!(long)(GDNativeClassBinding.customSignalGetArgumentCount, _godot_object, name); 191 } 192 /** 193 Get the name of a custom signal's argument. 194 */ 195 String customSignalGetArgumentName(in String name, in long argidx) const 196 { 197 checkClassBinding!(typeof(this))(); 198 return ptrcall!(String)(GDNativeClassBinding.customSignalGetArgumentName, _godot_object, name, argidx); 199 } 200 /** 201 Get the type of a custom signal's argument. 202 */ 203 Variant.Type customSignalGetArgumentType(in String name, in long argidx) const 204 { 205 checkClassBinding!(typeof(this))(); 206 return ptrcall!(Variant.Type)(GDNativeClassBinding.customSignalGetArgumentType, _godot_object, name, argidx); 207 } 208 /** 209 Remove a specific custom signal's argument. 210 */ 211 void customSignalRemoveArgument(in String name, in long argidx) 212 { 213 checkClassBinding!(typeof(this))(); 214 ptrcall!(void)(GDNativeClassBinding.customSignalRemoveArgument, _godot_object, name, argidx); 215 } 216 /** 217 Rename a custom signal's argument. 218 */ 219 void customSignalSetArgumentName(in String name, in long argidx, in String argname) 220 { 221 checkClassBinding!(typeof(this))(); 222 ptrcall!(void)(GDNativeClassBinding.customSignalSetArgumentName, _godot_object, name, argidx, argname); 223 } 224 /** 225 Change the type of a custom signal's argument. 226 */ 227 void customSignalSetArgumentType(in String name, in long argidx, in long type) 228 { 229 checkClassBinding!(typeof(this))(); 230 ptrcall!(void)(GDNativeClassBinding.customSignalSetArgumentType, _godot_object, name, argidx, type); 231 } 232 /** 233 Swap two of the arguments of a custom signal. 234 */ 235 void customSignalSwapArgument(in String name, in long argidx, in long withidx) 236 { 237 checkClassBinding!(typeof(this))(); 238 ptrcall!(void)(GDNativeClassBinding.customSignalSwapArgument, _godot_object, name, argidx, withidx); 239 } 240 /** 241 Connect two data ports. The value of `from_node`'s `from_port` would be fed into `to_node`'s `to_port`. 242 */ 243 void dataConnect(in String func, in long from_node, in long from_port, in long to_node, in long to_port) 244 { 245 checkClassBinding!(typeof(this))(); 246 ptrcall!(void)(GDNativeClassBinding.dataConnect, _godot_object, func, from_node, from_port, to_node, to_port); 247 } 248 /** 249 Disconnect two data ports previously connected with $(D dataConnect). 250 */ 251 void dataDisconnect(in String func, in long from_node, in long from_port, in long to_node, in long to_port) 252 { 253 checkClassBinding!(typeof(this))(); 254 ptrcall!(void)(GDNativeClassBinding.dataDisconnect, _godot_object, func, from_node, from_port, to_node, to_port); 255 } 256 /** 257 Returns the id of a function's entry point node. 258 */ 259 long getFunctionNodeId(in String name) const 260 { 261 checkClassBinding!(typeof(this))(); 262 return ptrcall!(long)(GDNativeClassBinding.getFunctionNodeId, _godot_object, name); 263 } 264 /** 265 Returns the position of the center of the screen for a given function. 266 */ 267 Vector2 getFunctionScroll(in String name) const 268 { 269 checkClassBinding!(typeof(this))(); 270 return ptrcall!(Vector2)(GDNativeClassBinding.getFunctionScroll, _godot_object, name); 271 } 272 /** 273 Returns a node given its id and its function. 274 */ 275 Ref!VisualScriptNode getNode(in String func, in long id) const 276 { 277 checkClassBinding!(typeof(this))(); 278 return ptrcall!(VisualScriptNode)(GDNativeClassBinding.getNode, _godot_object, func, id); 279 } 280 /** 281 Returns a node's position in pixels. 282 */ 283 Vector2 getNodePosition(in String func, in long id) const 284 { 285 checkClassBinding!(typeof(this))(); 286 return ptrcall!(Vector2)(GDNativeClassBinding.getNodePosition, _godot_object, func, id); 287 } 288 /** 289 Returns the default (initial) value of a variable. 290 */ 291 Variant getVariableDefaultValue(in String name) const 292 { 293 checkClassBinding!(typeof(this))(); 294 return ptrcall!(Variant)(GDNativeClassBinding.getVariableDefaultValue, _godot_object, name); 295 } 296 /** 297 Returns whether a variable is exported. 298 */ 299 bool getVariableExport(in String name) const 300 { 301 checkClassBinding!(typeof(this))(); 302 return ptrcall!(bool)(GDNativeClassBinding.getVariableExport, _godot_object, name); 303 } 304 /** 305 Returns the information for a given variable as a dictionary. The information includes its name, type, hint and usage. 306 */ 307 Dictionary getVariableInfo(in String name) const 308 { 309 checkClassBinding!(typeof(this))(); 310 return ptrcall!(Dictionary)(GDNativeClassBinding.getVariableInfo, _godot_object, name); 311 } 312 /** 313 Returns whether a signal exists with the specified name. 314 */ 315 bool hasCustomSignal(in String name) const 316 { 317 checkClassBinding!(typeof(this))(); 318 return ptrcall!(bool)(GDNativeClassBinding.hasCustomSignal, _godot_object, name); 319 } 320 /** 321 Returns whether the specified data ports are connected. 322 */ 323 bool hasDataConnection(in String func, in long from_node, in long from_port, in long to_node, in long to_port) const 324 { 325 checkClassBinding!(typeof(this))(); 326 return ptrcall!(bool)(GDNativeClassBinding.hasDataConnection, _godot_object, func, from_node, from_port, to_node, to_port); 327 } 328 /** 329 Returns whether a function exists with the specified name. 330 */ 331 bool hasFunction(in String name) const 332 { 333 checkClassBinding!(typeof(this))(); 334 return ptrcall!(bool)(GDNativeClassBinding.hasFunction, _godot_object, name); 335 } 336 /** 337 Returns whether a node exists with the given id. 338 */ 339 bool hasNode(in String func, in long id) const 340 { 341 checkClassBinding!(typeof(this))(); 342 return ptrcall!(bool)(GDNativeClassBinding.hasNode, _godot_object, func, id); 343 } 344 /** 345 Returns whether the specified sequence ports are connected. 346 */ 347 bool hasSequenceConnection(in String func, in long from_node, in long from_output, in long to_node) const 348 { 349 checkClassBinding!(typeof(this))(); 350 return ptrcall!(bool)(GDNativeClassBinding.hasSequenceConnection, _godot_object, func, from_node, from_output, to_node); 351 } 352 /** 353 Returns whether a variable exists with the specified name. 354 */ 355 bool hasVariable(in String name) const 356 { 357 checkClassBinding!(typeof(this))(); 358 return ptrcall!(bool)(GDNativeClassBinding.hasVariable, _godot_object, name); 359 } 360 /** 361 Remove a custom signal with the given name. 362 */ 363 void removeCustomSignal(in String name) 364 { 365 checkClassBinding!(typeof(this))(); 366 ptrcall!(void)(GDNativeClassBinding.removeCustomSignal, _godot_object, name); 367 } 368 /** 369 Remove a specific function and its nodes from the script. 370 */ 371 void removeFunction(in String name) 372 { 373 checkClassBinding!(typeof(this))(); 374 ptrcall!(void)(GDNativeClassBinding.removeFunction, _godot_object, name); 375 } 376 /** 377 Remove a specific node. 378 */ 379 void removeNode(in String func, in long id) 380 { 381 checkClassBinding!(typeof(this))(); 382 ptrcall!(void)(GDNativeClassBinding.removeNode, _godot_object, func, id); 383 } 384 /** 385 Remove a variable with the given name. 386 */ 387 void removeVariable(in String name) 388 { 389 checkClassBinding!(typeof(this))(); 390 ptrcall!(void)(GDNativeClassBinding.removeVariable, _godot_object, name); 391 } 392 /** 393 Change the name of a custom signal. 394 */ 395 void renameCustomSignal(in String name, in String new_name) 396 { 397 checkClassBinding!(typeof(this))(); 398 ptrcall!(void)(GDNativeClassBinding.renameCustomSignal, _godot_object, name, new_name); 399 } 400 /** 401 Change the name of a function. 402 */ 403 void renameFunction(in String name, in String new_name) 404 { 405 checkClassBinding!(typeof(this))(); 406 ptrcall!(void)(GDNativeClassBinding.renameFunction, _godot_object, name, new_name); 407 } 408 /** 409 Change the name of a variable. 410 */ 411 void renameVariable(in String name, in String new_name) 412 { 413 checkClassBinding!(typeof(this))(); 414 ptrcall!(void)(GDNativeClassBinding.renameVariable, _godot_object, name, new_name); 415 } 416 /** 417 Connect two sequence ports. The execution will flow from of `from_node`'s `from_output` into `to_node`. 418 Unlike $(D dataConnect), there isn't a `to_port`, since the target node can have only one sequence port. 419 */ 420 void sequenceConnect(in String func, in long from_node, in long from_output, in long to_node) 421 { 422 checkClassBinding!(typeof(this))(); 423 ptrcall!(void)(GDNativeClassBinding.sequenceConnect, _godot_object, func, from_node, from_output, to_node); 424 } 425 /** 426 Disconnect two sequence ports previously connected with $(D sequenceConnect). 427 */ 428 void sequenceDisconnect(in String func, in long from_node, in long from_output, in long to_node) 429 { 430 checkClassBinding!(typeof(this))(); 431 ptrcall!(void)(GDNativeClassBinding.sequenceDisconnect, _godot_object, func, from_node, from_output, to_node); 432 } 433 /** 434 Position the center of the screen for a function. 435 */ 436 void setFunctionScroll(in String name, in Vector2 ofs) 437 { 438 checkClassBinding!(typeof(this))(); 439 ptrcall!(void)(GDNativeClassBinding.setFunctionScroll, _godot_object, name, ofs); 440 } 441 /** 442 Set the base type of the script. 443 */ 444 void setInstanceBaseType(in String type) 445 { 446 checkClassBinding!(typeof(this))(); 447 ptrcall!(void)(GDNativeClassBinding.setInstanceBaseType, _godot_object, type); 448 } 449 /** 450 Position a node on the screen. 451 */ 452 void setNodePosition(in String func, in long id, in Vector2 position) 453 { 454 checkClassBinding!(typeof(this))(); 455 ptrcall!(void)(GDNativeClassBinding.setNodePosition, _godot_object, func, id, position); 456 } 457 /** 458 Change the default (initial) value of a variable. 459 */ 460 void setVariableDefaultValue(VariantArg1)(in String name, in VariantArg1 value) 461 { 462 checkClassBinding!(typeof(this))(); 463 ptrcall!(void)(GDNativeClassBinding.setVariableDefaultValue, _godot_object, name, value); 464 } 465 /** 466 Change whether a variable is exported. 467 */ 468 void setVariableExport(in String name, in bool enable) 469 { 470 checkClassBinding!(typeof(this))(); 471 ptrcall!(void)(GDNativeClassBinding.setVariableExport, _godot_object, name, enable); 472 } 473 /** 474 Set a variable's info, using the same format as $(D getVariableInfo). 475 */ 476 void setVariableInfo(in String name, in Dictionary value) 477 { 478 checkClassBinding!(typeof(this))(); 479 ptrcall!(void)(GDNativeClassBinding.setVariableInfo, _godot_object, name, value); 480 } 481 /** 482 483 */ 484 @property Dictionary data() 485 { 486 return _getData(); 487 } 488 /// ditto 489 @property void data(Dictionary v) 490 { 491 _setData(v); 492 } 493 }