1 /** 2 State machine for control of animations. 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.animationnodestatemachine; 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.animationrootnode; 25 import godot.animationnode; 26 import godot.animationnodestatemachinetransition; 27 /** 28 State machine for control of animations. 29 30 Contains multiple nodes representing animation states, connected in a graph. Node transitions can be configured to happen automatically or via code, using a shortest-path algorithm. Retrieve the $(D AnimationNodeStateMachinePlayback) object from the $(D AnimationTree) node to control it programmatically. 31 $(B Example:) 32 33 34 var state_machine = $AnimationTree.get("parameters/playback") 35 state_machine.travel("some_state") 36 37 38 */ 39 @GodotBaseClass struct AnimationNodeStateMachine 40 { 41 package(godot) enum string _GODOT_internal_name = "AnimationNodeStateMachine"; 42 public: 43 @nogc nothrow: 44 union { /** */ godot_object _godot_object; /** */ AnimationRootNode _GODOT_base; } 45 alias _GODOT_base this; 46 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 47 package(godot) __gshared bool _classBindingInitialized = false; 48 package(godot) static struct GDNativeClassBinding 49 { 50 __gshared: 51 @GodotName("_tree_changed") GodotMethod!(void) _treeChanged; 52 @GodotName("add_node") GodotMethod!(void, String, AnimationNode, Vector2) addNode; 53 @GodotName("add_transition") GodotMethod!(void, String, String, AnimationNodeStateMachineTransition) addTransition; 54 @GodotName("get_end_node") GodotMethod!(String) getEndNode; 55 @GodotName("get_graph_offset") GodotMethod!(Vector2) getGraphOffset; 56 @GodotName("get_node") GodotMethod!(AnimationNode, String) getNode; 57 @GodotName("get_node_name") GodotMethod!(String, AnimationNode) getNodeName; 58 @GodotName("get_node_position") GodotMethod!(Vector2, String) getNodePosition; 59 @GodotName("get_start_node") GodotMethod!(String) getStartNode; 60 @GodotName("get_transition") GodotMethod!(AnimationNodeStateMachineTransition, long) getTransition; 61 @GodotName("get_transition_count") GodotMethod!(long) getTransitionCount; 62 @GodotName("get_transition_from") GodotMethod!(String, long) getTransitionFrom; 63 @GodotName("get_transition_to") GodotMethod!(String, long) getTransitionTo; 64 @GodotName("has_node") GodotMethod!(bool, String) hasNode; 65 @GodotName("has_transition") GodotMethod!(bool, String, String) hasTransition; 66 @GodotName("remove_node") GodotMethod!(void, String) removeNode; 67 @GodotName("remove_transition") GodotMethod!(void, String, String) removeTransition; 68 @GodotName("remove_transition_by_index") GodotMethod!(void, long) removeTransitionByIndex; 69 @GodotName("rename_node") GodotMethod!(void, String, String) renameNode; 70 @GodotName("replace_node") GodotMethod!(void, String, AnimationNode) replaceNode; 71 @GodotName("set_end_node") GodotMethod!(void, String) setEndNode; 72 @GodotName("set_graph_offset") GodotMethod!(void, Vector2) setGraphOffset; 73 @GodotName("set_node_position") GodotMethod!(void, String, Vector2) setNodePosition; 74 @GodotName("set_start_node") GodotMethod!(void, String) setStartNode; 75 } 76 /// 77 pragma(inline, true) bool opEquals(in AnimationNodeStateMachine other) const 78 { return _godot_object.ptr is other._godot_object.ptr; } 79 /// 80 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 81 { _godot_object.ptr = n; return null; } 82 /// 83 pragma(inline, true) bool opEquals(typeof(null) n) const 84 { return _godot_object.ptr is n; } 85 /// 86 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 87 mixin baseCasts; 88 /// Construct a new instance of AnimationNodeStateMachine. 89 /// Note: use `memnew!AnimationNodeStateMachine` instead. 90 static AnimationNodeStateMachine _new() 91 { 92 static godot_class_constructor constructor; 93 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AnimationNodeStateMachine"); 94 if(constructor is null) return typeof(this).init; 95 return cast(AnimationNodeStateMachine)(constructor()); 96 } 97 @disable new(size_t s); 98 /** 99 100 */ 101 void _treeChanged() 102 { 103 Array _GODOT_args = Array.make(); 104 String _GODOT_method_name = String("_tree_changed"); 105 this.callv(_GODOT_method_name, _GODOT_args); 106 } 107 /** 108 Adds a new node to the graph. The `position` is used for display in the editor. 109 */ 110 void addNode(in String name, AnimationNode node, in Vector2 position = Vector2(0, 0)) 111 { 112 checkClassBinding!(typeof(this))(); 113 ptrcall!(void)(GDNativeClassBinding.addNode, _godot_object, name, node, position); 114 } 115 /** 116 Adds a transition between the given nodes. 117 */ 118 void addTransition(in String from, in String to, AnimationNodeStateMachineTransition transition) 119 { 120 checkClassBinding!(typeof(this))(); 121 ptrcall!(void)(GDNativeClassBinding.addTransition, _godot_object, from, to, transition); 122 } 123 /** 124 Returns the graph's end node. 125 */ 126 String getEndNode() const 127 { 128 checkClassBinding!(typeof(this))(); 129 return ptrcall!(String)(GDNativeClassBinding.getEndNode, _godot_object); 130 } 131 /** 132 Returns the draw offset of the graph. Used for display in the editor. 133 */ 134 Vector2 getGraphOffset() const 135 { 136 checkClassBinding!(typeof(this))(); 137 return ptrcall!(Vector2)(GDNativeClassBinding.getGraphOffset, _godot_object); 138 } 139 /** 140 Returns the animation node with the given name. 141 */ 142 Ref!AnimationNode getNode(in String name) const 143 { 144 checkClassBinding!(typeof(this))(); 145 return ptrcall!(AnimationNode)(GDNativeClassBinding.getNode, _godot_object, name); 146 } 147 /** 148 Returns the given animation node's name. 149 */ 150 String getNodeName(AnimationNode node) const 151 { 152 checkClassBinding!(typeof(this))(); 153 return ptrcall!(String)(GDNativeClassBinding.getNodeName, _godot_object, node); 154 } 155 /** 156 Returns the given node's coordinates. Used for display in the editor. 157 */ 158 Vector2 getNodePosition(in String name) const 159 { 160 checkClassBinding!(typeof(this))(); 161 return ptrcall!(Vector2)(GDNativeClassBinding.getNodePosition, _godot_object, name); 162 } 163 /** 164 Returns the graph's end node. 165 */ 166 String getStartNode() const 167 { 168 checkClassBinding!(typeof(this))(); 169 return ptrcall!(String)(GDNativeClassBinding.getStartNode, _godot_object); 170 } 171 /** 172 Returns the given transition. 173 */ 174 Ref!AnimationNodeStateMachineTransition getTransition(in long idx) const 175 { 176 checkClassBinding!(typeof(this))(); 177 return ptrcall!(AnimationNodeStateMachineTransition)(GDNativeClassBinding.getTransition, _godot_object, idx); 178 } 179 /** 180 Returns the number of connections in the graph. 181 */ 182 long getTransitionCount() const 183 { 184 checkClassBinding!(typeof(this))(); 185 return ptrcall!(long)(GDNativeClassBinding.getTransitionCount, _godot_object); 186 } 187 /** 188 Returns the given transition's start node. 189 */ 190 String getTransitionFrom(in long idx) const 191 { 192 checkClassBinding!(typeof(this))(); 193 return ptrcall!(String)(GDNativeClassBinding.getTransitionFrom, _godot_object, idx); 194 } 195 /** 196 Returns the given transition's end node. 197 */ 198 String getTransitionTo(in long idx) const 199 { 200 checkClassBinding!(typeof(this))(); 201 return ptrcall!(String)(GDNativeClassBinding.getTransitionTo, _godot_object, idx); 202 } 203 /** 204 Returns `true` if the graph contains the given node. 205 */ 206 bool hasNode(in String name) const 207 { 208 checkClassBinding!(typeof(this))(); 209 return ptrcall!(bool)(GDNativeClassBinding.hasNode, _godot_object, name); 210 } 211 /** 212 Returns `true` if there is a transition between the given nodes. 213 */ 214 bool hasTransition(in String from, in String to) const 215 { 216 checkClassBinding!(typeof(this))(); 217 return ptrcall!(bool)(GDNativeClassBinding.hasTransition, _godot_object, from, to); 218 } 219 /** 220 Deletes the given node from the graph. 221 */ 222 void removeNode(in String name) 223 { 224 checkClassBinding!(typeof(this))(); 225 ptrcall!(void)(GDNativeClassBinding.removeNode, _godot_object, name); 226 } 227 /** 228 Deletes the transition between the two specified nodes. 229 */ 230 void removeTransition(in String from, in String to) 231 { 232 checkClassBinding!(typeof(this))(); 233 ptrcall!(void)(GDNativeClassBinding.removeTransition, _godot_object, from, to); 234 } 235 /** 236 Deletes the given transition by index. 237 */ 238 void removeTransitionByIndex(in long idx) 239 { 240 checkClassBinding!(typeof(this))(); 241 ptrcall!(void)(GDNativeClassBinding.removeTransitionByIndex, _godot_object, idx); 242 } 243 /** 244 Renames the given node. 245 */ 246 void renameNode(in String name, in String new_name) 247 { 248 checkClassBinding!(typeof(this))(); 249 ptrcall!(void)(GDNativeClassBinding.renameNode, _godot_object, name, new_name); 250 } 251 /** 252 Replaces the node and keeps its transitions unchanged. 253 */ 254 void replaceNode(in String name, AnimationNode node) 255 { 256 checkClassBinding!(typeof(this))(); 257 ptrcall!(void)(GDNativeClassBinding.replaceNode, _godot_object, name, node); 258 } 259 /** 260 Sets the given node as the graph end point. 261 */ 262 void setEndNode(in String name) 263 { 264 checkClassBinding!(typeof(this))(); 265 ptrcall!(void)(GDNativeClassBinding.setEndNode, _godot_object, name); 266 } 267 /** 268 Sets the draw offset of the graph. Used for display in the editor. 269 */ 270 void setGraphOffset(in Vector2 offset) 271 { 272 checkClassBinding!(typeof(this))(); 273 ptrcall!(void)(GDNativeClassBinding.setGraphOffset, _godot_object, offset); 274 } 275 /** 276 Sets the node's coordinates. Used for display in the editor. 277 */ 278 void setNodePosition(in String name, in Vector2 position) 279 { 280 checkClassBinding!(typeof(this))(); 281 ptrcall!(void)(GDNativeClassBinding.setNodePosition, _godot_object, name, position); 282 } 283 /** 284 Sets the given node as the graph start point. 285 */ 286 void setStartNode(in String name) 287 { 288 checkClassBinding!(typeof(this))(); 289 ptrcall!(void)(GDNativeClassBinding.setStartNode, _godot_object, name); 290 } 291 }