Good idea! That sounds like a much neater solution~ 😮💨
That's my fault: there are various problems with what I posted. 👋
For that approach, you would need something like @TG22 suggested. However, there are a couple of differences:
Then:
- MV's
StorageManager.saveandloadmethods (different names than in MZ) expect a save ID rather than a file name, so you'd still need the conversion stuff I suggested.
- As noted, MV's load operations block execution until complete, so the
thenclause (for an async "Promise") should simply be removed.
JavaScript:
;void (function() {
'use strict';
/** Matched against custom per-slot save ID, see {@linkcode extractId}. */
const RX = /JDN_(\d+)/;
/** New local save file name. `%1` = slot ID. */
const FILENAME = "jdn_data%1.rpgsave";
/** New web storage data key. `%1` = slot ID. */
const WEB_KEY = "RPG JDN%1";
/**
* @param {*} value input internal file ID.
* @returns {?number} corresponding slot ID, or `null` if not applicable.
*/
const extractId = function(value) {
if (typeof value === "string") {
const match = RX.exec(value);
if (match)
return parseInt(match[1], 10);
}
return null;
};
// Patch - map custom ID (`"JDN_%1"`) to custom file name.
void (function() {
const alias = StorageManager.localFilePath;
StorageManager.localFilePath = function(savefileId) {
const id = extractId(savefileId);
if (id)
return SAVE_NAME.format(id);
return alias.apply(this, arguments);
};
})();
// Patch - map custom ID (`"JDN_%1"`) to custom web storage key.
void (function() {
const alias = StorageManager.webStorageKey;
StorageManager.webStorageKey = function(savefileId) {
const id = extractId(savefileId);
if (id)
return SAVE_NAME.format(id);
return alias.apply(this, arguments);
};
})();
})();
- Save (modelled on
DataManager.saveGame, rpg_managers.js):
JavaScript:const data = $gameVariables.value(1), id = "JDN_1"; StorageManager.backup(id); try { StorageManager.save(id, data) StorageManager.cleanBackup(id); } catch (ex) { console.error(ex); StorageManager.remove(id); StorageManager.restoreBackup(id); } - Load (modelled on
DataManager.loadGame, rpg_managers.js):
JavaScript:const id = "JDN_1"; try { $gameVariables.setValue(1, StorageManager.load(id)); } catch (ex) { console.error(ex); }
It reduces the file size, and gets unzipped automatically on load. This page claims the limit on local storage is currently 5 MiB per origin:
Storage quotas and eviction criteria - Web APIs | MDN
Web developers can use a number of technologies to store data in the user's browser (i.e., on the local disk of the device the user is using to view the website).