Advertisement
Guest User

Jay_MiniMapMaker

a guest
Nov 7th, 2015
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Map Making system
  3. // Jay_MiniMapMaker.js
  4. // Version 1.0.2
  5. //=============================================================================
  6.  
  7. var Imported = Imported || {};
  8. Imported.Jay_MiniMapMaker = true;
  9.  
  10. var Jay = Jay || {};
  11. Jay.MiniMapMaker = Jay.MiniMapMaker || {};
  12.  
  13. //=============================================================================
  14.  /*:
  15.  * @plugindesc Makes mimimaps, perfect for putting in the corner of the screen.
  16.  *
  17.  * @author Jason R. Godding
  18.  *
  19.  * @param Water Color
  20.  * @desc The color used for water tiles.
  21.  * @default #888888
  22.  *
  23.  * @param Walkable Color
  24.  * @desc The color used for walkable tiles.
  25.  * @default #FFFFFF
  26.  *
  27.  * @param Cliff Color
  28.  * @desc The color used for tiles along cliffs.
  29.  * @default #CCCCCC
  30.  *
  31.  * @param Unwalkable Color
  32.  * @desc The color used for unwalkable, but non-water, tiles.
  33.  * @default #AAAAAA
  34.  *
  35.  * @param Damage Color
  36.  * @desc The color used for damage tiles.
  37.  * @default #DDDDDD
  38.  *
  39.  * @param Default Scale
  40.  * @desc The scale to use when one isn't defined and autoscale is turned off. One tile becomes this many pixels high and wide.
  41.  * @default 1
  42.  *
  43.  * @param Auto Scale
  44.  * @desc Set to "true" to make the map automatically pick the scale when one isn't defined.
  45.  * @default false
  46.  *
  47.  * @param Max Size
  48.  * @desc If no scale is defined and Auto Scale is true, this is the size maps will try to scale to.
  49.  * @default 100
  50.  *
  51.  * @help Just put "MakeMap" in a Plugin Command to make an image of the current map.
  52.  * Use "MakeMap #", with a number in place of "#", to change the scale to that number.
  53.  * For example, "MakeMap 2" would have each tile be represented two pixels wide and two pixels high.
  54.  * Great for putting in corners of screens and whatnot.
  55.  *
  56.  * ====================================
  57.  *
  58.  * Version 1.0.2 - Added scaling options and a color for damage tiles.
  59.  *
  60.  * Version 1.0.1 - Fixed an issue that would cause certain horizontal-only tiles
  61.  * to be marked as "unwalkable" instead of the more correct "cliff".
  62.  *
  63.  * This plugin is free for non-commercial and commercial use, but please credit
  64.  * Jason R. Godding if you use it. Thank you.
  65.  *
  66.  */
  67.  
  68. Jay.Parameters = Jay.Parameters || {};
  69. Jay.Parameters.MiniMapMaker = PluginManager.parameters('Jay_MiniMapMaker');
  70.  
  71. Jay.Param = Jay.Param || {};
  72. Jay.Param.WaterColor = String(Jay.Parameters.MiniMapMaker['Water Color']);
  73. Jay.Param.WalkableColor = String(Jay.Parameters.MiniMapMaker['Walkable Color']);
  74. Jay.Param.CliffColor = String(Jay.Parameters.MiniMapMaker['Cliff Color']);
  75. Jay.Param.UnwalkableColor = String(Jay.Parameters.MiniMapMaker['Unwalkable Color']);
  76. Jay.Param.DamageColor = String(Jay.Parameters.MiniMapMaker['Damage Color']);
  77. Jay.Param.DefaultMapScale = Number(Jay.Parameters.MiniMapMaker['Default Scale']);
  78. Jay.Param.AutoScale = String(Jay.Parameters.MiniMapMaker['Auto Scale']) === 'true';
  79. Jay.Param.MaxSize = Number(Jay.Parameters.MiniMapMaker['Max Size']);
  80.  
  81. Jay.MiniMapMaker.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  82. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  83.     if (command === 'MakeMap') {
  84.         this.makeMap(args);
  85.     }
  86.     Jay.MiniMapMaker.pluginCommand.call(this, command, args);
  87. }
  88.  
  89. Game_Interpreter.prototype.makeMap = function(args) {
  90.     var width = $gameMap.width();
  91.     var height = $gameMap.height();
  92.     var scale;
  93.     if (args.length > 0) {
  94.         scale = Number(args[0]);
  95.     }
  96.     else if (Jay.Param.AutoScale) {
  97.         var size = Math.max(width, height);
  98.         if (size > Jay.Param.MaxSize) {
  99.             scale = 1;
  100.         }
  101.         else {
  102.             scale = Math.floor(Jay.Param.MaxSize / size);
  103.         }
  104.     }
  105.     else {
  106.         scale = Jay.Param.DefaultMapScale;
  107.     }
  108.     var map = new Bitmap(width * scale, height * scale);
  109.     for(var x = 0; x < width; x++) {
  110.         for(var y = 0; y < height; y++) {
  111.             var isWalkable = $gameMap.isPassable(x, y, 2) && $gameMap.isPassable(x, y, 4) &&
  112.                 $gameMap.isPassable(x, y, 6) && $gameMap.isPassable(x, y, 8);
  113.             var isCliff = !isWalkable && ($gameMap.isPassable(x, y, 2) || $gameMap.isPassable(x, y, 4) ||
  114.                 $gameMap.isPassable(x, y, 6) || $gameMap.isPassable(x, y, 8));
  115.             var isDamage = (isWalkable || isCliff) && $gameMap.isDamageFloor(x, y);
  116.             var isWater = $gameMap.isShipPassable(x, y);
  117.             if (isDamage) {
  118.                 map.fillRect(x * scale, y * scale, scale, scale, Jay.Param.DamageColor);
  119.             }
  120.             else if (isCliff) {
  121.                 map.fillRect(x * scale, y * scale, scale, scale, Jay.Param.CliffColor);
  122.             }
  123.             else if (isWalkable) {
  124.                 map.fillRect(x * scale, y * scale, scale, scale, Jay.Param.WalkableColor);
  125.             }
  126.             else if (isWater) {
  127.                 map.fillRect(x * scale, y * scale, scale, scale, Jay.Param.WaterColor);
  128.             }
  129.             else {
  130.                 map.fillRect(x * scale, y * scale, scale, scale, Jay.Param.UnwalkableColor);
  131.             }
  132.         }
  133.     }
  134.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/img/pictures');
  135.     if (path.match(/^\/([A-Z]\:)/)) {
  136.         path = path.slice(1);
  137.     }
  138.     path = decodeURIComponent(path);
  139.     var fs = require('fs');
  140.     fs.mkdir(path, function(){
  141.         var fileName = path + '/Map_' + $gameMap.mapId() + '.png';
  142.         var image = map.canvas.toDataURL();
  143.         var base64Data = image.replace(/^data:image\/png;base64,/, "");
  144.  
  145.             fs.writeFile(fileName, base64Data, 'base64', function(error){
  146.             if (error !== undefined && error !== null) {
  147.                 console.error('An error occurred while saving the screenshot', error);
  148.             }
  149.         });
  150.     });
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement