Advertisement
ezmash

Neon Black's Large Sprite Fix (MV)

Nov 12th, 2015
2,800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * @plugindesc Fixes an issue with large sprites appearing under ☆ passability tiles.
  3.  * @author Neon Black - Version 1.0
  4.  *
  5.  * @help Large Sprite ☆ Fix v1.0
  6.  *
  7.  * V1.0 - 8.11.2015
  8.  * V1.1 - 10.28.2015 Shaz fixed issue with incorrect bitmap dimensions
  9.  *
  10.  * This plugin was created to fix an issue similar to the fix applied in Ace
  11.  * where large sprites would display under ☆ passability tiles when they should
  12.  * appear above them.  This plugin is for the most part non-intrusive but does
  13.  * require a little bit of input from the user.
  14.  *
  15.  * By default, only the player is affected by this plugin.  To apply this fix to
  16.  * an event, add the tag <large sprite> to a comment box in the page of the
  17.  * event you would like to appear above ☆ tiles properly.
  18.  *
  19.  * This work by Neon Black is licensed under a Creative Commons Attribution 4.0
  20.  * International License.  To view a copy of this license, visit
  21.  * http://creativecommons.org/licenses/by/4.0/.  Permissions beyond the scope of
  22.  * this license may be available at neonblack.moe/terms.
  23.  *
  24.  * @param Terrain ID
  25.  * @desc This is the ID of the terrain to fix with ☆ tiles.  Terrain ID is set in the database.
  26.  * @default 7
  27.  *
  28.  * @param Large Followers
  29.  * @desc Enable this option to perform large sprite checking on followers.  Disabled by default.
  30.  * @default No
  31.  *
  32.  * @param Large Vehicles
  33.  * @desc Enable this option to perform large sprite checking on vehicles.  Enabled by default.
  34.  * @default Yes
  35.  */
  36.  
  37.  
  38.  
  39. //------
  40. // The following lines are the actual core code of the plugin.  While you are
  41. // certainly invited to look, modifying it may result in undesirable results.
  42. // Modify at your own risk!
  43. //------
  44.  
  45.  
  46.  
  47. //------
  48. // Imported and namespace
  49. //------
  50. var Imported = Imported || {};
  51. Imported.CP_LargeSpriteFix = 1.0;
  52.  
  53. var cpp = cpp || {};
  54. cpp.yyt = ['yes', 'y', 'true'];
  55. cpp.lsdf = cpp.lsdf || {};
  56.  
  57. cpp.lsdf.params    = PluginManager.parameters('CP_Large_Sprite_Fix');
  58. cpp.lsdf.terrain   = cpp.lsdf.params['Terrain ID'];
  59. cpp.lsdf.followers = cpp.yyt.indexOf(cpp.lsdf.params['Large Followers'].toLowerCase()) >= 0;
  60. cpp.lsdf.vehicles  = cpp.yyt.indexOf(cpp.lsdf.params['Large Vehicles'].toLowerCase()) >= 0;
  61.  
  62. //------
  63. // Alias functions
  64. //------
  65. var aliasUpdateBitmap081115a   = Sprite_Character.prototype.updateBitmap;
  66. var aliasUpdatePosition081115a = Sprite_Character.prototype.updatePosition;
  67. var aliasSetupPage081115a      = Game_Event.prototype.setupPage;
  68.  
  69. //------
  70. // Destructive functions list
  71. /*
  72.  */
  73.  
  74.  
  75. //------
  76. // Sprite_Character
  77. //------
  78. Sprite_Character.prototype.setUpperAreaSprite = false;
  79. Sprite_Character.prototype.forceGfxChange = false;
  80. Sprite_Character.prototype.oldBitmap = null;
  81. Sprite_Character.prototype.upperAreaSprite = null;
  82.  
  83. // Checks if the sprite has been changed.
  84. Sprite_Character.prototype.updateBitmap = function() {
  85.   if (this.isImageChanged() && this.setUpperAreaSprite)
  86.     this.forceGfxChange = true;
  87.   else
  88.     this.forceGfxChange = false;
  89.   aliasUpdateBitmap081115a.apply(this, arguments);
  90. }
  91.  
  92. Sprite_Character.prototype.updatePosition = function() {
  93.   aliasUpdatePosition081115a.apply(this, arguments);
  94.   if (this.spriteIsOnscreen())
  95.     this.checkEncompassedArea();
  96. }
  97.  
  98. // 5 would be highest priority level for characters
  99. Sprite_Character.prototype.spriteIsOnscreen = function() {
  100. //  if (this._character.largeSprite() && this._character.screenZ() < 5) {
  101.   if (this._character.screenZ() < 5) {
  102.     var rectArray = this.getEdgeRect();
  103.     if (rectArray[0] < Graphics._width && rectArray[1] < Graphics._height &&
  104.         rectArray[2] > 0 && rectArray[3] > 0)
  105.       return true;
  106.   }
  107.   return false;
  108. }
  109.  
  110. Sprite_Character.prototype.getEdgeRect = function() {
  111.   var x = this.x - Math.round(this.patternWidth() * this.anchor.x);
  112.   var y = this.y - Math.round(this.patternHeight() * this.anchor.y);
  113.   var w = x + this.patternWidth();
  114.   var h = y + this.patternHeight();
  115.   return [x, y, w, h];
  116. }
  117.  
  118. Sprite_Character.prototype.checkEncompassedArea = function() {
  119.   var tw = $gameMap.tileWidth();
  120.   var th = $gameMap.tileHeight();
  121.   if (this.setUpperAreaSprite && this.forceGfxChange)
  122.     this.oldBitmap = this.bitmap;
  123.   this.setUpperAreaSprite = false;
  124.   var boxArray = this.getEdgeRect();
  125.   var lastX = null;
  126.   var lastY = null;
  127.   var copyR = 0;
  128.   var mapXD = $gameMap.displayX() * $gameMap.tileWidth();
  129.   var mapYD = $gameMap.displayY() * $gameMap.tileHeight();
  130.   var totalH = (this.patternHeight() + this._character.jumpHeight());
  131.   var _bx = [false, 0, 0, 0];
  132.   for (var x = 0; x < this.patternWidth(); x++) {
  133.     var xp = Math.round(mapXD) + boxArray[0] + x;
  134.     if (Math.floor(xp / tw) !== lastX) {
  135.       lastX = Math.floor(xp / tw);
  136.       lastY = null;
  137.       copyR = 0;
  138.       for (var y = 0; y < totalH; y++) {
  139.         var yp = Math.round(mapYD) + boxArray[3] + this._character.jumpHeight() - y;
  140.         while (Math.floor(yp / th) === lastY) { y++; yp--; };
  141.         lastY = Math.floor(yp / th);
  142.         if (lastY === Math.round((this._character.screenY() +
  143.             this._character.jumpHeight() + mapYD) / th)) {
  144.           if ($gameMap.terrainTag(lastX, lastY) === Number(cpp.lsdf.terrain))
  145.             break;
  146.           continue;
  147.         }
  148.         if ($gameMap.terrainTag(lastX, lastY) !== Number(cpp.lsdf.terrain))
  149.           continue;
  150.         var copyR = Math.min(this.patternHeight(), Math.round(totalH - y + 1));
  151.         this.setUpperSprite();
  152.         break;
  153.       }
  154.     }
  155.     _bx = this.upperSpriteCopy(x, copyR, _bx);
  156.   }
  157.   _bx = this.upperSpriteCopy(x, 0, _bx);
  158.   if (!this.setUpperAreaSprite && this.upperAreaSprite) {
  159.     this.parent.removeChild(this.upperAreaSprite);
  160.     this.upperAreaSprite = null;
  161.     this.cpResetBitmapFrame();
  162.   }
  163. }
  164.  
  165. Sprite_Character.prototype.upperSpriteCopy = function(x, copyR, _bx) {
  166.   if (_bx[3] === copyR) {
  167.     _bx[2]++;
  168.     return _bx;
  169.   }
  170.   if (_bx[0] && this.upperAreaSprite && _bx[3] > 0 && _bx[3] < this.patternHeight()) {
  171.     var rect = new Rectangle();
  172.     rect.x = this._frame.x + _bx[1];
  173.     rect.y = this._frame.y;
  174.     rect.width = _bx[2];
  175.     rect.height = _bx[3];
  176.     this.upperAreaSprite.bitmap.blt(this.bitmap, rect.x, rect.y, rect.width,
  177.                                     rect.height, _bx[1], 0, rect.width, rect.height);
  178.     this.bitmap.clearRect(rect.x, rect.y, rect.width, rect.height);
  179.   }
  180.   return [true, x, 1, copyR];
  181. }
  182.  
  183. Sprite_Character.prototype.setUpperSprite = function() {
  184.   if (this.setUpperAreaSprite) { return }
  185.   if (this.upperAreaSprite) {
  186.     this.upperAreaSprite.visible = true;
  187.   } else {
  188.     this.upperAreaSprite = new Sprite();
  189.     this.parent.addChild(this.upperAreaSprite);
  190.     this.oldBitmap = this.bitmap;
  191.   }
  192.   this.upperAreaSprite.bitmap = new Bitmap(this.patternWidth(), this.patternHeight());
  193.   this.upperAreaSprite.x = this.x;
  194.   this.upperAreaSprite.y = this.y;
  195.   this.upperAreaSprite.anchor.x = this.anchor.x;
  196.   this.upperAreaSprite.anchor.y = this.anchor.y;
  197.   this.upperAreaSprite.opacity = this.opacity;
  198.   this.upperAreaSprite.visible = this.visible;
  199.   this.upperAreaSprite.z = 8;
  200.   this.setUpperAreaSprite = true;
  201.   var _oldFrame = new Rectangle();
  202.   _oldFrame.x      = this._frame.x;
  203.   _oldFrame.y      = this._frame.y;
  204.   _oldFrame.width  = this.patternWidth();
  205.   _oldFrame.height = this.patternHeight();
  206.   this.bitmap = new Bitmap(this.oldBitmap.width, this.oldBitmap.height);
  207.   this.bitmap.blt(this.oldBitmap, 0, 0, this.oldBitmap.width, this.oldBitmap.height,
  208.                   0, 0, this.bitmap.width, this.bitmap.height);
  209.   this.setFrame(_oldFrame.x, _oldFrame.y, _oldFrame.width, _oldFrame.height);
  210. }
  211.  
  212. Sprite_Character.prototype.cpResetBitmapFrame = function() {
  213.   var _oldFrame = new Rectangle();
  214.   _oldFrame.x      = this._frame.x;
  215.   _oldFrame.y      = this._frame.y;
  216.   _oldFrame.width  = this.patternWidth();
  217.   _oldFrame.height = this.patternHeight();
  218.   this.bitmap = this.oldBitmap;
  219.   this.setFrame(_oldFrame.x, _oldFrame.y, _oldFrame.width, _oldFrame.height);
  220. }
  221.  
  222.  
  223. //------
  224. // Game_CharacterBase
  225. //------
  226. Game_CharacterBase.prototype.largeSprite = function() { return false }
  227. Game_Player.prototype.largeSprite = function() { return true }
  228. Game_Follower.prototype.largeSprite = function() { return cpp.lsdf.followers }
  229. Game_Vehicle.prototype.largeSprite = function() { return cpp.lsdf.vehicles }
  230. Game_Event.prototype.largeSprite = function() { return this._largeSprite }
  231.  
  232. Game_Event.prototype.setupPage = function() {
  233.   aliasSetupPage081115a.apply(this, arguments);
  234.   this._largeSprite = false;
  235.   if (this._pageIndex >= 0) {
  236.     for (var i = 0; i < this.list().length; i++) {
  237.       if ([108, 408].indexOf(this.list()[i]['code']) >= 0) {
  238.         var note = this.list()[i]['parameters'][0];
  239.         if (note.match(/<large sprite>/i))
  240.           this._largeSprite = true;
  241.       }
  242.     }
  243.   }
  244. }
  245.  
  246.  
  247. //------
  248. // End of plugin
  249. //------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement