Fear3d

OrangeMapshotMZ

Dec 10th, 2022
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*=============================================================================
  2.  * Orange - Mapshot MZ
  3.  * By Hudell (Ported by Arthran)
  4.  * OrangeMapshotMZ.js
  5.  * Version: 1.7
  6.  * Free for commercial and non commercial use.
  7.  *=============================================================================*/
  8. /*:
  9.  * @target MZ
  10.  * @plugindesc This plugin will save a picture of the entire map on a Mapshots folder when you press a key. <OrangeMapshotMZ>
  11.  * @author Hudell (Ported by Arthran)
  12.  *
  13.  * @param useMapName
  14.  * @desc if true, the filename will be the name of the map. If false it will be the number.
  15.  * @default true
  16.  * @type boolean
  17.  * @on Use Map Name
  18.  * @off Use Map Number
  19.  *
  20.  * @param layerType
  21.  * @desc 0 = all, 1 = upper and lower, 2 = separate everything
  22.  * @default 0
  23.  * @type number
  24.  *
  25.  * @param drawAutoShadows
  26.  * @desc set this to false to disable autoshadows on the map shot
  27.  * @default true
  28.  * @type boolean
  29.  * @on Draw
  30.  * @off Do Not Draw
  31.  *
  32.  * @param drawEvents
  33.  * @desc set this to false to stop drawing the events on the full bitmap
  34.  * @default true
  35.  * @type boolean
  36.  * @on Draw
  37.  * @off Do Not Draw
  38.  *
  39.  * @param keyCode
  40.  * @desc code of the key that will be used (44 = printscreen). http://www.javascriptkeycode.com
  41.  * @default 44
  42.  * @type number
  43.  *
  44.  * @param imageType
  45.  * @desc What type of image should be generated. Can be png, jpeg or webp
  46.  * @default png
  47.  * @type text
  48.  *
  49.  * @param imageQuality
  50.  * @desc If the imageType is jpeg or webp, you can set this to a number between 0 and 100 indicating the quality of the image
  51.  * @default 70
  52.  * @type number
  53.  *
  54.  * @param imagePath
  55.  * @desc The path where the images will be saved
  56.  * @default ./Mapshots
  57.  * @type text
  58.  *
  59.  * @help
  60.  * Check keycodes at  http://www.javascriptkeycode.com
  61.  */
  62. var Imported = Imported || {};
  63.  
  64. var OrangeMapshotMZ = OrangeMapshotMZ || {};
  65.  
  66. (function ($) {
  67.     "use strict";
  68.  
  69.     var parameters = $plugins.filter(function (plugin) {
  70.         return plugin.description.indexOf('<OrangeMapshotMZ>') >= 0;
  71.     });
  72.     if (parameters.length === 0) {
  73.         throw new Error("Couldn't find OrangeMapshotMZ parameters.");
  74.     }
  75.     $.Parameters = parameters[0].parameters;
  76.  
  77.     $.Param = {};
  78.     $.Param.useMapName = $.Parameters.useMapName !== "false";
  79.     $.Param.drawAutoShadows = $.Parameters.drawAutoShadows !== "false";
  80.     $.Param.drawEvents = $.Parameters.drawEvents !== "false";
  81.     $.Param.layerType = Number($.Parameters.layerType || 0);
  82.     $.Param.imageType = $.Parameters.imageType || 'png';
  83.     $.Param.imagePath = $.Parameters.imagePath || './Mapshots';
  84.     $.Param.imageQuality = Number($.Parameters.imageQuality || 70);
  85.  
  86.     $.Param.keyCode = Number($.Parameters.keyCode || 44);
  87.  
  88.     $.imageType = function () {
  89.         if ($.Param.imageType == 'webp') return 'image/webp';
  90.         if ($.Param.imageType == 'jpeg' || $.Param.imageType == 'jpg') return 'image/jpeg';
  91.         return 'image/png';
  92.     };
  93.  
  94.     $.imageRegex = function () {
  95.         if ($.Param.imageType == 'webp') return (/^data:image\/webp;base64,/);
  96.         if ($.Param.imageType == 'jpeg' || $.Param.imageType == 'jpg') return (/^data:image\/jpeg;base64,/);
  97.  
  98.         return (/^data:image\/png;base64,/);
  99.     };
  100.  
  101.     $.fileExtension = function () {
  102.         if ($.Param.imageType == 'webp') return '.webp';
  103.         if ($.Param.imageType == 'jpeg' || $.Param.imageType == 'jpg') return '.jpg';
  104.         return '.png';
  105.     };
  106.  
  107.     $.imageQuality = function () {
  108.         if ($.fileExtension() == '.jpg' || $.fileExtension() == '.webp') {
  109.             return Math.min($.Param.imageQuality, 100) / 100;
  110.         }
  111.  
  112.         return 1;
  113.     };
  114.  
  115.     $.baseFileName = function () {
  116.         var mapName = ($gameMap._mapId).padZero(3);
  117.         if ($.Param.useMapName) {
  118.             mapName = $dataMapInfos[$gameMap._mapId].name;
  119.         } else {
  120.             mapName = 'Map' + mapName;
  121.         }
  122.  
  123.         return mapName;
  124.     };
  125.  
  126.     $.getMapshot = function () {
  127.         var lowerBitmap;
  128.         var upperBitmap;
  129.  
  130.         switch ($.Param.layerType) {
  131.             case 1:
  132.                 lowerBitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  133.                 upperBitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  134.                 SceneManager._scene._spriteset._tilemap._paintEverything(lowerBitmap, upperBitmap);
  135.  
  136.                 return [lowerBitmap, upperBitmap];
  137.             case 2:
  138.                 var groundBitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  139.                 var ground2Bitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  140.                 var lowerBitmapLayer = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  141.                 var upperBitmapLayer = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  142.                 var shadowBitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  143.                 var lowerEvents = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  144.                 var normalEvents = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  145.                 var upperEvents = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  146.  
  147.                 SceneManager._scene._spriteset._tilemap._paintLayered(groundBitmap, ground2Bitmap, lowerBitmapLayer, upperBitmapLayer, shadowBitmap, lowerEvents, normalEvents, upperEvents);
  148.                 return [groundBitmap, ground2Bitmap, lowerBitmapLayer, upperBitmapLayer, shadowBitmap, lowerEvents, normalEvents, upperEvents];
  149.             default:
  150.                 lowerBitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  151.                 upperBitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  152.                 SceneManager._scene._spriteset._tilemap._paintEverything(lowerBitmap, upperBitmap);
  153.  
  154.                 var bitmap = new Bitmap($dataMap.width * $gameMap.tileWidth(), $dataMap.height * $gameMap.tileHeight());
  155.                 bitmap.blt(lowerBitmap, 0, 0, lowerBitmap.width, lowerBitmap.height, 0, 0, lowerBitmap.width, lowerBitmap.height);
  156.                 bitmap.blt(upperBitmap, 0, 0, upperBitmap.width, upperBitmap.height, 0, 0, upperBitmap.width, upperBitmap.height);
  157.                 return [bitmap];
  158.         }
  159.     };
  160.  
  161.     function MapShotTileMap() {
  162.     }
  163.  
  164.     MapShotTileMap.prototype = Object.create(Tilemap.prototype);
  165.     MapShotTileMap.prototype.constructor = MapShotTileMap;
  166.  
  167.     MapShotTileMap.prototype._drawAutotile = function (bitmap, tileId, dx, dy) {
  168.         var autotileTable = Tilemap.FLOOR_AUTOTILE_TABLE;
  169.         var kind = Tilemap.getAutotileKind(tileId);
  170.         var shape = Tilemap.getAutotileShape(tileId);
  171.         var tx = kind % 8;
  172.         var ty = Math.floor(kind / 8);
  173.         var bx = 0;
  174.         var by = 0;
  175.         var setNumber = 0;
  176.         var isTable = false;
  177.  
  178.         if (Tilemap.isTileA1(tileId)) {
  179.             var waterSurfaceIndex = [0, 1, 2, 1][this.animationFrame % 4];
  180.             setNumber = 0;
  181.             if (kind === 0) {
  182.                 bx = waterSurfaceIndex * 2;
  183.                 by = 0;
  184.             } else if (kind === 1) {
  185.                 bx = waterSurfaceIndex * 2;
  186.                 by = 3;
  187.             } else if (kind === 2) {
  188.                 bx = 6;
  189.                 by = 0;
  190.             } else if (kind === 3) {
  191.                 bx = 6;
  192.                 by = 3;
  193.             } else {
  194.                 bx = Math.floor(tx / 4) * 8;
  195.                 by = ty * 6 + Math.floor(tx / 2) % 2 * 3;
  196.                 if (kind % 2 === 0) {
  197.                     bx += waterSurfaceIndex * 2;
  198.                 }
  199.                 else {
  200.                     bx += 6;
  201.                     autotileTable = Tilemap.WATERFALL_AUTOTILE_TABLE;
  202.                     by += this.animationFrame % 3;
  203.                 }
  204.             }
  205.         } else if (Tilemap.isTileA2(tileId)) {
  206.             setNumber = 1;
  207.             bx = tx * 2;
  208.             by = (ty - 2) * 3;
  209.             isTable = this._isTableTile(tileId);
  210.         } else if (Tilemap.isTileA3(tileId)) {
  211.             setNumber = 2;
  212.             bx = tx * 2;
  213.             by = (ty - 6) * 2;
  214.             autotileTable = Tilemap.WALL_AUTOTILE_TABLE;
  215.         } else if (Tilemap.isTileA4(tileId)) {
  216.             setNumber = 3;
  217.             bx = tx * 2;
  218.             by = Math.floor((ty - 10) * 2.5 + (ty % 2 === 1 ? 0.5 : 0));
  219.             if (ty % 2 === 1) {
  220.                 autotileTable = Tilemap.WALL_AUTOTILE_TABLE;
  221.             }
  222.         }
  223.  
  224.         var table = autotileTable[shape];
  225.         var source = this._bitmaps[setNumber];
  226.  
  227.         if (table && source) {
  228.             var w1 = this.tileWidth / 2;
  229.             var h1 = this.tileHeight / 2;
  230.             for (var i = 0; i < 4; i++) {
  231.                 var qsx = table[i][0];
  232.                 var qsy = table[i][1];
  233.                 var sx1 = (bx * 2 + qsx) * w1;
  234.                 var sy1 = (by * 2 + qsy) * h1;
  235.                 var dx1 = dx + (i % 2) * w1;
  236.                 var dy1 = dy + Math.floor(i / 2) * h1;
  237.                 if (isTable && (qsy === 1 || qsy === 5)) {
  238.                     var qsx2 = qsx;
  239.                     var qsy2 = 3;
  240.                     if (qsy === 1) {
  241.                         qsx2 = [0, 3, 2, 1][qsx];
  242.                     }
  243.                     var sx2 = (bx * 2 + qsx2) * w1;
  244.                     var sy2 = (by * 2 + qsy2) * h1;
  245.                     bitmap.blt(source, sx2, sy2, w1, h1, dx1, dy1, w1, h1);
  246.                     dy1 += h1 / 2;
  247.                     bitmap.blt(source, sx1, sy1, w1, h1 / 2, dx1, dy1, w1, h1 / 2);
  248.                 } else {
  249.                     bitmap.blt(source, sx1, sy1, w1, h1, dx1, dy1, w1, h1);
  250.                 }
  251.             }
  252.         }
  253.     };
  254.  
  255.     MapShotTileMap.prototype._drawNormalTile = function(bitmap, tileId, dx, dy) {
  256.         var setNumber = 0;
  257.  
  258.         if (Tilemap.isTileA5(tileId)) {
  259.             setNumber = 4;
  260.         } else {
  261.             setNumber = 5 + Math.floor(tileId / 256);
  262.         }
  263.  
  264.         var w = this.tileWidth;
  265.         var h = this.tileHeight;
  266.         var sx = (Math.floor(tileId / 128) % 2 * 8 + tileId % 8) * w;
  267.         var sy = (Math.floor(tileId % 256 / 8) % 16) * h;
  268.  
  269.         var source = this._bitmaps[setNumber];
  270.         if (source) {
  271.             bitmap.blt(source, sx, sy, w, h, dx, dy, w, h);
  272.         }
  273.     };
  274.  
  275.     MapShotTileMap.prototype._drawTableEdge = function(bitmap, tileId, dx, dy) {
  276.         if (Tilemap.isTileA2(tileId)) {
  277.             var autotileTable = Tilemap.FLOOR_AUTOTILE_TABLE;
  278.             var kind = Tilemap.getAutotileKind(tileId);
  279.             var shape = Tilemap.getAutotileShape(tileId);
  280.             var tx = kind % 8;
  281.             var ty = Math.floor(kind / 8);
  282.             var setNumber = 1;
  283.             var bx = tx * 2;
  284.             var by = (ty - 2) * 3;
  285.             var table = autotileTable[shape];
  286.  
  287.             if (table) {
  288.                 var source = this._bitmaps[setNumber];
  289.                 var w1 = this.tileWidth / 2;
  290.                 var h1 = this.tileHeight / 2;
  291.                 for (var i = 0; i < 2; i++) {
  292.                     var qsx = table[2 + i][0];
  293.                     var qsy = table[2 + i][1];
  294.                     var sx1 = (bx * 2 + qsx) * w1;
  295.                     var sy1 = (by * 2 + qsy) * h1 + h1 / 2;
  296.                     var dx1 = dx + (i % 2) * w1;
  297.                     var dy1 = dy + Math.floor(i / 2) * h1;
  298.                     bitmap.blt(source, sx1, sy1, w1, h1 / 2, dx1, dy1, w1, h1 / 2);
  299.                 }
  300.             }
  301.         }
  302.     };
  303.  
  304.     MapShotTileMap.prototype._drawShadow = function(bitmap, shadowBits, dx, dy) {
  305.         if (shadowBits & 0x0f) {
  306.             var w1 = this.tileWidth / 2;
  307.             var h1 = this.tileHeight / 2;
  308.             var color = 'rgba(0,0,0,0.5)';
  309.             for (var i = 0; i < 4; i++) {
  310.                 if (shadowBits & (1 << i)) {
  311.                     var dx1 = dx + (i % 2) * w1;
  312.                     var dy1 = dy + Math.floor(i / 2) * h1;
  313.                     bitmap.fillRect(dx1, dy1, w1, h1, color);
  314.                 }
  315.             }
  316.         }
  317.     };
  318.  
  319.     Tilemap.prototype._drawTileOldStyle = function (bitmap, tileId, dx, dy) {
  320.         if (Tilemap.isVisibleTile(tileId)) {
  321.             if (Tilemap.isAutotile(tileId)) {
  322.                 MapShotTileMap.prototype._drawAutotile.call(this, bitmap, tileId, dx, dy);
  323.             } else {
  324.                 MapShotTileMap.prototype._drawNormalTile.call(this, bitmap, tileId, dx, dy);
  325.             }
  326.         }
  327.     };
  328.  
  329.     Tilemap.prototype._paintEverything = function (lowerBitmap, upperBitmap) {
  330.         var tileCols = $dataMap.width;
  331.         var tileRows = $dataMap.height;
  332.  
  333.         for (var y = 0; y < tileRows; y++) {
  334.             for (var x = 0; x < tileCols; x++) {
  335.                 this._paintTilesOnBitmap(lowerBitmap, upperBitmap, x, y);
  336.             }
  337.         }
  338.  
  339.         if ($.Param.drawEvents !== false) {
  340.             this._paintCharacters(lowerBitmap, 0);
  341.             this._paintCharacters(lowerBitmap, 1);
  342.             this._paintCharacters(upperBitmap, 2);
  343.         }
  344.     };
  345.  
  346.     Tilemap.prototype._paintLayered = function (groundBitmap, ground2Bitmap, lowerBitmap, upperLayer, shadowBitmap, lowerEvents, normalEvents, upperEvents) {
  347.         var tileCols = $dataMap.width;
  348.         var tileRows = $dataMap.height;
  349.  
  350.         for (var y = 0; y < tileRows; y++) {
  351.             for (var x = 0; x < tileCols; x++) {
  352.                 this._paintTileOnLayers(groundBitmap, ground2Bitmap, lowerBitmap, upperLayer, shadowBitmap, x, y);
  353.             }
  354.         }
  355.  
  356.         this._paintCharacters(lowerEvents, 0);
  357.         this._paintCharacters(normalEvents, 1);
  358.         this._paintCharacters(upperEvents, 2);
  359.     };
  360.  
  361.     Tilemap.prototype._paintCharacters = function (bitmap, priority) {
  362.         this.children.forEach(function (child) {
  363.             if (child instanceof Sprite_Character) {
  364.                 if (child._character !== null) {
  365.                     if (child._character instanceof Game_Player || child._character instanceof Game_Follower || child._character instanceof Game_Vehicle) return;
  366.                 }
  367.  
  368.                 child.update();
  369.  
  370.                 if (child._characterName === '' && child._tileId === 0) return;
  371.                 if (priority !== undefined && child._character._priorityType !== priority) return;
  372.  
  373.                 var x = child.x - child._frame.width / 2 + $gameMap._displayX * $gameMap.tileWidth();
  374.                 var y = child.y - child._frame.height + $gameMap._displayY * $gameMap.tileHeight();
  375.  
  376.                 bitmap.blt(child.bitmap, child._frame.x, child._frame.y, child._frame.width, child._frame.height, x, y, child._frame.width, child._frame.height);
  377.             }
  378.         });
  379.     };
  380.  
  381.     Tilemap.prototype._paintTileOnLayers = function (groundBitmap, ground2Bitmap, lowerBitmap, upperBitmap, shadowBitmap, x, y) {
  382.         var tableEdgeVirtualId = 10000;
  383.         var mx = x;
  384.         var my = y;
  385.         var dx = (mx * this.tileWidth);
  386.         var dy = (my * this.tileHeight);
  387.         var lx = dx / this.tileWidth;
  388.         var ly = dy / this.tileHeight;
  389.         var tileId0 = this._readMapData(mx, my, 0);
  390.         var tileId1 = this._readMapData(mx, my, 1);
  391.         var tileId2 = this._readMapData(mx, my, 2);
  392.         var tileId3 = this._readMapData(mx, my, 3);
  393.         var shadowBits = this._readMapData(mx, my, 4);
  394.         var upperTileId1 = this._readMapData(mx, my - 1, 1);
  395.  
  396.         if (groundBitmap !== undefined) {
  397.             groundBitmap.clearRect(dx, dy, this.tileWidth, this.tileHeight);
  398.         }
  399.  
  400.         if (ground2Bitmap !== undefined) {
  401.             ground2Bitmap.clearRect(dx, dy, this.tileWidth, this.tileHeight);
  402.         }
  403.  
  404.         if (lowerBitmap !== undefined) {
  405.             lowerBitmap.clearRect(dx, dy, this.tileWidth, this.tileHeight);
  406.         }
  407.  
  408.         if (upperBitmap !== undefined) {
  409.             upperBitmap.clearRect(dx, dy, this.tileWidth, this.tileHeight);
  410.         }
  411.  
  412.         if (shadowBitmap !== undefined) {
  413.             shadowBitmap.clearRect(dx, dy, this.tileWidth, this.tileHeight);
  414.         }
  415.  
  416.         var me = this;
  417.  
  418.         function drawTiles(bitmap, tileId, shadowBits, upperTileId1) {
  419.             if (tileId < 0) {
  420.                 if ($.Param.drawAutoShadows && shadowBits !== undefined) {
  421.                     MapShotTileMap.prototype._drawShadow.call(me, bitmap, shadowBits, dx, dy);
  422.                 }
  423.             } else if (tileId >= tableEdgeVirtualId) {
  424.                 MapShotTileMap.prototype._drawTableEdge.call(me, bitmap, upperTileId1, dx, dy);
  425.             } else {
  426.                 me._drawTileOldStyle(bitmap, tileId, dx, dy);
  427.             }
  428.         }
  429.  
  430.         if (groundBitmap !== undefined) {
  431.             drawTiles(groundBitmap, tileId0, undefined, upperTileId1);
  432.  
  433.             if (shadowBitmap !== undefined && tileId0 < 0) {
  434.                 drawTiles(shadowBitmap, tileId0, shadowBits, upperTileId1);
  435.             }
  436.         }
  437.  
  438.         if (ground2Bitmap !== undefined) {
  439.             drawTiles(ground2Bitmap, tileId1, undefined, upperTileId1);
  440.  
  441.             if (shadowBitmap !== undefined && tileId1 < 0) {
  442.                 drawTiles(shadowBitmap, tileId1, shadowBits, upperTileId1);
  443.             }
  444.         }
  445.  
  446.         if (lowerBitmap !== undefined) {
  447.             drawTiles(lowerBitmap, tileId2, undefined, upperTileId1);
  448.  
  449.             if (shadowBitmap !== undefined && tileId2 < 0) {
  450.                 drawTiles(shadowBitmap, tileId2, shadowBits, upperTileId1);
  451.             }
  452.         }
  453.  
  454.         if (upperBitmap !== undefined) {
  455.             drawTiles(upperBitmap, tileId3, shadowBits, upperTileId1);
  456.  
  457.             if (shadowBitmap !== undefined && tileId3 < 0) {
  458.                 drawTiles(shadowBitmap, tileId3, shadowBits, upperTileId1);
  459.             }
  460.         }
  461.     };
  462.  
  463.     Tilemap.prototype._paintTilesOnBitmap = function (lowerBitmap, upperBitmap, x, y) {
  464.         var tableEdgeVirtualId = 10000;
  465.         var mx = x;
  466.         var my = y;
  467.         var dx = (mx * this.tileWidth);
  468.         var dy = (my * this.tileHeight);
  469.         var lx = dx / this.tileWidth;
  470.         var ly = dy / this.tileHeight;
  471.         var tileId0 = this._readMapData(mx, my, 0);
  472.         var tileId1 = this._readMapData(mx, my, 1);
  473.         var tileId2 = this._readMapData(mx, my, 2);
  474.         var tileId3 = this._readMapData(mx, my, 3);
  475.         var shadowBits = this._readMapData(mx, my, 4);
  476.         var upperTileId1 = this._readMapData(mx, my - 1, 1);
  477.         var lowerTiles = [];
  478.         var upperTiles = [];
  479.  
  480.         if (this._isHigherTile(tileId0)) {
  481.             upperTiles.push(tileId0);
  482.         } else {
  483.             lowerTiles.push(tileId0);
  484.         }
  485.         if (this._isHigherTile(tileId1)) {
  486.             upperTiles.push(tileId1);
  487.         } else {
  488.             lowerTiles.push(tileId1);
  489.         }
  490.  
  491.         lowerTiles.push(-shadowBits);
  492.  
  493.         if (this._isTableTile(upperTileId1) && !this._isTableTile(tileId1)) {
  494.             if (!Tilemap.isShadowingTile(tileId0)) {
  495.                 lowerTiles.push(tableEdgeVirtualId + upperTileId1);
  496.             }
  497.         }
  498.  
  499.         if (this._isOverpassPosition(mx, my)) {
  500.             upperTiles.push(tileId2);
  501.             upperTiles.push(tileId3);
  502.         } else {
  503.             if (this._isHigherTile(tileId2)) {
  504.                 upperTiles.push(tileId2);
  505.             } else {
  506.                 lowerTiles.push(tileId2);
  507.             }
  508.             if (this._isHigherTile(tileId3)) {
  509.                 upperTiles.push(tileId3);
  510.             } else {
  511.                 lowerTiles.push(tileId3);
  512.             }
  513.         }
  514.  
  515.         lowerBitmap.clearRect(dx, dy, this.tileWidth, this.tileHeight);
  516.         upperBitmap.clearRect(dx, dy, this.tileWidth, this.tileHeight);
  517.  
  518.         for (var i = 0; i < lowerTiles.length; i++) {
  519.             var lowerTileId = lowerTiles[i];
  520.             if (lowerTileId < 0) {
  521.                 if ($.Param.drawAutoShadows) {
  522.                     MapShotTileMap.prototype._drawShadow.call(this, lowerBitmap, shadowBits, dx, dy);
  523.                 }
  524.             } else if (lowerTileId >= tableEdgeVirtualId) {
  525.                 MapShotTileMap.prototype._drawTableEdge.call(this, lowerBitmap, upperTileId1, dx, dy);
  526.             } else {
  527.                 this._drawTileOldStyle(lowerBitmap, lowerTileId, dx, dy);
  528.             }
  529.         }
  530.  
  531.         for (var j = 0; j < upperTiles.length; j++) {
  532.             this._drawTileOldStyle(upperBitmap, upperTiles[j], dx, dy);
  533.         }
  534.     };
  535.  
  536.     $.saveMapshot = function () {
  537.         if (!Utils.isNwjs()) return;
  538.  
  539.         var fs = require('fs');
  540.         var path = $.Param.imagePath;
  541.  
  542.         try {
  543.             fs.mkdir(path, function () {
  544.                 try {
  545.                     var fileName = path + '/' + $.baseFileName();
  546.                     var ext = $.fileExtension();
  547.                     var names = [fileName + ext];
  548.                     var regex = $.imageRegex();
  549.  
  550.                     switch ($.Param.layerType) {
  551.                         case 1:
  552.                             names = [
  553.                                 fileName + ' Lower' + ext,
  554.                                 fileName + ' Upper' + ext
  555.                             ];
  556.                             break;
  557.                         case 2:
  558.                             names = [
  559.                                 fileName + ' Ground' + ext,
  560.                                 fileName + ' Ground 2' + ext,
  561.                                 fileName + ' Lower' + ext,
  562.                                 fileName + ' Upper' + ext,
  563.                                 fileName + ' Shadows' + ext,
  564.                                 fileName + ' Lower Events' + ext,
  565.                                 fileName + ' Normal Events' + ext,
  566.                                 fileName + ' Upper Events' + ext
  567.                             ];
  568.  
  569.                             break;
  570.                         default:
  571.                             names = [fileName + ext];
  572.                             break;
  573.                     }
  574.  
  575.                     var snaps = $.getMapshot();
  576.  
  577.                     var callback = function (error) {
  578.                         if (error !== undefined && error !== null) {
  579.                             console.error('An error occured while saving the mapshot', error);
  580.                         }
  581.                     };
  582.  
  583.                     for (var i = 0; i < names.length; i++) {
  584.                         var urlData = snaps[i].canvas.toDataURL($.imageType(), $.imageQuality());
  585.                         var base64Data = urlData.replace(regex, "");
  586.  
  587.                         fs.writeFile(names[i], base64Data, 'base64', callback);
  588.                     }
  589.                 } catch (error) {
  590.                     if (error !== undefined && error !== null) {
  591.                         console.error('An error occured while saving the map shot:', error);
  592.                     }
  593.                 }
  594.             });
  595.  
  596.             var nodePath = require('path');
  597.             var longPath = nodePath.resolve(path);
  598.  
  599.             if (process.platform == 'win32' && $._openedFolder === undefined) {
  600.                 $._openedFolder = true;
  601.  
  602.                 setTimeout(function () {
  603.                     var exec = require('child_process').exec;
  604.                     exec('explorer ' + longPath);
  605.                 }, 100);
  606.             } else {
  607.                 $gameMessage.add('Mapshot saved to \n' + longPath.replace(/\\/g, '\\\\').match(/.{1,40}/g).join('\n'));
  608.             }
  609.  
  610.         } catch (error) {
  611.             if (error !== undefined && error !== null) {
  612.                 console.error('An error occured while saving the mapshot:', error);
  613.             }
  614.         }
  615.     };
  616.  
  617.     $.onKeyUp = function (event) {
  618.         if (event.keyCode == $.Param.keyCode) {
  619.             if (SceneManager._scene instanceof Scene_Map) {
  620.                 $.saveMapshot();
  621.             }
  622.         }
  623.     };
  624.  
  625.     document.addEventListener('keyup', $.onKeyUp);
  626. })(OrangeMapshotMZ);
  627.  
  628. Imported.OrangeMapshotMZ = 1.7;
Add Comment
Please, Sign In to add comment