Advertisement
Double_X

DoubleX RMMV Dynamic Data v101d

Oct 30th, 2015 (edited)
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info                                                          
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name                                                          
  5.  *      DoubleX RMMV Dynamic Data                                            
  6.  *----------------------------------------------------------------------------
  7.  *    # Terms Of Use                                                          
  8.  *      You shall keep this plugin's Plugin Info part's contents intact      
  9.  *      You shalln't claim that this plugin's written by anyone other than    
  10.  *      DoubleX or his aliases                                                
  11.  *      None of the above applies to DoubleX or his aliases                  
  12.  *----------------------------------------------------------------------------
  13.  *    # Prerequisites                                                        
  14.  *      Abilities:                                                            
  15.  *      1. Thorough comprehensions to the other custom plugins to edit their  
  16.  *         data loaded and cached during game executions                      
  17.  *----------------------------------------------------------------------------
  18.  *    # Links                                                                
  19.  *      This plugin:                                                          
  20.  *      1. http://pastebin.com/6qxskYb9                                      
  21.  *      Mentioned Patreon Supporters:
  22.  *      https://www.patreon.com/posts/71738797
  23.  *----------------------------------------------------------------------------
  24.  *    # Author                                                                
  25.  *      DoubleX                                                              
  26.  *----------------------------------------------------------------------------
  27.  *    # Changelog                                                            
  28.  *      v1.01d(GMT 1400 27-1-2016):                                          
  29.  *      1. Fixed undefined DD and DoubleX_RMMV.Dynamic_Data in defining latter
  30.  *      2. Fixed caching original data before they're completed loaded bug    
  31.  *      v1.01c(GMT 0100 26-12-2015):                                          
  32.  *      1. Fixed corupting the database upon reloading it on the title screen
  33.  *      2. Fixed some syntax errors due to typos                              
  34.  *      v1.01b(GMT 0900 25-11-2015):                                          
  35.  *      1. Fixed missing param dynamic_data_states in the plugin manager bug  
  36.  *      2. Fixed accessing private variables inside $gameSystem bug          
  37.  *      3. The aliased function names becomes more unique to this plugin      
  38.  *      v1.01a(GMT 1200 16-11-2015):                                          
  39.  *      1. Lets users set which part of the database changes will be saved    
  40.  *      2. The aliased functions can be accessed by other custom plugins now  
  41.  *      v1.00b(GMT 0800 11-11-2015):                                          
  42.  *      1. Added descriptions that will be shown in the plugin manager        
  43.  *      v1.00a(GMT 0100 31-10-2015):                                          
  44.  *      1. 1st version of this plugin finished                                
  45.  *============================================================================*/
  46. /*:
  47.  * @plugindesc Stores the database changes done by users during game executions
  48.  *             Can't be used with data read from the database files upon use
  49.  *             Can't be used with any map data
  50.  * @author DoubleX
  51.  *
  52.  * @param dynamicDataActors
  53.  * @desc Saves the actors part of the database changes in savefiles if and only
  54.  *       if dynamicDataActors is set as true
  55.  * @default false
  56.  *
  57.  * @param dynamicDataClasses
  58.  * @desc Saves the classes part of the database changes in savefiles if and only
  59.  *       if dynamicDataClasses is set as true
  60.  * @default false
  61.  *
  62.  * @param dynamicDataSkills
  63.  * @desc Saves the skills part of the database changes in savefiles if and only
  64.  *       if dynamicDataSkills is set as true
  65.  * @default false
  66.  *
  67.  * @param dynamicDataItems
  68.  * @desc Saves the items part of the database changes in savefiles if and only
  69.  *       if dynamicDataItems is set as true
  70.  * @default false
  71.  *
  72.  * @param dynamicDataWeapons
  73.  * @desc Saves the weapons part of the database changes in savefiles if and only
  74.  *       if dynamicDataWeapons is set as true
  75.  * @default false
  76.  *
  77.  * @param dynamicDataArmors
  78.  * @desc Saves the armors part of the database changes in savefiles if and only
  79.  *       if dynamicDataArmors is set as true
  80.  * @default false
  81.  *
  82.  * @param dynamicDataEnemies
  83.  * @desc Saves the enemies part of the database changes in savefiles if and only
  84.  *       if dynamicDataEnemies is set as true
  85.  * @default false
  86.  *
  87.  * @param dynamicDataTroops
  88.  * @desc Saves the troops part of the database changes in savefiles if and only
  89.  *       if dynamicDataTroops is set as true
  90.  * @default false
  91.  *
  92.  * @param dynamicDataStates
  93.  * @desc Saves the states part of the database changes in savefiles if and only
  94.  *       if dynamicDataStates is set as true
  95.  * @default false
  96.  *
  97.  * @param dynamicDataAnimations
  98.  * @desc Saves the animations part of the database changes in savefiles if and
  99.  *       only if dynamicDataAnimations is set as true
  100.  * @default false
  101.  *
  102.  * @param dynamicDataTilesets
  103.  * @desc Saves the tilesets part of the database changes in savefiles if and
  104.  *       only if dynamicDataTilesets is set as true
  105.  * @default false
  106.  *
  107.  * @param dynamicDataCommonEvents
  108.  * @desc Saves the common events part of the database changes in savefiles if
  109.  *       and only if dynamicDataCommonEvents is set as true
  110.  * @default false
  111.  *
  112.  * @param dynamicDataSystem
  113.  * @desc Saves the system part of the database changes in savefiles if and only
  114.  *       if dynamicDataSystem is set as true
  115.  * @default false
  116.  *
  117.  * @help
  118.  * In the default RMMV setting, you can edit the loaded parts of the database
  119.  * but you can't save those changes, as the database's always loaded from the
  120.  * raw json files upon game start
  121.  * With this plugin, all the loaded parts of the database will be saved in
  122.  * savefiles and loaded from those savefiles upon loading those savefiles
  123.  * The default plugin file name is DoubleX RMMV Dynamic Data v101d
  124.  * If you want to change that, you must edit the value of
  125.  * DoubleX_RMMV.Dynamic_Data_File, which must be done via opening the plugin
  126.  * js file directly
  127.  */
  128.  
  129. "use strict";
  130. var DoubleX_RMMV = DoubleX_RMMV || {};
  131. DoubleX_RMMV["Dynamic Data"] = "v1.01d";
  132.  
  133. // The plugin file name must be the same as DoubleX_RMMV.Dynamic_Data_File
  134. DoubleX_RMMV.Dynamic_Data_File = "DoubleX RMMV Dynamic Data v101d";
  135.  
  136. /*============================================================================
  137.  *    ## Plugin Implementations                                              
  138.  *       You need not edit this part as it's about how this plugin works      
  139.  *----------------------------------------------------------------------------
  140.  *    # Plugin Support Info:                                                  
  141.  *      1. Prerequisites                                                      
  142.  *         - Some Javascript coding proficiency to fully comprehend this      
  143.  *           plugin                                                          
  144.  *      2. Function documentation                                            
  145.  *         - The 1st part describes why this function's rewritten/extended for
  146.  *           rewritten/extended functions or what the function does for new  
  147.  *           functions                                                        
  148.  *         - The 2nd part describes what the arguments of the function are    
  149.  *         - The 3rd part informs which version rewritten, extended or created
  150.  *           this function                                                    
  151.  *         - The 4th part informs whether the function's rewritten or new    
  152.  *         - The 5th part informs whether the function's a real or potential  
  153.  *           hotspot                                                          
  154.  *         - The 6th part describes how this function works for new functions
  155.  *           only, and describes the parts added, removed or rewritten for    
  156.  *           rewritten or extended functions only                            
  157.  *         Example:                                                          
  158.  * /*----------------------------------------------------------------------
  159.  *  *    Why rewrite/extended/What this function does                      
  160.  *  *----------------------------------------------------------------------*/
  161. /* // arguments: What these arguments are                                    
  162.  * functionName = function(arguments) { // Version X+; Hotspot                
  163.  *     // Added/Removed/Rewritten to do something/How this function works    
  164.  *     functionContents                                                      
  165.  *     //                                                                    
  166.  * } // functionName                                                          
  167.  *----------------------------------------------------------------------------*/
  168.  
  169. DoubleX_RMMV.Dynamic_Data = {
  170.  
  171.     // Stores all this plugin's parameters that are shown in the plugin manager
  172.     params: PluginManager.parameters(DoubleX_RMMV.Dynamic_Data_File),
  173.  
  174.     baseData: {}
  175.  
  176. };
  177.  
  178. (function(DD) {
  179.  
  180.     Object.keys(DD.params).forEach(function(param) {
  181.         DD[param] = DD.params[param] === "true";
  182.     });
  183.  
  184.     DD.storeBaseData = function() {
  185.         var data = [$dataActors, $dataClasses, $dataSkills, $dataItems];
  186.         data = data.concat([$dataWeapons, $dataArmors, $dataEnemies]);
  187.         data = data.concat([$dataTroops, $dataStates, $dataAnimations]);
  188.         data = data.concat([$dataTilesets, $dataCommonEvents, $dataSystem]);
  189.         var params = Object.keys(DD.params);
  190.         var baseData = DD.baseData;
  191.         for (var index = 0, length = data.length; index < length; index++) {
  192.             baseData[params[index]] = data[index];
  193.         }
  194.     }; // DD.storeBaseData
  195.  
  196.     DD.restoreBaseData = function() {
  197.         var baseData = DD.baseData;
  198.         $dataActors = baseData.dynamicDataActors;
  199.         $dataClasses = baseData.dynamicDataClasses;
  200.         $dataSkills = baseData.dynamicDataSkills;
  201.         $dataItems = baseData.dynamicDataItems;
  202.         $dataWeapons = baseData.dynamicDataWeapons;
  203.         $dataArmors = baseData.dynamicDataArmors;
  204.         $dataEnemies = baseData.dynamicDataEnemies;
  205.         $dataTroops = baseData.dynamicDataTroops;
  206.         $dataStates = baseData.dynamicDataStates;
  207.         $dataAnimations = baseData.dynamicDataAnimations;
  208.         $dataTilesets = baseData.dynamicDataTilesets;
  209.         $dataCommonEvents = baseData.dynamicDataCommonEvents;
  210.         $dataSystem = baseData.dynamicDataSystem;
  211.     }; // DD.restoreBaseData
  212.  
  213.     DD.DataManager = {};
  214.     var DM = DD.DataManager;
  215.  
  216.     DM.saveGameWithoutRescue = DataManager.saveGameWithoutRescue;
  217.     DataManager.saveGameWithoutRescue = function(savefileId) {
  218.         DM.saveDynamicData.call(this); // Added
  219.         DM.saveGameWithoutRescue.apply(this, arguments);
  220.     }; // DataManager.saveGameWithoutRescue
  221.  
  222.     DM.extractSaveContents = DataManager.extractSaveContents;
  223.     DataManager.extractSaveContents = function(savefileId) {
  224.         DM.extractSaveContents.apply(this, arguments);
  225.         DM.loadDynamicData.call(this); // Added
  226.     }; // DataManager.extractSaveContents
  227.  
  228.     DM.saveDynamicData = function() { // New
  229.         var data = [$dataActors, $dataClasses, $dataSkills, $dataItems];
  230.         data = data.concat([$dataWeapons, $dataArmors, $dataEnemies]);
  231.         data = data.concat([$dataTroops, $dataStates, $dataAnimations]);
  232.         data = data.concat([$dataTilesets, $dataCommonEvents, $dataSystem]);
  233.         var params = Object.keys(DD.params);
  234.         if (params.length !== data.length) {
  235.             throw new Error("Errors in reading params from the plugin manager");
  236.         }
  237.         for (var index = 0, length = data.length; index < length; index++) {
  238.             if (DD[params[index]]) { $gameSystem[params[index]] = data[index]; }
  239.         }
  240.     }; // DM.saveDynamicData
  241.  
  242.     DM.loadDynamicData = function() { // New
  243.         if (DD.dynamicDataActors) {
  244.             $dataActors = $gameSystem.dynamicDataActors;
  245.         }
  246.         if (DD.dynamicDataClasses) {
  247.             $dataClasses = $gameSystem.dynamicDataClasses;
  248.         }
  249.         if (DD.dynamicDataSkills) {
  250.             $dataSkills = $gameSystem.dynamicDataSkills;
  251.         }
  252.         if (DD.dynamicDataItems) {
  253.             $dataItems = $gameSystem.dynamicDataItems;
  254.         }
  255.         if (DD.dynamicDataWeapons) {
  256.             $dataWeapons = $gameSystem.dynamicDataWeapons;
  257.         }
  258.         if (DD.dynamicDataArmors) {
  259.             $dataArmors = $gameSystem.dynamicDataArmors;
  260.         }
  261.         if (DD.dynamicDataEnemies) {
  262.             $dataEnemies = $gameSystem.dynamicDataEnemies;
  263.         }
  264.         if (DD.dynamicDataTroops) {
  265.             $dataTroops = $gameSystem.dynamicDataTroops;
  266.         }
  267.         if (DD.dynamicDataStates) {
  268.             $dataStates = $gameSystem.dynamicDataStates;
  269.         }
  270.         if (DD.dynamicDataAnimations) {
  271.             $dataAnimations = $gameSystem.dynamicDataAnimations;
  272.         }
  273.         if (DD.dynamicDataTilesets) {
  274.             $dataTilesets = $gameSystem.dynamicDataTilesets;
  275.         }
  276.         if (DD.dynamicDataCommonEvents) {
  277.             $dataCommonEvents = $gameSystem.dynamicDataCommonEvents;
  278.         }
  279.         if (DD.dynamicDataSystem) {
  280.             $dataSystem = $gameSystem.dynamicDataSystem;
  281.         }
  282.     }; // DM.loadDynamicData
  283.  
  284.     /*------------------------------------------------------------------------
  285.      *    New public instance variables                                      
  286.      *------------------------------------------------------------------------*/
  287.     // The copies of all database parts that will be saved into save files
  288.     Object.keys(DD.params).forEach(function(param) {
  289.         Object.defineProperty(Game_System.prototype, param, {
  290.             get: function() { return this["_" + param]; },
  291.             set: function(data) { this["_" + param] = data; },
  292.             configurable: true
  293.         });
  294.     });
  295.  
  296.     DD.Scene_Boot = {};
  297.     var SB = DD.Scene_Boot;
  298.  
  299.     SB.start = Scene_Boot.prototype.start;
  300.     Scene_Boot.prototype.start = function() {
  301.         SB.start.apply(this, arguments);
  302.         DD.storeBaseData(); // Added to allow using original data for new game
  303.     }; // Scene_Boot.prototype.start
  304.  
  305.     DD.Scene_Title = {};
  306.     var ST = DD.Scene_Title;
  307.  
  308.     ST.start = Scene_Title.prototype.start;
  309.     Scene_Title.prototype.start = function(savefileId) {
  310.         ST.start.apply(this, arguments);
  311.         DD.restoreBaseData(); // Added to use the original data for new game
  312.     }; // Scene_Title.prototype.start
  313.  
  314. })(DoubleX_RMMV.Dynamic_Data);
  315.  
  316. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement