playNextAnimation()

in src/core/animpack/AnimationFeature.js [1117:1166]


  playNextAnimation(layerName, animationName, transitionTime, easingFn) {
    const layer = this._layerMap[layerName];

    if (layer === undefined) {
      const e = `Cannot play next animation on layer ${layerName} for host ${this._host.id}. No layer exists with this name.`;
      return Deferred.reject(e);
    }

    if (animationName === undefined) {
      animationName = layer.currentAnimation;
    }

    const animation = layer.getState(layer.currentAnimation);

    if (animation === null) {
      const e = `Cannot play next animation on layer ${layerName} for host ${this._host.id}. No animation exists with name ${animationName}.`;
      return Deferred.reject(e);
    } else if (this.getAnimationType(layerName, animationName) !== 'queue') {
      const e = `Cannot play next animation on layer ${layerName} for host ${this._host.id}. ${animationName} is not a queue state.`;
      return Deferred.reject(e);
    }

    const onNext = ({name, canAdvance, isQueueEnd}) => {
      if (layer.currentAnimation === animationName) {
        // Notify that a new animation has begun
        this.emit(this.constructor.EVENTS.playNextAnimation, {
          layerName,
          animationName,
          nextQueuedAnimation: name,
          canAdvance,
          isQueueEnd,
        });
      }
    };

    // Make the queue animation current if it wasn't already
    if (layer.currentAnimation === null) {
      layer.resumeAnimation(
        animation.name,
        transitionTime,
        easingFn,
        undefined,
        undefined,
        undefined,
        onNext
      );
    }

    return animation.next(onNext, true);
  }