SHARE
TWEET

Change Tile Size (MV)

ezmash Oct 24th, 2015 (edited) 7,644 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Change Tile Size
  3. // by Shaz
  4. // version 1.2
  5. // Last Update: 2017.04.12
  6. //=============================================================================
  7.  
  8. /*:
  9.  * @plugindesc Allows maps based on a grid size other than 48x48
  10.    <ChangeTileSize> v1.1
  11.  * @author Shaz
  12.  *
  13.  * @param Tile Size
  14.  * @desc Size of tiles (pixels)
  15.  * @default 48
  16.  *
  17.  * @param Tileset Image Folder
  18.  * @desc Folder where the in-game tilesets are kept
  19.  * @default img/tilesets/
  20.  *
  21.  * @param Parallax Image Folder
  22.  * @desc Folder where the in-game parallaxes are kept
  23.  * @default img/parallaxes/
  24.  *
  25.  * @help This plugin does not provide plugin commands.
  26.  *
  27.  * To use the map editor with tiles of a size other than 48x48 in your project,
  28.  * have two folders for tileset images.  The folder named in the plugin
  29.  * parameters is for original, high-quality, final-sized tiles.  The
  30.  * original folder, img/tilesets/ can contain a duplicate copy of each
  31.  * tileset, shrunk or enlarged to 48x48 pixels per tile.  Quality in the
  32.  * editor may be poorer, but the original tiles will be used in the game.
  33.  * The img/tilesets folder can be cleared prior to distribution.
  34.  *
  35.  * The same applies to the img/parallaxes folder if using a parallax map
  36.  * with a grid size other than 48x48.
  37.  *
  38.  * ----------------------------------------------------------------------------
  39.  * Revisions
  40.  *
  41.  * 1.1  2016.10.17 Catered for Tilemap tilesize to reduce choppiness
  42.  *                 Removed dependency on js file name
  43.  *      2016.10.23 Ensure resized tiles/parallaxes are included in build
  44.  * 1.2  2017.04.12 Fix issue with excluding unused resources
  45.  * ----------------------------------------------------------------------------
  46. RESOURCE LIST - DO NOT MODIFY BELOW THIS LINE
  47. RESOURCE LIST - DO NOT MODIFY ABOVE THIS LINE
  48.  */
  49.  
  50. (function() {
  51.  
  52.   var parameters = $plugins.filter(function(p) { return p.description.contains('<ChangeTileSize>'); })[0].parameters;
  53.   var tileSize = parseInt(parameters['Tile Size'] || 48);
  54.   var tilesetsFolder = String(parameters['Tileset Image Folder'] || 'img/tilesets/');
  55.   var parallaxesFolder = String(parameters['Parallax Image Folder'] || 'img/parallaxes/');
  56.  
  57.   ImageManager.loadTileset = function(filename, hue) {
  58.     return this.loadBitmap(tilesetsFolder, filename, hue, false);
  59.   };
  60.  
  61.   ImageManager.loadParallax = function(filename, hue) {
  62.       return this.loadBitmap(parallaxesFolder, filename, hue, true);
  63.   };
  64.  
  65.   Game_Map.prototype.tileWidth = function() {
  66.     return tileSize;
  67.   };
  68.  
  69.   Game_Map.prototype.tileHeight = function() {
  70.     return tileSize;
  71.   };
  72.  
  73.   Game_Vehicle.prototype.maxAltitude = function() {
  74.     return tileSize;
  75.   };
  76.  
  77.   var Tilemap_initialize = Tilemap.prototype.initialize;
  78.   Tilemap.prototype.initialize = function() {
  79.     Tilemap_initialize.call(this);
  80.     this._tileWidth = tileSize;
  81.     this._tileHeight = tileSize;
  82.   };
  83.  
  84.   // Add image files to required assets list, to ensure they are included
  85.   // in a deployed project
  86.   var _changeTileSize_Scene_Boot_start = Scene_Boot.prototype.start;
  87.   Scene_Boot.prototype.start = function() {
  88.     _changeTileSize_Scene_Boot_start.call(this);
  89.  
  90.     if (!Utils.isOptionValid('test') || DataManager.isBattleTest() ||
  91.       DataManager.isEventTest()) {
  92.         return;
  93.       }
  94.  
  95.     // Read in this script
  96.     var fs = require('fs');
  97.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/');
  98.     if (path.match(/^\/([A-Z]\:)/)) {
  99.       path = path.slice(1);
  100.     }
  101.     path = decodeURIComponent(path);
  102.     var scriptName = $plugins.filter(function(p) {
  103.       return p.description.contains('<ChangeTileSize>') && p.status;
  104.     })[0].name + '.js';
  105.     var sourcePath = path + 'js/plugins/' + scriptName;
  106.     var dataPath = path + 'data/';
  107.     if (fs.existsSync(sourcePath)) {
  108.       var source = fs.readFileSync(sourcePath, { encoding: 'utf8' });
  109.       source = source.split('\r\n');
  110.       var resListStart = source.indexOf('RESOURCE LIST - DO NOT MODIFY BELOW THIS LINE');
  111.       var resListEnd = source.indexOf('RESOURCE LIST - DO NOT MODIFY ABOVE THIS LINE');
  112.       if (resListStart === -1 || resListEnd === -1) {
  113.         console.log('ERROR - Unable to create resource list for ' + scriptName);
  114.         console.log('Please redownload the script and paste over your current version');
  115.       } else {
  116.         // remove previous list of resources
  117.         source.splice(resListStart + 1, resListEnd - resListStart - 1);
  118.         // build list of new resources
  119.         var resTilesets = [];
  120.         var resParallaxes = [];
  121.  
  122.         // get tilesets & parallaxes that are actually used
  123.         $dataMapInfos.forEach(function(mapinfo) {
  124.           if (mapinfo) {
  125.             var map = JSON.parse(fs.readFileSync(dataPath + 'Map%1.json'.format(mapinfo.id.padZero(3))));
  126.  
  127.             if (!resTilesets.contains(map.tilesetId)) {
  128.               resTilesets.push(map.tilesetId);
  129.             }
  130.  
  131.             if (map.parallaxName !== '' && !resParallaxes.contains(map.parallaxName)) {
  132.               resParallaxes.push(map.parallaxName);
  133.             }
  134.  
  135.             // map events
  136.             map.events.forEach(function (event) {
  137.               if (event) {
  138.                 event.pages.forEach(function (page) {
  139.                   if (page) {
  140.                     getResources(page.list, resTilesets, resParallaxes);
  141.                   }
  142.                 })
  143.               }
  144.             })
  145.           }
  146.         });
  147.  
  148.         // common events
  149.         $dataCommonEvents.forEach(function(commonEvent) {
  150.           if (commonEvent) {
  151.             getResources(commonEvent.list, resTilesets, resParallaxes);
  152.           }
  153.         });
  154.  
  155.         // troop events
  156.         $dataTroops.forEach(function (troop) {
  157.           if (troop) {
  158.             troop.pages.forEach(function (page) {
  159.               if (page) {
  160.                 getResources(page.list, resTilesets, resParallaxes);
  161.               }
  162.             })
  163.           }
  164.         })
  165.  
  166.         // add resource list to script
  167.         var inspos = resListStart + 1;
  168.  
  169.         resTilesetNames = [];
  170.         resTilesets.forEach(function(tilesetId) {
  171.           var tileset = $dataTilesets[tilesetId];
  172.           if (tileset) {
  173.             tileset.tilesetNames.forEach(function(tilesetName) {
  174.               if (tilesetName !== '' && !resTilesetNames.contains(tilesetName)) {
  175.                 resTilesetNames.push(tilesetName);
  176.               }
  177.             })
  178.           }
  179.         });
  180.  
  181.         var tag = ' * @requiredAssets';
  182.         source.splice(inspos, 0, tag);
  183.  
  184.         resTilesetNames.forEach(function(tilesetName) {
  185.           tag = ' * @requiredAssets ' + tilesetsFolder + tilesetName;
  186.           source.splice(inspos, 0, tag);
  187.         });
  188.  
  189.         resParallaxes.forEach(function(parallaxName) {
  190.           tag = ' * @requiredAssets ' + parallaxesFolder + parallaxName;
  191.           source.splice(inspos, 0, tag);
  192.         });
  193.  
  194.         // and save the file
  195.         source = source.join('\r\n');
  196.         fs.writeFileSync(sourcePath, source, { encoding: 'utf8' });
  197.       }
  198.     }
  199.   };
  200.  
  201.   getResources = function(list, aryTilesets, aryParallaxes) {
  202.     list.filter(function (cmd) {
  203.       return cmd.code === 282 || cmd.code === 284;
  204.     }).forEach(function(cmd) {
  205.       if (cmd.code === 282 && !aryTilesets.contains(cmd.parameters[0])) {
  206.         aryTilesets.push(cmd.parameters[0]);
  207.       }
  208.       if (cmd.code === 284 && !aryParallaxes.contains(cmd.parameters[0])) {
  209.         aryParallaxes.push(cmd.parameters[0]);
  210.       }
  211.     });
  212.   };
  213. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top