ModSaveDataPlugin

I wish to share my save data plugin with no copyright/license restritions. I wish to purpose as a convenant of mods memory usage where the main core objects doesn't need to be modified adding attributes.

Data stored in $modData object is 100% serializable and will be stored when game is saved and any plugin that uses ModSaveDataPlugin won't have any problem with other mods compatibilities beacause their data will be isolated from other mods data.

Also data will have a better and visual structure.

JavaScript:
//=============================================================================
// ModSaveDataPlugin.js
//=============================================================================
/*:
* @plugindesc Mod that provides a serializable object for mod data saving.
* @author VolcoV
*
* @help
*
* Mod data plugin provides a new serializable object: $modData wich can store
* any kind of JSON data from scripts. (As serializable object, it will be
* saved and loaded on save/load game).
*
* Use example:
*
* $modData.myProfessionsMod = {
*  alchemy: {
*    character: 1,
*    level: 3,
*    exp: 61,
*    nextLevel: 127
*  },
*  smithing: {
*    character: 1,
*    level: 3,
*    exp: 61,
*    nextLevel: 127
*  }
* };
*
* const alchemyLevel = $modData.myProfessionsMod.alchemy.level;
*
*
* Why should I use ModSaveData:
*
* - No license comercial/personal restrictions. That plugis is under MIT
*   license: https://opensource.org/licenses/MIT
* - Less plugins incompatibilities: data structure is isolated from
*   core structure
* - Data is saved when game is saved and restored when game is loaded.
*
* Usage:
*
* - Plugin must be included listed before the plugins that will use $modData.
* - $modData will be cleared on new game start. If your plugin needs to add
*   initial data to $modData consider to add this data modifying
*   DataManager.setupNewGame in your plugin. Example:
*
*  let _DataManager_setupNewGame = DataManager.setupNewGame;
*  DataManager.setupNewGame = function() {
*    _DataManager_setupNewGame.call(this);
*    $modData.myPluginData = {
*      yourPlugin: 'initializationExample'
*    };
*  }
*
* @link JSON format documentation: https://www.json.org/json-en.html
*/
(() => {
    window['$modData'] = {};
    let _DataManager_makeSaveContents = DataManager.makeSaveContents;
    DataManager.makeSaveContents = function () {
        const contents = _DataManager_makeSaveContents.call(this);
        contents.modData = $modData;
        return contents;
    };
    let _DataManager_extractSaveContents = DataManager.extractSaveContents;
    DataManager.extractSaveContents = function (contents) {
        _DataManager_extractSaveContents.call(this, contents);
        $modData = contents.modData || {};
    };
    let _DataManager_setupNewGame = DataManager.setupNewGame;
    DataManager.setupNewGame = function() {
        _DataManager_setupNewGame.call(this);
        $modData = {};
    };
})();

Version: 1.0.0
Last update: 29/06/2020
This is actually very helpful, as a programmer I will be using this if I have a project in MV. Perfect example of a simple feature, but very helpful. Thank you!
This is actually very helpful, as a programmer I will be using this if I have a project in MV. Perfect example of a simple feature, but very helpful. Thank you!
Thats what i've been looking for: simple, flexible and useful. Please notice me about any possible bug or feature, I will try to keep that post updated.
FIrst: I've added a sematic version as described in npmjs documentation.

I've found a bug which was solved. It may contain some breaking changes so I will tell how to update the plugin. If an older version than 1.0.0 is being used (published at 29-06-2020)

The problem:

The plugin may not be removing stored data when a new game is created. This will cause that if you go to main screen from an advanced game and create a new game, $modData will remain the other saved game data.

The solution:

To avoid the current issue, $modData will be cleared each time a new game is created. This would cause some problem if a plugin initializes data on first load so, i suggest to initialize data using DataManager.setupNewGame method.
Example:

Code:
let _DataManager_setupNewGame = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
  _DataManager_setupNewGame.call(this); // backtracking call (keep default functionality)
  $modData.myPluginData = {
      // Place here your initial data so it will be initialized when a new game is created
    yourPlugin: 'initializationExample'
  };
}

I apologize for any possible inconvenience. Any bugs found or suggestions for improvement are always welcome.

Original thread: https://forums.rpgmakerweb.com/threads/modsavedataplugin.123348/