Whether save data is available
Internal
saveEvent triggered after a save slot is selected and before loading data from the save to all game objects (such as tWgm.tGameCharactor)
Each mod's save object is available in the handler.
Internal
saveEvent triggered when collecting save objects from each mod
Adds handlers for the save object of your mod
By adding these handlers, you can store and retrieve your mod's save object to/from the save.
Example:
// `init.js` of `sample4` mod, which counts how many times you performed saving
(function () {
const logger = maginai.logging.getLogger('sample4');
// Variable for counting saving
let saveCount;
maginai.modSave.addSaveObjectHandlers(
// `name` - Mod's name
'sample4',
// `notFoundHandler` - Called when no existing save object for `name`
(isNewGame) => {
// Initialize saveCount
saveCount = 0;
// Show a message and whether it's a new game
logger.info(
`'sample4' is applied to this save for the first time. isNewGame: ${isNewGame}`
);
},
// `loadHandler` - Called when existing save object found for `name`
(saveObj) => {
saveCount = saveObj.saveCount;
// Show the `saveCount` loaded from the save
logger.info(
`Save object has been loaded. saveCount:` + saveCount.toString()
);
},
// `saveHandler` - Should return a save object to be written for `name`
() => {
// Increment `saveCount` by 1
saveCount += 1;
// Show the current `saveCount`
logger.info(
`Save object has been saved. saveCount:` + saveCount.toString()
);
// Return a new save object
return { saveCount };
}
);
})();
Mod's name
Called when the selected save is loading, but there's no existing save object for name
in it
Called when the selected save is loading, and saveObject
is the existing save object for name
Called just before saving, and it should return a save object for name
to be written
maginai.modSave
submodule classDo not instantiate directly; use from
maginai.modSave
.You can store and retrieve a json-serializable object for each
name
to/from the save.In this document, we call the object 'save object'.
name
is the unique key for the corresponding save object; usually, mod's name is used to avoid conflict with other mods' save objects.Use addSaveObjectHandlers for standard store/retrieve handling.
See the detail and examples of the method.
In few cases, you might need to use getSaveObject, setSaveObject or removeSaveObject directly.
You can call these methods at any time as long as a save is loaded.
Use
getSaveObject(name)
to obtain the save object forname
from the current save.Use
setSaveObject(name, obj)
to setobj
as a save object forname
.Use
removeSaveObject(name)
to delete the save object forname
.The changes made by
setSaveObject
andremoveSaveObject
will be written to the current save the next time save operation is performed.Each of these methods throws an exception if no save data is loaded, such as on the title screen.
Notes:
addSaveObjectHandlers
is the same as:name
results in operation on the same save object. You can use this to extend other modstWgm.isL
is set totrue
, the save size will be logged to the dev console when a save operation is performed