ModSaveDataPlugin

VolcoV

Villager
Member
Joined
May 6, 2020
Messages
5
Reaction score
2
First Language
Spanish
Primarily Uses
RMMV
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
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,282
Reaction score
4,406
First Language
English
Primarily Uses
RMMV
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!
 

VolcoV

Villager
Member
Joined
May 6, 2020
Messages
5
Reaction score
2
First Language
Spanish
Primarily Uses
RMMV
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.
 

VolcoV

Villager
Member
Joined
May 6, 2020
Messages
5
Reaction score
2
First Language
Spanish
Primarily Uses
RMMV
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

lunarrosecrow wrote on hiddenone's profile.
please don't lurk hiddenone I'm quarantining!!!
lunarrosecrow wrote on Edward.T's profile.
Hello Edward sorry to bother you and didn't start a conversation cause I thought i'd be a little weird or disrespectful but I was wondering do you still have your Generator resources you posted as the links on the page are dead?
Stream will be live shortly! It is my birthday, and thus I am doing an extended stream! I will be doing a variety of things. Among the activities I will be doing: Playing Oceanhorn: Monster of the Uncharted Seas, art, and some Text Adventure~ Feel free to drop by!
It would be cool if you could "copy as code" event commands :< .
Just managed to recover my Yahoo e-mail that i lost 3 months ago. Turns out an IP from U.S had hacked it and set the pass back to normal.. Like WTF ?

Forum statistics

Threads
99,484
Messages
965,916
Members
131,111
Latest member
HannyBee21
Top