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.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.node; 25 import godot.animation; 26 /** 27 Container and player of $(D Animation) resources. 28 29 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. 30 $(D AnimationPlayer) is more suited than $(D Tween) for animations where you know the final values in advance. For example, fading a screen in and out is more easily done with an $(D AnimationPlayer) node thanks to the animation tools provided by the editor. That particular example can also be implemented with a $(D Tween) node, but it requires doing everything by code. 31 Updating the target properties of animations occurs at process time. 32 */ 33 @GodotBaseClass struct AnimationPlayer 34 { 35 package(godot) enum string _GODOT_internal_name = "AnimationPlayer"; 36 public: 37 @nogc nothrow: 38 union { /** */ godot_object _godot_object; /** */ Node _GODOT_base; } 39 alias _GODOT_base this; 40 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 41 package(godot) __gshared bool _classBindingInitialized = false; 42 package(godot) static struct GDNativeClassBinding 43 { 44 __gshared: 45 @GodotName("_animation_changed") GodotMethod!(void) _animationChanged; 46 @GodotName("_node_removed") GodotMethod!(void, Node) _nodeRemoved; 47 @GodotName("add_animation") GodotMethod!(GodotError, String, Animation) addAnimation; 48 @GodotName("advance") GodotMethod!(void, double) advance; 49 @GodotName("animation_get_next") GodotMethod!(String, String) animationGetNext; 50 @GodotName("animation_set_next") GodotMethod!(void, String, String) animationSetNext; 51 @GodotName("clear_caches") GodotMethod!(void) clearCaches; 52 @GodotName("clear_queue") GodotMethod!(void) clearQueue; 53 @GodotName("find_animation") GodotMethod!(String, Animation) findAnimation; 54 @GodotName("get_animation") GodotMethod!(Animation, String) getAnimation; 55 @GodotName("get_animation_list") GodotMethod!(PoolStringArray) getAnimationList; 56 @GodotName("get_animation_process_mode") GodotMethod!(AnimationPlayer.AnimationProcessMode) getAnimationProcessMode; 57 @GodotName("get_assigned_animation") GodotMethod!(String) getAssignedAnimation; 58 @GodotName("get_autoplay") GodotMethod!(String) getAutoplay; 59 @GodotName("get_blend_time") GodotMethod!(double, String, String) getBlendTime; 60 @GodotName("get_current_animation") GodotMethod!(String) getCurrentAnimation; 61 @GodotName("get_current_animation_length") GodotMethod!(double) getCurrentAnimationLength; 62 @GodotName("get_current_animation_position") GodotMethod!(double) getCurrentAnimationPosition; 63 @GodotName("get_default_blend_time") GodotMethod!(double) getDefaultBlendTime; 64 @GodotName("get_method_call_mode") GodotMethod!(AnimationPlayer.AnimationMethodCallMode) getMethodCallMode; 65 @GodotName("get_playing_speed") GodotMethod!(double) getPlayingSpeed; 66 @GodotName("get_queue") GodotMethod!(PoolStringArray) getQueue; 67 @GodotName("get_root") GodotMethod!(NodePath) getRoot; 68 @GodotName("get_speed_scale") GodotMethod!(double) getSpeedScale; 69 @GodotName("has_animation") GodotMethod!(bool, String) hasAnimation; 70 @GodotName("is_active") GodotMethod!(bool) isActive; 71 @GodotName("is_playing") GodotMethod!(bool) isPlaying; 72 @GodotName("play") GodotMethod!(void, String, double, double, bool) play; 73 @GodotName("play_backwards") GodotMethod!(void, String, double) playBackwards; 74 @GodotName("queue") GodotMethod!(void, String) queue; 75 @GodotName("remove_animation") GodotMethod!(void, String) removeAnimation; 76 @GodotName("rename_animation") GodotMethod!(void, String, String) renameAnimation; 77 @GodotName("seek") GodotMethod!(void, double, bool) seek; 78 @GodotName("set_active") GodotMethod!(void, bool) setActive; 79 @GodotName("set_animation_process_mode") GodotMethod!(void, long) setAnimationProcessMode; 80 @GodotName("set_assigned_animation") GodotMethod!(void, String) setAssignedAnimation; 81 @GodotName("set_autoplay") GodotMethod!(void, String) setAutoplay; 82 @GodotName("set_blend_time") GodotMethod!(void, String, String, double) setBlendTime; 83 @GodotName("set_current_animation") GodotMethod!(void, String) setCurrentAnimation; 84 @GodotName("set_default_blend_time") GodotMethod!(void, double) setDefaultBlendTime; 85 @GodotName("set_method_call_mode") GodotMethod!(void, long) setMethodCallMode; 86 @GodotName("set_root") GodotMethod!(void, NodePath) setRoot; 87 @GodotName("set_speed_scale") GodotMethod!(void, double) setSpeedScale; 88 @GodotName("stop") GodotMethod!(void, bool) stop; 89 } 90 /// 91 pragma(inline, true) bool opEquals(in AnimationPlayer other) const 92 { return _godot_object.ptr is other._godot_object.ptr; } 93 /// 94 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 95 { _godot_object.ptr = n; return null; } 96 /// 97 pragma(inline, true) bool opEquals(typeof(null) n) const 98 { return _godot_object.ptr is n; } 99 /// 100 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 101 mixin baseCasts; 102 /// Construct a new instance of AnimationPlayer. 103 /// Note: use `memnew!AnimationPlayer` instead. 104 static AnimationPlayer _new() 105 { 106 static godot_class_constructor constructor; 107 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AnimationPlayer"); 108 if(constructor is null) return typeof(this).init; 109 return cast(AnimationPlayer)(constructor()); 110 } 111 @disable new(size_t s); 112 /// 113 enum AnimationProcessMode : int 114 { 115 /** 116 Process animation during the physics process. This is especially useful when animating physics bodies. 117 */ 118 animationProcessPhysics = 0, 119 /** 120 Process animation during the idle process. 121 */ 122 animationProcessIdle = 1, 123 /** 124 Do not process animation. Use $(D advance) to process the animation manually. 125 */ 126 animationProcessManual = 2, 127 } 128 /// 129 enum AnimationMethodCallMode : int 130 { 131 /** 132 Batch method calls during the animation process, then do the calls after events are processed. This avoids bugs involving deleting nodes or modifying the AnimationPlayer while playing. 133 */ 134 animationMethodCallDeferred = 0, 135 /** 136 Make method calls immediately when reached in the animation. 137 */ 138 animationMethodCallImmediate = 1, 139 } 140 /// 141 enum Constants : int 142 { 143 animationProcessPhysics = 0, 144 animationMethodCallDeferred = 0, 145 animationProcessIdle = 1, 146 animationMethodCallImmediate = 1, 147 animationProcessManual = 2, 148 } 149 /** 150 151 */ 152 void _animationChanged() 153 { 154 Array _GODOT_args = Array.make(); 155 String _GODOT_method_name = String("_animation_changed"); 156 this.callv(_GODOT_method_name, _GODOT_args); 157 } 158 /** 159 160 */ 161 void _nodeRemoved(Node arg0) 162 { 163 Array _GODOT_args = Array.make(); 164 _GODOT_args.append(arg0); 165 String _GODOT_method_name = String("_node_removed"); 166 this.callv(_GODOT_method_name, _GODOT_args); 167 } 168 /** 169 Adds `animation` to the player accessible with the key `name`. 170 */ 171 GodotError addAnimation(in String name, Animation animation) 172 { 173 checkClassBinding!(typeof(this))(); 174 return ptrcall!(GodotError)(GDNativeClassBinding.addAnimation, _godot_object, name, animation); 175 } 176 /** 177 Shifts position in the animation timeline and immediately updates the animation. `delta` is the time in seconds to shift. Events between the current frame and `delta` are handled. 178 */ 179 void advance(in double delta) 180 { 181 checkClassBinding!(typeof(this))(); 182 ptrcall!(void)(GDNativeClassBinding.advance, _godot_object, delta); 183 } 184 /** 185 Returns the name of the next animation in the queue. 186 */ 187 String animationGetNext(in String anim_from) const 188 { 189 checkClassBinding!(typeof(this))(); 190 return ptrcall!(String)(GDNativeClassBinding.animationGetNext, _godot_object, anim_from); 191 } 192 /** 193 Triggers the `anim_to` animation when the `anim_from` animation completes. 194 */ 195 void animationSetNext(in String anim_from, in String anim_to) 196 { 197 checkClassBinding!(typeof(this))(); 198 ptrcall!(void)(GDNativeClassBinding.animationSetNext, _godot_object, anim_from, anim_to); 199 } 200 /** 201 $(D AnimationPlayer) caches animated nodes. It may not notice if a node disappears; $(D clearCaches) forces it to update the cache again. 202 */ 203 void clearCaches() 204 { 205 checkClassBinding!(typeof(this))(); 206 ptrcall!(void)(GDNativeClassBinding.clearCaches, _godot_object); 207 } 208 /** 209 Clears all queued, unplayed animations. 210 */ 211 void clearQueue() 212 { 213 checkClassBinding!(typeof(this))(); 214 ptrcall!(void)(GDNativeClassBinding.clearQueue, _godot_object); 215 } 216 /** 217 Returns the name of `animation` or an empty string if not found. 218 */ 219 String findAnimation(Animation animation) const 220 { 221 checkClassBinding!(typeof(this))(); 222 return ptrcall!(String)(GDNativeClassBinding.findAnimation, _godot_object, animation); 223 } 224 /** 225 Returns the $(D Animation) with key `name` or `null` if not found. 226 */ 227 Ref!Animation getAnimation(in String name) const 228 { 229 checkClassBinding!(typeof(this))(); 230 return ptrcall!(Animation)(GDNativeClassBinding.getAnimation, _godot_object, name); 231 } 232 /** 233 Returns the list of stored animation names. 234 */ 235 PoolStringArray getAnimationList() const 236 { 237 checkClassBinding!(typeof(this))(); 238 return ptrcall!(PoolStringArray)(GDNativeClassBinding.getAnimationList, _godot_object); 239 } 240 /** 241 242 */ 243 AnimationPlayer.AnimationProcessMode getAnimationProcessMode() const 244 { 245 checkClassBinding!(typeof(this))(); 246 return ptrcall!(AnimationPlayer.AnimationProcessMode)(GDNativeClassBinding.getAnimationProcessMode, _godot_object); 247 } 248 /** 249 250 */ 251 String getAssignedAnimation() const 252 { 253 checkClassBinding!(typeof(this))(); 254 return ptrcall!(String)(GDNativeClassBinding.getAssignedAnimation, _godot_object); 255 } 256 /** 257 258 */ 259 String getAutoplay() const 260 { 261 checkClassBinding!(typeof(this))(); 262 return ptrcall!(String)(GDNativeClassBinding.getAutoplay, _godot_object); 263 } 264 /** 265 Gets the blend time (in seconds) between two animations, referenced by their names. 266 */ 267 double getBlendTime(in String anim_from, in String anim_to) const 268 { 269 checkClassBinding!(typeof(this))(); 270 return ptrcall!(double)(GDNativeClassBinding.getBlendTime, _godot_object, anim_from, anim_to); 271 } 272 /** 273 274 */ 275 String getCurrentAnimation() const 276 { 277 checkClassBinding!(typeof(this))(); 278 return ptrcall!(String)(GDNativeClassBinding.getCurrentAnimation, _godot_object); 279 } 280 /** 281 282 */ 283 double getCurrentAnimationLength() const 284 { 285 checkClassBinding!(typeof(this))(); 286 return ptrcall!(double)(GDNativeClassBinding.getCurrentAnimationLength, _godot_object); 287 } 288 /** 289 290 */ 291 double getCurrentAnimationPosition() const 292 { 293 checkClassBinding!(typeof(this))(); 294 return ptrcall!(double)(GDNativeClassBinding.getCurrentAnimationPosition, _godot_object); 295 } 296 /** 297 298 */ 299 double getDefaultBlendTime() const 300 { 301 checkClassBinding!(typeof(this))(); 302 return ptrcall!(double)(GDNativeClassBinding.getDefaultBlendTime, _godot_object); 303 } 304 /** 305 306 */ 307 AnimationPlayer.AnimationMethodCallMode getMethodCallMode() const 308 { 309 checkClassBinding!(typeof(this))(); 310 return ptrcall!(AnimationPlayer.AnimationMethodCallMode)(GDNativeClassBinding.getMethodCallMode, _godot_object); 311 } 312 /** 313 Gets the actual playing speed of current animation or 0 if not playing. This speed is the $(D playbackSpeed) property multiplied by `custom_speed` argument specified when calling the $(D play) method. 314 */ 315 double getPlayingSpeed() const 316 { 317 checkClassBinding!(typeof(this))(); 318 return ptrcall!(double)(GDNativeClassBinding.getPlayingSpeed, _godot_object); 319 } 320 /** 321 Returns a list of the animation names that are currently queued to play. 322 */ 323 PoolStringArray getQueue() 324 { 325 checkClassBinding!(typeof(this))(); 326 return ptrcall!(PoolStringArray)(GDNativeClassBinding.getQueue, _godot_object); 327 } 328 /** 329 330 */ 331 NodePath getRoot() const 332 { 333 checkClassBinding!(typeof(this))(); 334 return ptrcall!(NodePath)(GDNativeClassBinding.getRoot, _godot_object); 335 } 336 /** 337 338 */ 339 double getSpeedScale() const 340 { 341 checkClassBinding!(typeof(this))(); 342 return ptrcall!(double)(GDNativeClassBinding.getSpeedScale, _godot_object); 343 } 344 /** 345 Returns `true` if the $(D AnimationPlayer) stores an $(D Animation) with key `name`. 346 */ 347 bool hasAnimation(in String name) const 348 { 349 checkClassBinding!(typeof(this))(); 350 return ptrcall!(bool)(GDNativeClassBinding.hasAnimation, _godot_object, name); 351 } 352 /** 353 354 */ 355 bool isActive() const 356 { 357 checkClassBinding!(typeof(this))(); 358 return ptrcall!(bool)(GDNativeClassBinding.isActive, _godot_object); 359 } 360 /** 361 Returns `true` if playing an animation. 362 */ 363 bool isPlaying() const 364 { 365 checkClassBinding!(typeof(this))(); 366 return ptrcall!(bool)(GDNativeClassBinding.isPlaying, _godot_object); 367 } 368 /** 369 Plays the animation with key `name`. Custom blend times and speed can be set. If `custom_speed` is negative and `from_end` is `true`, the animation will play backwards (which is equivalent to calling $(D playBackwards)). 370 The $(D AnimationPlayer) keeps track of its current or last played animation with $(D assignedAnimation). If this method is called with that same animation `name`, or with no `name` parameter, the assigned animation will resume playing if it was paused, or restart if it was stopped (see $(D stop) for both pause and stop). If the animation was already playing, it will keep playing. 371 $(B Note:) The animation will be updated the next time the $(D AnimationPlayer) is processed. If other variables are updated at the same time this is called, they may be updated too early. To perform the update immediately, call `advance(0)`. 372 */ 373 void play(in String name = gs!"", in double custom_blend = -1, in double custom_speed = 1, in bool from_end = false) 374 { 375 checkClassBinding!(typeof(this))(); 376 ptrcall!(void)(GDNativeClassBinding.play, _godot_object, name, custom_blend, custom_speed, from_end); 377 } 378 /** 379 Plays the animation with key `name` in reverse. 380 This method is a shorthand for $(D play) with `custom_speed = -1.0` and `from_end = true`, so see its description for more information. 381 */ 382 void playBackwards(in String name = gs!"", in double custom_blend = -1) 383 { 384 checkClassBinding!(typeof(this))(); 385 ptrcall!(void)(GDNativeClassBinding.playBackwards, _godot_object, name, custom_blend); 386 } 387 /** 388 Queues an animation for playback once the current one is done. 389 $(B Note:) If a looped animation is currently playing, the queued animation will never play unless the looped animation is stopped somehow. 390 */ 391 void queue(in String name) 392 { 393 checkClassBinding!(typeof(this))(); 394 ptrcall!(void)(GDNativeClassBinding.queue, _godot_object, name); 395 } 396 /** 397 Removes the animation with key `name`. 398 */ 399 void removeAnimation(in String name) 400 { 401 checkClassBinding!(typeof(this))(); 402 ptrcall!(void)(GDNativeClassBinding.removeAnimation, _godot_object, name); 403 } 404 /** 405 Renames an existing animation with key `name` to `newname`. 406 */ 407 void renameAnimation(in String name, in String newname) 408 { 409 checkClassBinding!(typeof(this))(); 410 ptrcall!(void)(GDNativeClassBinding.renameAnimation, _godot_object, name, newname); 411 } 412 /** 413 Seeks the animation to the `seconds` point in time (in seconds). If `update` is `true`, the animation updates too, otherwise it updates at process time. Events between the current frame and `seconds` are skipped. 414 */ 415 void seek(in double seconds, in bool update = false) 416 { 417 checkClassBinding!(typeof(this))(); 418 ptrcall!(void)(GDNativeClassBinding.seek, _godot_object, seconds, update); 419 } 420 /** 421 422 */ 423 void setActive(in bool active) 424 { 425 checkClassBinding!(typeof(this))(); 426 ptrcall!(void)(GDNativeClassBinding.setActive, _godot_object, active); 427 } 428 /** 429 430 */ 431 void setAnimationProcessMode(in long mode) 432 { 433 checkClassBinding!(typeof(this))(); 434 ptrcall!(void)(GDNativeClassBinding.setAnimationProcessMode, _godot_object, mode); 435 } 436 /** 437 438 */ 439 void setAssignedAnimation(in String anim) 440 { 441 checkClassBinding!(typeof(this))(); 442 ptrcall!(void)(GDNativeClassBinding.setAssignedAnimation, _godot_object, anim); 443 } 444 /** 445 446 */ 447 void setAutoplay(in String name) 448 { 449 checkClassBinding!(typeof(this))(); 450 ptrcall!(void)(GDNativeClassBinding.setAutoplay, _godot_object, name); 451 } 452 /** 453 Specifies a blend time (in seconds) between two animations, referenced by their names. 454 */ 455 void setBlendTime(in String anim_from, in String anim_to, in double sec) 456 { 457 checkClassBinding!(typeof(this))(); 458 ptrcall!(void)(GDNativeClassBinding.setBlendTime, _godot_object, anim_from, anim_to, sec); 459 } 460 /** 461 462 */ 463 void setCurrentAnimation(in String anim) 464 { 465 checkClassBinding!(typeof(this))(); 466 ptrcall!(void)(GDNativeClassBinding.setCurrentAnimation, _godot_object, anim); 467 } 468 /** 469 470 */ 471 void setDefaultBlendTime(in double sec) 472 { 473 checkClassBinding!(typeof(this))(); 474 ptrcall!(void)(GDNativeClassBinding.setDefaultBlendTime, _godot_object, sec); 475 } 476 /** 477 478 */ 479 void setMethodCallMode(in long mode) 480 { 481 checkClassBinding!(typeof(this))(); 482 ptrcall!(void)(GDNativeClassBinding.setMethodCallMode, _godot_object, mode); 483 } 484 /** 485 486 */ 487 void setRoot(NodePathArg0)(in NodePathArg0 path) 488 { 489 checkClassBinding!(typeof(this))(); 490 ptrcall!(void)(GDNativeClassBinding.setRoot, _godot_object, path); 491 } 492 /** 493 494 */ 495 void setSpeedScale(in double speed) 496 { 497 checkClassBinding!(typeof(this))(); 498 ptrcall!(void)(GDNativeClassBinding.setSpeedScale, _godot_object, speed); 499 } 500 /** 501 Stops or pauses the currently playing animation. If `reset` is `true`, the animation position is reset to `0` and the playback speed is reset to `1.0`. 502 If `reset` is `false`, the $(D currentAnimationPosition) will be kept and calling $(D play) or $(D playBackwards) without arguments or with the same animation name as $(D assignedAnimation) will resume the animation. 503 */ 504 void stop(in bool reset = true) 505 { 506 checkClassBinding!(typeof(this))(); 507 ptrcall!(void)(GDNativeClassBinding.stop, _godot_object, reset); 508 } 509 /** 510 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). 511 */ 512 @property String assignedAnimation() 513 { 514 return getAssignedAnimation(); 515 } 516 /// ditto 517 @property void assignedAnimation(String v) 518 { 519 setAssignedAnimation(v); 520 } 521 /** 522 The name of the animation to play when the scene loads. 523 */ 524 @property String autoplay() 525 { 526 return getAutoplay(); 527 } 528 /// ditto 529 @property void autoplay(String v) 530 { 531 setAutoplay(v); 532 } 533 /** 534 The name of the currently playing animation. If no animation is playing, the property's value is an empty string. Changing this value does not restart the animation. See $(D play) for more information on playing animations. 535 $(B Note): while this property appears in the inspector, it's not meant to be edited, and it's not saved in the scene. This property is mainly used to get the currently playing animation, and internally for animation playback tracks. For more information, see $(D Animation). 536 */ 537 @property String currentAnimation() 538 { 539 return getCurrentAnimation(); 540 } 541 /// ditto 542 @property void currentAnimation(String v) 543 { 544 setCurrentAnimation(v); 545 } 546 /** 547 The length (in seconds) of the currently being played animation. 548 */ 549 @property double currentAnimationLength() 550 { 551 return getCurrentAnimationLength(); 552 } 553 /** 554 The position (in seconds) of the currently playing animation. 555 */ 556 @property double currentAnimationPosition() 557 { 558 return getCurrentAnimationPosition(); 559 } 560 /** 561 The call mode to use for Call Method tracks. 562 */ 563 @property AnimationPlayer.AnimationMethodCallMode methodCallMode() 564 { 565 return getMethodCallMode(); 566 } 567 /// ditto 568 @property void methodCallMode(long v) 569 { 570 setMethodCallMode(v); 571 } 572 /** 573 If `true`, updates animations in response to process-related notifications. 574 */ 575 @property bool playbackActive() 576 { 577 return isActive(); 578 } 579 /// ditto 580 @property void playbackActive(bool v) 581 { 582 setActive(v); 583 } 584 /** 585 The default time in which to blend animations. Ranges from 0 to 4096 with 0.01 precision. 586 */ 587 @property double playbackDefaultBlendTime() 588 { 589 return getDefaultBlendTime(); 590 } 591 /// ditto 592 @property void playbackDefaultBlendTime(double v) 593 { 594 setDefaultBlendTime(v); 595 } 596 /** 597 The process notification in which to update animations. 598 */ 599 @property AnimationPlayer.AnimationProcessMode playbackProcessMode() 600 { 601 return getAnimationProcessMode(); 602 } 603 /// ditto 604 @property void playbackProcessMode(long v) 605 { 606 setAnimationProcessMode(v); 607 } 608 /** 609 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. 610 */ 611 @property double playbackSpeed() 612 { 613 return getSpeedScale(); 614 } 615 /// ditto 616 @property void playbackSpeed(double v) 617 { 618 setSpeedScale(v); 619 } 620 /** 621 The node from which node path references will travel. 622 */ 623 @property NodePath rootNode() 624 { 625 return getRoot(); 626 } 627 /// ditto 628 @property void rootNode(NodePath v) 629 { 630 setRoot(v); 631 } 632 }