//=================================================================================================
// Loop_Animation.js
//=================================================================================================
/*:
* @plugindesc 循环动画。
* @author 芯☆淡茹水
* @help
* 
* Sprite_Base 以及其子类,皆可以播放循环动画,以下代称为 objSprite 。
*
* 开始循环动画: objSprite.startLoopAnimation(animationId, mirror, delay);
* animationId :动画ID。
* mirror :是否镜像。
* delay :延迟帧数。
*
* 停止循环动画: objSprite.stopLoopAnimation(animationId);
*
* 是否正在播放某个循环动画: objSprite.isLoopAnimationPlaying(animationId);
*
*/
//=================================================================================================
;(function(){
//=================================================================================================
var Sprite_Base_initialize = Sprite_Base.prototype.initialize;
Sprite_Base.prototype.initialize = function() {
    Sprite_Base_initialize.call(this);
    this._loopAnimationSprites = [];
};
Sprite_Base.prototype.startLoopAnimation = function(animationId, mirror, delay) {
    if (!$dataAnimations[animationId] || this.isLoopAnimationPlaying(animationId)) return;
    var sprite = new Sprite_LoopAnimation();
    sprite.setup(this._effectTarget, animationId, mirror, delay);
    this.parent.addChild(sprite);
    this._loopAnimationSprites.push(sprite);
};
Sprite_Base.prototype.stopLoopAnimation = function(animationId) {
    var anmSprite = this._loopAnimationSprites.filter(function(sprite){
        return sprite.id() === animationId;
    }).shift();
    if (anmSprite) {
        var index = this._loopAnimationSprites.indexOf(anmSprite);
        anmSprite.remove();
        this._loopAnimationSprites.splice(index, 1);
    }
};
Sprite_Base.prototype.isLoopAnimationPlaying = function(animationId) {
    return this._loopAnimationSprites.some(function(anmSprite){
        return anmSprite.id() === animationId;
    });
};
//=================================================================================================
function Sprite_LoopAnimation() {
    this.initialize.apply(this, arguments);
}
Sprite_LoopAnimation.prototype = Object.create(Sprite_Animation.prototype);
Sprite_LoopAnimation.prototype.constructor = Sprite_LoopAnimation;
Sprite_LoopAnimation.prototype.id = function() {
    return this._animationId;
};
Sprite_LoopAnimation.prototype.setup = function(target, animationId, mirror, delay) {
    this._animationId = animationId;
    var animation = $dataAnimations[animationId];
    Sprite_Animation.prototype.setup.call(this, target, animation, mirror, delay);
};
Sprite_LoopAnimation.prototype.isPlaying = function() {
    return true;
};
Sprite_LoopAnimation.prototype.updateMain = function() {
    if (this._duration <= 0) {
        this._target.setBlendColor([0, 0, 0, 0]);
        this._target.show();
        this.setupDuration();
    } else Sprite_Animation.prototype.updateMain.call(this);
};
//=================================================================================================
}()); // end
//=================================================================================================