Zeriab

[RMMZ] MoarMaps

Aug 26th, 2020
1,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // RPG Maker MZ - Moar maps
  3. // Last Updated: 2020.08.26
  4. //=============================================================================
  5. // Copyright 2020 Zeriab
  6. //
  7. // This software is provided 'as-is', without any express or implied
  8. // warranty. In no event will the authors be held liable for any damages
  9. // arising from the use of this software.
  10. //
  11. // Permission is granted to anyone to use this software for any purpose,
  12. // including commercial applications, and to alter it and redistribute it
  13. // freely, subject to the following restrictions:
  14. //
  15. // 1. The origin of this software must not be misrepresented; you must not
  16. //    claim that you wrote the original software. If you use this software
  17. //    in a product, an acknowledgement in the product documentation would be
  18. //    appreciated but is not required.
  19. // 2. Altered source versions must be plainly marked as such, and must not be
  20. //    misrepresented as being the original software.
  21. // 3. This notice may not be removed or altered from any source distribution.
  22. //=============================================================================
  23.  
  24. /*:
  25.  * @target MZ
  26.  * @plugindesc Allows using more than 2000 maps
  27.  * @author Zeriab
  28.  *
  29.  * @help Zeriab_MoarMaps.js
  30.  *
  31.  * When 2000 maps is not enough. When you NEED MOAR MAPS!
  32.  *
  33.  * This plugin provides plugin commands transfering between subfolder of maps.
  34.  * Each can have up to 2000 maps. No map limit is imposed.
  35.  *
  36.  * When you have hundreds of thousands of maps they do take up alot of harddrive
  37.  * space. Fear not. This plugin together with my Zeriab_MoarMapsHelper plugin
  38.  * allows you compress maps in all your subfolders.
  39.  *
  40.  * @param IsCompressed
  41.  * @text Use compressed maps
  42.  * @desc You can use Zeriab_MoarMapsHelper to compress your maps so they take up less space
  43.  * @default false
  44.  * @type boolean
  45.  *
  46.  * @param CompressedFolder
  47.  * @type string
  48.  * @default pak
  49.  * @text Folder in 'data' that contains the compressed maps
  50.  * @desc Please ensure this folder is the same as the one specified in the Zeriab_MoarMapsHelper plugin
  51.  *
  52.  *
  53.  * @command transfer
  54.  * @text Transfer to a subfolder
  55.  * @desc Mimics the transfer event command with the option of changing the subfolder
  56.  *
  57.  * @arg subfolder
  58.  * @type string
  59.  * @default church
  60.  * @text Subfolder
  61.  * @desc Use maps from the specific subfolder. For example "church" and transfer to Map 3 leads to data/church/Map003.json
  62.  *
  63.  * @arg mapId
  64.  * @text Map ID
  65.  * @type number
  66.  * @min 1
  67.  * @max 2000
  68.  * @default 1
  69.  *
  70.  * @arg x
  71.  * @text X
  72.  * @type number
  73.  * @min 1
  74.  * @max 256
  75.  * @default 8
  76.  *
  77.  * @arg y
  78.  * @text Y
  79.  * @type number
  80.  * @min 1
  81.  * @max 256
  82.  * @default 6
  83.  *
  84.  * @arg direction
  85.  * @text Direction
  86.  * @type select
  87.  * @default 0
  88.  * @option Retain
  89.  * @value 0
  90.  * @option Down
  91.  * @value 2
  92.  * @option Left
  93.  * @value 4
  94.  * @option Right
  95.  * @value 6
  96.  * @option Up
  97.  * @value 8
  98.  *
  99.  * @arg fade
  100.  * @text Fade
  101.  * @type select
  102.  * @default 0
  103.  * @option Black
  104.  * @value 0
  105.  * @option White
  106.  * @value 1
  107.  * @option None
  108.  * @value 2
  109.  *
  110.  *
  111.  * @command transferMain
  112.  * @text Transfer to the main folder
  113.  * @desc Mimics the transfer event command
  114.  *       Use this when you need to transfer from a subfolder back to the main folder
  115.  *
  116.  * @arg mapId
  117.  * @text Map ID
  118.  * @type number
  119.  * @min 1
  120.  * @max 2000
  121.  * @default 1
  122.  *
  123.  * @arg x
  124.  * @text X
  125.  * @type number
  126.  * @min 1
  127.  * @max 256
  128.  * @default 8
  129.  *
  130.  * @arg y
  131.  * @text Y
  132.  * @type number
  133.  * @min 1
  134.  * @max 256
  135.  * @default 6
  136.  *
  137.  * @arg direction
  138.  * @text Direction
  139.  * @type select
  140.  * @default 0
  141.  * @option Retain
  142.  * @value 0
  143.  * @option Down
  144.  * @value 2
  145.  * @option Left
  146.  * @value 4
  147.  * @option Right
  148.  * @value 6
  149.  * @option Up
  150.  * @value 8
  151.  *
  152.  * @arg fade
  153.  * @text Fade
  154.  * @type select
  155.  * @default 0
  156.  * @option Black
  157.  * @value 0
  158.  * @option White
  159.  * @value 1
  160.  * @option None
  161.  * @value 2
  162.  */
  163. (() => {
  164.     'use strict';
  165.     const pluginName = "Zeriab_MoarMaps";
  166.     const parameters = PluginManager.parameters(pluginName);
  167.     const isCompressed = eval(parameters.IsCompressed || 'false');
  168.     const compressedFolder = parameters.CompressedFolder;
  169.  
  170.     PluginManager.registerCommand(pluginName, "transfer", args => {
  171.         const subfolder = args.subfolder.toLowerCase();
  172.         const mapId = Number(args.mapId);
  173.         const x = Number(args.x);
  174.         const y = Number(args.y);
  175.         const direction = Number(args.direction);
  176.         const fade = Number(args.fade);
  177.  
  178.         $gameSystem.setMapsFolder(subfolder);
  179.         $gamePlayer.reserveTransfer(mapId, x, y, direction, fade);
  180.     });
  181.  
  182.     PluginManager.registerCommand(pluginName, "transferMain", args => {
  183.         const mapId = Number(args.mapId);
  184.         const x = Number(args.x);
  185.         const y = Number(args.y);
  186.         const direction = Number(args.direction);
  187.         const fade = Number(args.fade);
  188.  
  189.         $gameSystem.clearMapsFolder();
  190.         $gamePlayer.reserveTransfer(mapId, x, y, direction, fade);
  191.     });
  192.  
  193.     // Store the subfolder information in $gameSystem so it gets included in the saves
  194.     Game_System.prototype.setMapsFolder = function(subfolder) {
  195.         if (this._MapSubFolder !== subfolder)
  196.         {
  197.             this._MapSubFolder = subfolder;
  198.             this._MapFolderChange = true;
  199.             $gamePlayer.requestMapReload();
  200.         }
  201.     };
  202.  
  203.     // Default folder is the top level 'data' folder
  204.     Game_System.prototype.clearMapsFolder = function() {
  205.         this.setMapsFolder('');
  206.     };
  207.  
  208.     const _DataManager_loadMapData = DataManager.loadMapData
  209.     DataManager.loadMapData = function(mapId) {
  210.         // Old saves without any subfolder information is considered to use the default folder
  211.         const subfolder = $gameSystem._MapSubFolder || '';
  212.         if (subfolder && subfolder.length >= 1)
  213.         {
  214.             if (mapId > 0) {
  215.                 var filename = DataManager.makeMapName(subfolder, mapId);
  216.                 if (isCompressed) {
  217.                     this.loadDataZipFile('$dataMap', filename);
  218.                 } else {
  219.                     this.loadDataFile('$dataMap', filename)
  220.                 }
  221.             } else {
  222.                 this.makeEmptyMap();
  223.             }
  224.         }
  225.         else
  226.         {
  227.             _DataManager_loadMapData.apply(this, arguments);
  228.         }
  229.     };
  230.    
  231.     DataManager.makeMapName = function(subfolder, mapId, compressed) {
  232.         var filename = 'Map%1.json'.format(mapId.padZero(3));
  233.         if (subfolder && subfolder.length >= 1)
  234.         {
  235.             if (isCompressed) {
  236.                 filename = '%3/%1/%2.pak'.format(subfolder, filename, compressedFolder);
  237.             } else {
  238.                 filename = '%1/%2'.format(subfolder, filename);
  239.             }
  240.         }
  241.         return filename;
  242.     };
  243.    
  244.     DataManager.loadDataZipFile = function(name, src) {
  245.         const xhr = new XMLHttpRequest();
  246.         const url = "data/" + src;
  247.         window[name] = null;
  248.         xhr.open("GET", url);
  249.         xhr.onload = () => this.onXhrZipLoad(xhr, name, src, url);
  250.         xhr.onerror = () => this.onXhrError(name, src, url);
  251.         xhr.send();
  252.     };
  253.  
  254.     DataManager.onXhrZipLoad = function(xhr, name, src, url) {
  255.         if (xhr.status < 400) {
  256.             const zip = xhr.responseText;
  257.             StorageManager
  258.                 .zipToJson(zip)
  259.                 .then(json =>
  260.                     StorageManager.jsonToObject(json)
  261.                         .then(map => {
  262.                             window[name] = map;
  263.                             this.onLoad(window[name]);
  264.                         })
  265.                 );
  266.         } else {
  267.             this.onXhrError(name, src, url);
  268.         }
  269.     };
  270. })();
Add Comment
Please, Sign In to add comment