AnimationController.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * AnimationController.js
  3. *
  4. * @author realor
  5. */
  6. import { Controller } from './Controller.js'
  7. class AnimationController extends Controller {
  8. constructor(object, name) {
  9. super(object, name)
  10. this.input = 0
  11. this._animating = false
  12. this._animate = this.animate.bind(this)
  13. this._onNodeChanged = this.onNodeChanged.bind(this)
  14. }
  15. onStart() {
  16. const application = this.application
  17. application.addEventListener('scene', this._onNodeChanged)
  18. this.startAnimation()
  19. }
  20. onStop() {
  21. const application = this.application
  22. application.removeEventListener('scene', this._onNodeChanged)
  23. this.stopAnimation()
  24. }
  25. startAnimation() {
  26. if (!this._animating) {
  27. this._animating = true
  28. this.application.addEventListener('animation', this._animate)
  29. }
  30. }
  31. stopAnimation() {
  32. if (this._animating) {
  33. this._animating = false
  34. this.application.removeEventListener('animation', this._animate)
  35. }
  36. }
  37. animate(event) {}
  38. onNodeChanged(event) {
  39. if (event.type === 'nodeChanged' && this.hasChanged(event)) {
  40. this.startAnimation()
  41. }
  42. }
  43. }
  44. export { AnimationController }