ezmash

More Character Frames (MV)

Oct 24th, 2015
7,502
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // More Character Frames
  3. // by Shaz
  4. // Last Updated: 2015.09.21
  5. //=============================================================================
  6.  
  7. /*:
  8.  * @plugindesc Allows more than 3 Frames
  9.  * @author Shaz
  10.  *
  11.  * @help This plugin does not provide plugin commands.
  12.  *
  13.  * Add [D L R U] to your character sheet name (with $ prefix) to specify haw
  14.  * many frames in each direction (Down, Left, Right, Up).
  15.  * Spritesheets with this added to the file name will use a looping frame
  16.  * animation rather than the back-and-forth default animation.
  17.  *
  18.  * The first frame should be the idle/still pose.
  19.  *
  20.  * eg. $Ralph [8 8 8 8].png
  21.  *     is a character sheet consisting of 4 rows with 8 frames per row.
  22.  *     Animation will go from frame 1 to 8 then start at 1 again.
  23.  */
  24.  
  25. (function() {
  26.  
  27.   ImageManager.isMultiFrameCharacter = function(filename) {
  28.     var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
  29.     return frames && frames.length === 5;
  30.   };
  31.  
  32.   ImageManager.getCharacterFrameCount = function(filename) {
  33.     var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
  34.     if (!frames) {
  35.       return [3, 3, 3, 3];
  36.     } else {
  37.       return frames.splice(1, 4);
  38.     }
  39.   };
  40.  
  41.   var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
  42.   Game_CharacterBase.initMembers = function() {
  43.     _Game_CharacterBase_initMembers.call(this);
  44.     this._isMultiFrame = false;
  45.     this._frames = [3, 3, 3, 3];
  46.   };
  47.  
  48.   var _Game_CharacterBase_maxPattern = Game_CharacterBase.prototype.maxPattern;
  49.   Game_CharacterBase.prototype.maxPattern = function() {
  50.     if (!this._isMultiFrame) {
  51.       return _Game_CharacterBase_maxPattern.call(this);
  52.     } else {
  53.       return this._frames[(this._direction / 2) - 1];
  54.     }
  55.   };
  56.  
  57.   var _Game_CharacterBase_pattern = Game_CharacterBase.prototype.pattern;
  58.   Game_CharacterBase.prototype.pattern = function() {
  59.     if (!this._isMultiFrame) {
  60.       return _Game_CharacterBase_pattern.call(this);
  61.     } else {
  62.       return this._pattern < this._frames[this._direction / 2 - 1] ? this._pattern : 0;
  63.     }
  64.   };
  65.  
  66.   var _Game_CharacterBase_isOriginalPattern = Game_CharacterBase.prototype.isOriginalPattern;
  67.   Game_CharacterBase.prototype.isOriginalPattern = function() {
  68.     if (!this._isMultiFrame) {
  69.       return _Game_CharacterBase_isOriginalPattern.call(this);
  70.     } else {
  71.       return this.pattern() === 0;
  72.     }
  73.   };
  74.  
  75.   var _Game_CharacterBase_resetPattern = Game_CharacterBase.prototype.resetPattern;
  76.   Game_CharacterBase.prototype.resetPattern = function() {
  77.     if (!this._isMultiFrame) {
  78.       _Game_CharacterBase_resetPattern.call(this);
  79.     } else {
  80.       this.setPattern(0);
  81.     }
  82.   };
  83.  
  84.   var _Game_CharacterBase_setImage = Game_CharacterBase.prototype.setImage;
  85.   Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
  86.     _Game_CharacterBase_setImage.call(this, characterName, characterIndex);
  87.     this._isMultiFrame = ImageManager.isMultiFrameCharacter(characterName);
  88.     this._frames = ImageManager.getCharacterFrameCount(characterName);
  89.   };
  90.  
  91.   var _Game_CharacterBase_setTileImage = Game_CharacterBase.prototype.setTileImage;
  92.   Game_CharacterBase.prototype.setTileImage = function(tileId) {
  93.     _Game_CharacterBase_setTileImage.call(this, tileId);
  94.     this._isMultiFrame = false;
  95.     this._frames = [3, 3, 3, 3];
  96.   };
  97.  
  98.   Game_CharacterBase.prototype.isMultiFrame = function() {
  99.     return this._isMultiFrame;
  100.   };
  101.  
  102.   Game_CharacterBase.prototype.getDirectionFrames = function() {
  103.     return this._frames[this._direction / 2 - 1];
  104.   };
  105.  
  106.   var _Game_Event_initMembers = Game_Event.prototype.initMembers;
  107.   Game_Event.prototype.initMembers = function() {
  108.     _Game_Event_initMembers.call(this);
  109.     if (this._isMultiFrame) {
  110.       this._originalPattern = 0;
  111.     }
  112.   };
  113.  
  114.   var _Sprite_Character_patternWidth = Sprite_Character.prototype.patternWidth;
  115.   Sprite_Character.prototype.patternWidth = function() {
  116.     if (!this._character.isMultiFrame()) {
  117.       return _Sprite_Character_patternWidth.call(this);
  118.     } else {
  119.       return this.bitmap.width / this._character.getDirectionFrames();
  120.     }
  121.   };
  122.  
  123. })();
RAW Paste Data