Three relevant methods (cf rpg_managers.js):
- Initialise -
DataManager.createGameObjects - on new game
- Make save data -
DataManager.makeSaveContents - on save
- Read save data -
DataManager.extractSaveContents - on load
I'd suggest aliasing each of these, e.g.
Spoiler: Code example
JavaScript:
(function(alias) {
DataManager.createGameObjects = function() {
alias.apply(this, arguments);
$myClass = new myClass();
};
})(DataManager.createGameObjects);
(function(alias) {
DataManager.makeSaveContents = function() {
var contents = alias.apply(this, arguments);
contents.mySaveProperty = $myClass;
return contents;
};
})(DataManager.makeSaveContents);
(function(alias) {
DataManager.extractSaveContents = function(contents) {
alias.apply(this, arguments);
var data = contents.mySaveProperty;
if (data) $myClass = data;
};
})(DataManager.extractSaveContents);
If you don't want to save the entire object then you can build your own data structure as needed. Also watch out for naming conflicts, as usual: the
contents variable seen here is the data for the entire save file.
Since the save data is recursively passed through JSON
stringify/
parse, primitive values and standard objects are OK; functions, maps, etc will be dropped. Probably not relevant but I thought I'd mention it~
Edit: if you intend this to be a single instance (?) another option could be to store custom save data on an existing object that gets saved, e.g.
$gameSystem. It would increase the chance of naming conflicts, but you wouldn't have to bother with writing custom code to handle new/save/load for those values.