Advertisement
WCouillard

Coolie_IndividualAnimDimensions

Sep 21st, 2021 (edited)
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Coolie_IndividualAnimDimensions.js
  3. //=============================================================================
  4. var Imported = Imported || {};
  5. Imported.Coolie_IndividualAnimDimensions = true;
  6.  
  7. var Coolie = Coolie || {};
  8. Coolie.IAD = Coolie.IAD || {};
  9. Coolie.IAD.version = 1.00;
  10.  
  11. /*:
  12.  * @plugindesc v1.0 Coolie Individual Anim Dimensions
  13.  *      Special thanks to caethyril
  14.  *
  15.  * @author Coolie, caethyril
  16.  *
  17.  * @help
  18.  * ---------------------------------------------------------------------
  19.  * Coolie's Individual Animation Dimensions
  20.  * ---------------------------------------------------------------------
  21.  * RPG Maker MV forces a very small 192x192 size for each cell in an
  22.  * animation. This is way too small for an engine that allows us to make
  23.  * games with much higher resolutions.
  24.  *
  25.  * This plugin allows you to set the width and height of the animation
  26.  * cells in individual animations in your database, so you can use anims
  27.  * with cell sizes bigger (or smaller) than 192x192.
  28.  *
  29.  * Keep in mind, each cell must be the same width and height on BOTH
  30.  * animation files used to create the animation.
  31.  *
  32.  * When the notetag to customize the animation size does not exist, the
  33.  * animation will use the default 192x192 cell size, so the default RMMV
  34.  * animations will not be ruined.
  35.  *
  36.  * ---------------------------------------------------------------------
  37.  * NOTETAG (ANIMATION NAME)
  38.  * ---------------------------------------------------------------------
  39.  *
  40.  * YourAnimationName<iad:W,H,[+/-]X,[+/-]Y>
  41.  *
  42.  *  Just like this, do not use any spaces!
  43.  *
  44.  *  W = the width of the animation cells for this animation (i.e. 256)
  45.  *  H = the height of the animation cells for this animation (i.e. 128)
  46.  *  X = the X offset of the animation, in case the editor doesn't allow
  47.  *      you to get it in the perfect position. Needs a + or - before it.
  48.  *  Y = the Y offset of the animation, in case the editor doesn't allow
  49.  *      you to get it in the perfect position. Needs a + or - before it.
  50.  *
  51.  * Example of an Animation name that would utilize this plugin:
  52.  *
  53.  *  Fire<iad:256,128,+45,-36>
  54.  *
  55.  * The above example would expect an animation sheet of...
  56.  * - Five columns at a width of 256 each, or 1,280 pixels wide
  57.  * - Image height equaling 128 * the number of rows in the image file
  58.  * - For a 60 cell anim, this would be 12 rows of 5, or 1,536 pixels
  59.  *   high.
  60.  * In-game...
  61.  * - The animation would be placed in-game +45 pixels from its X position
  62.  *   in the MV editor.
  63.  * - The animation would be placed in-game -36 pixels from its Y position
  64.  *   in the MV editor.
  65.  * - TIP! You can leave your animation at X/Y 0/0 in the editor and use
  66.  *   the notetag on the name to position your animation anywhere on the
  67.  *   screen!
  68.  * - TIP! It may also be a good idea to always make each cell have an
  69.  *   EVEN value (i.e. 500x250 rather than 501x249) to ensure that the anim
  70.  *   is always properly centered where it is placed. Not required, though!
  71.  *
  72.  * ---------------------------------------------------------------------
  73.  * IMPORTANT NOTE
  74.  * ---------------------------------------------------------------------
  75.  * The RPG Maker MV editor cannot tell that you are using a bigger or
  76.  * smaller cell size for your animations. It will likely take trial and
  77.  * error or an outside application to be able to properly set up your
  78.  * animations that use these tags, such as GIMP or Photoshop.
  79.  *
  80.  * Accompanying this plugin with Tsukimi's 'AnimationFrameRate' plugin
  81.  * will allow you to slow your animations down enough by adding a '%' to
  82.  * the name of your animations, to see where to properly shift the X/Y
  83.  * value of the animation to get it in the right place on your game's
  84.  * screen. After it's set, you can remove the '%' from your animation
  85.  * name to get it back to its normal speed, or speed it up with another
  86.  * tag.
  87.  *
  88.  * Example:
  89.  *
  90.  * %Fire<iad:256,128,+45,-36>
  91.  *
  92.  * ---------------------------------------------------------------------
  93.  * COMPATIBILITY
  94.  * ---------------------------------------------------------------------
  95.  * This plugin was written for RPG Maker MV version 1.5.1!
  96.  *  - It may not work with earlier versions, which are unsupported.
  97.  *  - Please make sure you are using version 1.5.1 before making a bug
  98.  *    report.
  99.  *
  100.  * This plugin only overwrites one function:
  101.  *
  102.  *   Sprite_Animation.prototype.updateCellSprite
  103.  *
  104.  * If you have any other plugins that also overwrites this function, you
  105.  * may have some issues with using this plugin. I will try my best to
  106.  * patch for compatibility.
  107.  *
  108.  * ---------------------------------------------------------------------
  109.  * TERMS OF USE
  110.  * ---------------------------------------------------------------------
  111.  * It is OK to use this plugin in both commercial and non-commercial
  112.  * projects.
  113.  *
  114.  * Credit is appreciated, but not required. The individuals who made
  115.  * this plugin, if you wish to credit them, are:
  116.  *
  117.  * - Coolie (William Couillard)
  118.  *    * Plugin author
  119.  * - caethyril
  120.  *    * Assistance with notetags
  121.  *
  122.  * ---------------------------------------------------------------------
  123.  */
  124.  
  125. (function() {
  126. 'use strict';
  127.     const alias = Scene_Boot.prototype.start;
  128.     Scene_Boot.prototype.start = function() {
  129.         $dataAnimations.forEach(function(obj, id) {
  130.             if (obj) {
  131.             const iad_note = /<iad:(\d+),(\d+),([\+\-]\d+),([\+\-]\d+)>/.exec(obj.name);
  132.                 if (iad_note !== null) {
  133.                     obj.meta || (obj.meta = {});
  134.                     obj.meta.iad = [iad_note[1], iad_note[2], iad_note[3], iad_note[4]];
  135.                     obj.meta.iad = [parseInt(iad_note[1], 10), parseInt(iad_note[2], 10), parseInt(iad_note[3], 10), parseInt(iad_note[4], 10)];
  136.                 }
  137.             }
  138.         });
  139.         alias.apply(this, arguments);
  140.     };
  141. })();
  142.      
  143. Sprite_Animation.prototype.updateCellSprite = function(sprite, cell) {
  144.     var pattern = cell[0];
  145.     if (pattern >= 0) {
  146.         if (this._animation.meta && this._animation.meta.iad) {
  147.             var iad_w = this._animation.meta.iad[0];
  148.             var iad_h = this._animation.meta.iad[1];
  149.             var iad_x = this._animation.meta.iad[2];
  150.             var iad_y = this._animation.meta.iad[3];
  151.             var sx = pattern % 5 * iad_w;
  152.             var sy = Math.floor(pattern % 100 / 5) * iad_h;
  153.         } else {
  154.             var sx = pattern % 5 * 192;
  155.             var sy = Math.floor(pattern % 100 / 5) * 192;
  156.         }
  157.        
  158.         var mirror = this._mirror;
  159.         sprite.bitmap = pattern < 100 ? this._bitmap1 : this._bitmap2;
  160.        
  161.         if (this._animation.meta && this._animation.meta.iad) {
  162.             sprite.setFrame(sx, sy, iad_w, iad_h);
  163.             sprite.x = cell[1] + iad_x;
  164.             sprite.y = cell[2] + iad_y;
  165.         } else {
  166.             sprite.setFrame(sx, sy, 192, 192);
  167.             sprite.x = cell[1];
  168.             sprite.y = cell[2];
  169.         }
  170.        
  171.         sprite.rotation = cell[4] * Math.PI / 180;
  172.         sprite.scale.x = cell[3] / 100;
  173.  
  174.         if(cell[5]){
  175.             sprite.scale.x *= -1;
  176.         }
  177.         if(mirror){
  178.             sprite.x *= -1;
  179.             sprite.rotation *= -1;
  180.             sprite.scale.x *= -1;
  181.         }
  182.  
  183.         sprite.scale.y = cell[3] / 100;
  184.         sprite.opacity = cell[6];
  185.         sprite.blendMode = cell[7];
  186.         sprite.visible = true;
  187.     } else {
  188.         sprite.visible = false;
  189.     }
  190. };
Tags: Plugin js RMMV
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement