1 /** 2 Container and player of $(D Animation) resources. 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.animationplayer; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.node; 24 import godot.animation; 25 /** 26 Container and player of $(D Animation) resources. 27 28 An animation player is used for general purpose playback of $(D Animation) resources. It contains a dictionary of animations (referenced by name) and custom blend times between their transitions. Additionally, animations can be played and blended in different channels. 29 */ 30 @GodotBaseClass struct AnimationPlayer 31 { 32 enum string _GODOT_internal_name = "AnimationPlayer"; 33 public: 34 @nogc nothrow: 35 union { godot_object _godot_object; Node _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct _classBinding 40 { 41 __gshared: 42 @GodotName("_node_removed") GodotMethod!(void, GodotObject) _nodeRemoved; 43 @GodotName("_animation_changed") GodotMethod!(void) _animationChanged; 44 @GodotName("add_animation") GodotMethod!(GodotError, String, Animation) addAnimation; 45 @GodotName("remove_animation") GodotMethod!(void, String) removeAnimation; 46 @GodotName("rename_animation") GodotMethod!(void, String, String) renameAnimation; 47 @GodotName("has_animation") GodotMethod!(bool, String) hasAnimation; 48 @GodotName("get_animation") GodotMethod!(Animation, String) getAnimation; 49 @GodotName("get_animation_list") GodotMethod!(PoolStringArray) getAnimationList; 50 @GodotName("animation_set_next") GodotMethod!(void, String, String) animationSetNext; 51 @GodotName("animation_get_next") GodotMethod!(String, String) animationGetNext; 52 @GodotName("set_blend_time") GodotMethod!(void, String, String, double) setBlendTime; 53 @GodotName("get_blend_time") GodotMethod!(double, String, String) getBlendTime; 54 @GodotName("set_default_blend_time") GodotMethod!(void, double) setDefaultBlendTime; 55 @GodotName("get_default_blend_time") GodotMethod!(double) getDefaultBlendTime; 56 @GodotName("play") GodotMethod!(void, String, double, double, bool) play; 57 @GodotName("play_backwards") GodotMethod!(void, String, double) playBackwards; 58 @GodotName("stop") GodotMethod!(void, bool) stop; 59 @GodotName("is_playing") GodotMethod!(bool) isPlaying; 60 @GodotName("set_current_animation") GodotMethod!(void, String) setCurrentAnimation; 61 @GodotName("get_current_animation") GodotMethod!(String) getCurrentAnimation; 62 @GodotName("set_assigned_animation") GodotMethod!(void, String) setAssignedAnimation; 63 @GodotName("get_assigned_animation") GodotMethod!(String) getAssignedAnimation; 64 @GodotName("queue") GodotMethod!(void, String) queue; 65 @GodotName("clear_queue") GodotMethod!(void) clearQueue; 66 @GodotName("set_active") GodotMethod!(void, bool) setActive; 67 @GodotName("is_active") GodotMethod!(bool) isActive; 68 @GodotName("set_speed_scale") GodotMethod!(void, double) setSpeedScale; 69 @GodotName("get_speed_scale") GodotMethod!(double) getSpeedScale; 70 @GodotName("get_playing_speed") GodotMethod!(double) getPlayingSpeed; 71 @GodotName("set_autoplay") GodotMethod!(void, String) setAutoplay; 72 @GodotName("get_autoplay") GodotMethod!(String) getAutoplay; 73 @GodotName("set_root") GodotMethod!(void, NodePath) setRoot; 74 @GodotName("get_root") GodotMethod!(NodePath) getRoot; 75 @GodotName("find_animation") GodotMethod!(String, Animation) findAnimation; 76 @GodotName("clear_caches") GodotMethod!(void) clearCaches; 77 @GodotName("set_animation_process_mode") GodotMethod!(void, long) setAnimationProcessMode; 78 @GodotName("get_animation_process_mode") GodotMethod!(AnimationPlayer.AnimationProcessMode) getAnimationProcessMode; 79 @GodotName("get_current_animation_position") GodotMethod!(double) getCurrentAnimationPosition; 80 @GodotName("get_current_animation_length") GodotMethod!(double) getCurrentAnimationLength; 81 @GodotName("seek") GodotMethod!(void, double, bool) seek; 82 @GodotName("advance") GodotMethod!(void, double) advance; 83 } 84 bool opEquals(in AnimationPlayer other) const { return _godot_object.ptr is other._godot_object.ptr; } 85 AnimationPlayer opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 86 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 87 mixin baseCasts; 88 static AnimationPlayer _new() 89 { 90 static godot_class_constructor constructor; 91 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AnimationPlayer"); 92 if(constructor is null) return typeof(this).init; 93 return cast(AnimationPlayer)(constructor()); 94 } 95 @disable new(size_t s); 96 /// 97 enum AnimationProcessMode : int 98 { 99 /** 100 Process animation during the physics process. This is especially useful when animating physics bodies. 101 */ 102 animationProcessPhysics = 0, 103 /** 104 Process animation during the idle process. 105 */ 106 animationProcessIdle = 1, 107 /** 108 Do not process animation. Use the 'advance' method to process the animation manually. 109 */ 110 animationProcessManual = 2, 111 } 112 /// 113 enum Constants : int 114 { 115 animationProcessPhysics = 0, 116 animationProcessIdle = 1, 117 animationProcessManual = 2, 118 } 119 /** 120 121 */ 122 void _nodeRemoved(GodotObject arg0) 123 { 124 Array _GODOT_args = Array.empty_array; 125 _GODOT_args.append(arg0); 126 String _GODOT_method_name = String("_node_removed"); 127 this.callv(_GODOT_method_name, _GODOT_args); 128 } 129 /** 130 131 */ 132 void _animationChanged() 133 { 134 Array _GODOT_args = Array.empty_array; 135 String _GODOT_method_name = String("_animation_changed"); 136 this.callv(_GODOT_method_name, _GODOT_args); 137 } 138 /** 139 Adds `animation` to the player accessible with the key `name`. 140 */ 141 GodotError addAnimation(StringArg0)(in StringArg0 name, Animation animation) 142 { 143 checkClassBinding!(typeof(this))(); 144 return ptrcall!(GodotError)(_classBinding.addAnimation, _godot_object, name, animation); 145 } 146 /** 147 Remove the animation with key `name`. 148 */ 149 void removeAnimation(StringArg0)(in StringArg0 name) 150 { 151 checkClassBinding!(typeof(this))(); 152 ptrcall!(void)(_classBinding.removeAnimation, _godot_object, name); 153 } 154 /** 155 Rename an existing animation with key `name` to `newname`. 156 */ 157 void renameAnimation(StringArg0, StringArg1)(in StringArg0 name, in StringArg1 newname) 158 { 159 checkClassBinding!(typeof(this))(); 160 ptrcall!(void)(_classBinding.renameAnimation, _godot_object, name, newname); 161 } 162 /** 163 Returns `true` if the `AnimationPlayer` stores an $(D Animation) with key `name`. 164 */ 165 bool hasAnimation(StringArg0)(in StringArg0 name) const 166 { 167 checkClassBinding!(typeof(this))(); 168 return ptrcall!(bool)(_classBinding.hasAnimation, _godot_object, name); 169 } 170 /** 171 Returns the $(D Animation) with key `name` or `null` if not found. 172 */ 173 Ref!Animation getAnimation(StringArg0)(in StringArg0 name) const 174 { 175 checkClassBinding!(typeof(this))(); 176 return ptrcall!(Animation)(_classBinding.getAnimation, _godot_object, name); 177 } 178 /** 179 Returns the list of stored animation names. 180 */ 181 PoolStringArray getAnimationList() const 182 { 183 checkClassBinding!(typeof(this))(); 184 return ptrcall!(PoolStringArray)(_classBinding.getAnimationList, _godot_object); 185 } 186 /** 187 Triggers the `anim_to` animation when the `anim_from` animation completes. 188 */ 189 void animationSetNext(StringArg0, StringArg1)(in StringArg0 anim_from, in StringArg1 anim_to) 190 { 191 checkClassBinding!(typeof(this))(); 192 ptrcall!(void)(_classBinding.animationSetNext, _godot_object, anim_from, anim_to); 193 } 194 /** 195 Returns the name of the next animation in the queue. 196 */ 197 String animationGetNext(StringArg0)(in StringArg0 anim_from) const 198 { 199 checkClassBinding!(typeof(this))(); 200 return ptrcall!(String)(_classBinding.animationGetNext, _godot_object, anim_from); 201 } 202 /** 203 Specify a blend time (in seconds) between two animations, referenced by their names. 204 */ 205 void setBlendTime(StringArg0, StringArg1)(in StringArg0 anim_from, in StringArg1 anim_to, in double sec) 206 { 207 checkClassBinding!(typeof(this))(); 208 ptrcall!(void)(_classBinding.setBlendTime, _godot_object, anim_from, anim_to, sec); 209 } 210 /** 211 Get the blend time (in seconds) between two animations, referenced by their names. 212 */ 213 double getBlendTime(StringArg0, StringArg1)(in StringArg0 anim_from, in StringArg1 anim_to) const 214 { 215 checkClassBinding!(typeof(this))(); 216 return ptrcall!(double)(_classBinding.getBlendTime, _godot_object, anim_from, anim_to); 217 } 218 /** 219 220 */ 221 void setDefaultBlendTime(in double sec) 222 { 223 checkClassBinding!(typeof(this))(); 224 ptrcall!(void)(_classBinding.setDefaultBlendTime, _godot_object, sec); 225 } 226 /** 227 228 */ 229 double getDefaultBlendTime() const 230 { 231 checkClassBinding!(typeof(this))(); 232 return ptrcall!(double)(_classBinding.getDefaultBlendTime, _godot_object); 233 } 234 /** 235 Play the animation with key `name`. Custom speed and blend times can be set. If custom speed is negative (-1), 'from_end' being true can play the animation backwards. 236 */ 237 void play(StringArg0)(in StringArg0 name = "", in double custom_blend = -1, in double custom_speed = 1, in bool from_end = false) 238 { 239 checkClassBinding!(typeof(this))(); 240 ptrcall!(void)(_classBinding.play, _godot_object, name, custom_blend, custom_speed, from_end); 241 } 242 /** 243 Play the animation with key `name` in reverse. 244 */ 245 void playBackwards(StringArg0)(in StringArg0 name = "", in double custom_blend = -1) 246 { 247 checkClassBinding!(typeof(this))(); 248 ptrcall!(void)(_classBinding.playBackwards, _godot_object, name, custom_blend); 249 } 250 /** 251 Stop the currently playing animation. If `reset` is `true`, the anim position is reset to `0`. 252 */ 253 void stop(in bool reset = true) 254 { 255 checkClassBinding!(typeof(this))(); 256 ptrcall!(void)(_classBinding.stop, _godot_object, reset); 257 } 258 /** 259 Returns `true` if playing an animation. 260 */ 261 bool isPlaying() const 262 { 263 checkClassBinding!(typeof(this))(); 264 return ptrcall!(bool)(_classBinding.isPlaying, _godot_object); 265 } 266 /** 267 268 */ 269 void setCurrentAnimation(StringArg0)(in StringArg0 anim) 270 { 271 checkClassBinding!(typeof(this))(); 272 ptrcall!(void)(_classBinding.setCurrentAnimation, _godot_object, anim); 273 } 274 /** 275 276 */ 277 String getCurrentAnimation() const 278 { 279 checkClassBinding!(typeof(this))(); 280 return ptrcall!(String)(_classBinding.getCurrentAnimation, _godot_object); 281 } 282 /** 283 284 */ 285 void setAssignedAnimation(StringArg0)(in StringArg0 anim) 286 { 287 checkClassBinding!(typeof(this))(); 288 ptrcall!(void)(_classBinding.setAssignedAnimation, _godot_object, anim); 289 } 290 /** 291 292 */ 293 String getAssignedAnimation() const 294 { 295 checkClassBinding!(typeof(this))(); 296 return ptrcall!(String)(_classBinding.getAssignedAnimation, _godot_object); 297 } 298 /** 299 Queue an animation for playback once the current one is done. 300 */ 301 void queue(StringArg0)(in StringArg0 name) 302 { 303 checkClassBinding!(typeof(this))(); 304 ptrcall!(void)(_classBinding.queue, _godot_object, name); 305 } 306 /** 307 Clears all queued, unplayed animations. 308 */ 309 void clearQueue() 310 { 311 checkClassBinding!(typeof(this))(); 312 ptrcall!(void)(_classBinding.clearQueue, _godot_object); 313 } 314 /** 315 316 */ 317 void setActive(in bool active) 318 { 319 checkClassBinding!(typeof(this))(); 320 ptrcall!(void)(_classBinding.setActive, _godot_object, active); 321 } 322 /** 323 324 */ 325 bool isActive() const 326 { 327 checkClassBinding!(typeof(this))(); 328 return ptrcall!(bool)(_classBinding.isActive, _godot_object); 329 } 330 /** 331 332 */ 333 void setSpeedScale(in double speed) 334 { 335 checkClassBinding!(typeof(this))(); 336 ptrcall!(void)(_classBinding.setSpeedScale, _godot_object, speed); 337 } 338 /** 339 340 */ 341 double getSpeedScale() const 342 { 343 checkClassBinding!(typeof(this))(); 344 return ptrcall!(double)(_classBinding.getSpeedScale, _godot_object); 345 } 346 /** 347 Get the actual playing speed of current animation or 0 if not playing. This speed is the `playback_speed` property multiplied by `custom_speed` argument specified when calling the `play` method. 348 */ 349 double getPlayingSpeed() const 350 { 351 checkClassBinding!(typeof(this))(); 352 return ptrcall!(double)(_classBinding.getPlayingSpeed, _godot_object); 353 } 354 /** 355 356 */ 357 void setAutoplay(StringArg0)(in StringArg0 name) 358 { 359 checkClassBinding!(typeof(this))(); 360 ptrcall!(void)(_classBinding.setAutoplay, _godot_object, name); 361 } 362 /** 363 364 */ 365 String getAutoplay() const 366 { 367 checkClassBinding!(typeof(this))(); 368 return ptrcall!(String)(_classBinding.getAutoplay, _godot_object); 369 } 370 /** 371 372 */ 373 void setRoot(NodePathArg0)(in NodePathArg0 path) 374 { 375 checkClassBinding!(typeof(this))(); 376 ptrcall!(void)(_classBinding.setRoot, _godot_object, path); 377 } 378 /** 379 380 */ 381 NodePath getRoot() const 382 { 383 checkClassBinding!(typeof(this))(); 384 return ptrcall!(NodePath)(_classBinding.getRoot, _godot_object); 385 } 386 /** 387 Returns the name of `animation` or empty string if not found. 388 */ 389 String findAnimation(Animation animation) const 390 { 391 checkClassBinding!(typeof(this))(); 392 return ptrcall!(String)(_classBinding.findAnimation, _godot_object, animation); 393 } 394 /** 395 `AnimationPlayer` caches animated nodes. It may not notice if a node disappears, so clear_caches forces it to update the cache again. 396 */ 397 void clearCaches() 398 { 399 checkClassBinding!(typeof(this))(); 400 ptrcall!(void)(_classBinding.clearCaches, _godot_object); 401 } 402 /** 403 404 */ 405 void setAnimationProcessMode(in long mode) 406 { 407 checkClassBinding!(typeof(this))(); 408 ptrcall!(void)(_classBinding.setAnimationProcessMode, _godot_object, mode); 409 } 410 /** 411 412 */ 413 AnimationPlayer.AnimationProcessMode getAnimationProcessMode() const 414 { 415 checkClassBinding!(typeof(this))(); 416 return ptrcall!(AnimationPlayer.AnimationProcessMode)(_classBinding.getAnimationProcessMode, _godot_object); 417 } 418 /** 419 420 */ 421 double getCurrentAnimationPosition() const 422 { 423 checkClassBinding!(typeof(this))(); 424 return ptrcall!(double)(_classBinding.getCurrentAnimationPosition, _godot_object); 425 } 426 /** 427 428 */ 429 double getCurrentAnimationLength() const 430 { 431 checkClassBinding!(typeof(this))(); 432 return ptrcall!(double)(_classBinding.getCurrentAnimationLength, _godot_object); 433 } 434 /** 435 Seek the animation to the `seconds` point in time (in seconds). If `update` is `true`, the animation updates too, otherwise it updates at process time. 436 */ 437 void seek(in double seconds, in bool update = false) 438 { 439 checkClassBinding!(typeof(this))(); 440 ptrcall!(void)(_classBinding.seek, _godot_object, seconds, update); 441 } 442 /** 443 Shifts position in the animation timeline. Delta is the time in seconds to shift. 444 */ 445 void advance(in double delta) 446 { 447 checkClassBinding!(typeof(this))(); 448 ptrcall!(void)(_classBinding.advance, _godot_object, delta); 449 } 450 /** 451 The node from which node path references will travel. Default value: `".."`. 452 */ 453 @property NodePath rootNode() 454 { 455 return getRoot(); 456 } 457 /// ditto 458 @property void rootNode(NodePath v) 459 { 460 setRoot(v); 461 } 462 /** 463 The name of the current animation, "" if not playing anything. When being set, does not restart the animation. See also $(D play). Default value: `""`. 464 */ 465 @property String currentAnimation() 466 { 467 return getCurrentAnimation(); 468 } 469 /// ditto 470 @property void currentAnimation(String v) 471 { 472 setCurrentAnimation(v); 473 } 474 /** 475 If playing, the current animation; otherwise, the animation last played. When set, would change the animation, but would not play it unless currently playing. See also $(D currentAnimation). 476 */ 477 @property String assignedAnimation() 478 { 479 return getAssignedAnimation(); 480 } 481 /// ditto 482 @property void assignedAnimation(String v) 483 { 484 setAssignedAnimation(v); 485 } 486 /** 487 The name of the animation to play when the scene loads. Default value: `""`. 488 */ 489 @property String autoplay() 490 { 491 return getAutoplay(); 492 } 493 /// ditto 494 @property void autoplay(String v) 495 { 496 setAutoplay(v); 497 } 498 /** 499 The length (in seconds) of the currently being played animation. 500 */ 501 @property double currentAnimationLength() 502 { 503 return getCurrentAnimationLength(); 504 } 505 /** 506 The position (in seconds) of the currently playing animation. 507 */ 508 @property double currentAnimationPosition() 509 { 510 return getCurrentAnimationPosition(); 511 } 512 /** 513 The process notification in which to update animations. Default value: `ANIMATION_PROCESS_IDLE`. 514 */ 515 @property AnimationPlayer.AnimationProcessMode playbackProcessMode() 516 { 517 return getAnimationProcessMode(); 518 } 519 /// ditto 520 @property void playbackProcessMode(long v) 521 { 522 setAnimationProcessMode(v); 523 } 524 /** 525 The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision. Default value: `0`. 526 */ 527 @property double playbackDefaultBlendTime() 528 { 529 return getDefaultBlendTime(); 530 } 531 /// ditto 532 @property void playbackDefaultBlendTime(double v) 533 { 534 setDefaultBlendTime(v); 535 } 536 /** 537 If `true`, updates animations in response to process-related notifications. Default value: `true`. 538 */ 539 @property bool playbackActive() 540 { 541 return isActive(); 542 } 543 /// ditto 544 @property void playbackActive(bool v) 545 { 546 setActive(v); 547 } 548 /** 549 The speed scaling ratio. For instance, if this value is 1 then the animation plays at normal speed. If it's 0.5 then it plays at half speed. If it's 2 then it plays at double speed. Default value: `1`. 550 */ 551 @property double playbackSpeed() 552 { 553 return getSpeedScale(); 554 } 555 /// ditto 556 @property void playbackSpeed(double v) 557 { 558 setSpeedScale(v); 559 } 560 }