//=============================================================================
// Character Still Pose
// by ProGM
// Last Updated: 2015.09.21
//=============================================================================

/*:
 * @plugindesc Allows more than 3 Frames
 * @author Shaz
 *
 * @help This plugin does not provide plugin commands.
 *
 * Add [D L R U] to your character sheet name (with $ prefix) to specify haw
 * many frames in each direction (Down, Left, Right, Up).
 * Spritesheets with this added to the file name will use a looping frame
 * animation rather than the back-and-forth default animation.
 *
 * The first frame should be the idle/still pose.
 *
 * eg. $Ralph [8 8 8 8].png
 *     is a character sheet consisting of 4 rows with 8 frames per row.
 *     Animation will go from frame 1 to 8 then start at 1 again.
 */

(function() {

  ImageManager.isDirectAnimation = function(filename) {
      var sign = filename.match(/^\[\]/);
      return sign && sign[0].contains('[]');
  };

  var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
  Game_CharacterBase.initMembers = function() {
    _Game_CharacterBase_initMembers.call(this);
    this._isDirectAnimation = false;
  };

  var _Game_CharacterBase_maxPattern = Game_CharacterBase.prototype.pattern;
  Game_CharacterBase.prototype.maxPattern = function() {
    if (this._isDirectAnimation) {
      return 3;
    } else {
      _Game_CharacterBase_maxPattern.call(this);
    }
  };

  var _Game_CharacterBase_setImage = Game_CharacterBase.prototype.setImage;
  Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
    _Game_CharacterBase_setImage.call(this, characterName, characterIndex);
    this._isDirectAnimation = ImageManager.isDirectAnimation(characterName);
  };

  var _Game_CharacterBase_setTileImage = Game_CharacterBase.prototype.setTileImage;
  Game_CharacterBase.prototype.setTileImage = function(tileId) {
    _Game_CharacterBase_setTileImage.call(this, tileId);
    this._isDirectAnimation = false;
  };

})();