63 lines
2.4 KiB
JavaScript
63 lines
2.4 KiB
JavaScript
//=============================================================================
|
||
// RPG Maker MZ - KN_Save.js
|
||
//=============================================================================
|
||
|
||
/*:ja
|
||
* @target MZ
|
||
* @author kurogoma knights
|
||
* @base PluginCommonBase
|
||
* @plugindesc セーブ改変 テスト時は平文、リリース時は暗号化
|
||
*/
|
||
|
||
(() => {
|
||
'use strict';
|
||
const script = document.currentScript;
|
||
const param = PluginManagerEx.createParameter(script);
|
||
|
||
// テストプレイ判定
|
||
const isTestPlay = Utils.isOptionValid("test");
|
||
|
||
// 平文使用判定(テストプレイ時は常に平文、リリース時はパラメータに従う)
|
||
const usePlainText = isTestPlay;
|
||
// const usePlainText = true; // trueにするとビルド版でも平文保存になる
|
||
|
||
|
||
// JsonEx.stringifyの差し替え(平文時のみ整形版を使用)
|
||
const _JsonEx_stringify = JsonEx.stringify;
|
||
JsonEx.stringify = function(object) {
|
||
return usePlainText ? JsonEx.stringifySpace(object) : _JsonEx_stringify.call(this, object);
|
||
};
|
||
|
||
// save(コアの実装を利用)
|
||
StorageManager.saveObject = function(saveName, object) {
|
||
if (usePlainText) {
|
||
// 平文:objectToJson → saveZip(圧縮スキップ)
|
||
return this.objectToJson(object)
|
||
.then(json => this.saveZip(saveName, json));
|
||
} else {
|
||
// 暗号化:objectToJson → jsonToZip → saveZip
|
||
return this.objectToJson(object)
|
||
.then(json => this.jsonToZip(json))
|
||
.then(zip => this.saveZip(saveName, zip));
|
||
}
|
||
};
|
||
|
||
// load(コアの実装を利用、失敗したら平文で試す)
|
||
StorageManager.loadObject = function(saveName) {
|
||
// まず本家の方法(圧縮データ)で読み込み
|
||
return this.loadZip(saveName)
|
||
.then(zip => this.zipToJson(zip))
|
||
.then(json => this.jsonToObject(json))
|
||
.catch(() => {
|
||
// 失敗したら平文として試す
|
||
return this.loadFromLocalFile(saveName)
|
||
.then(data => this.jsonToObject(data));
|
||
});
|
||
};
|
||
|
||
// 平文保存用の整形関数
|
||
JsonEx.stringifySpace = function(object) {
|
||
return JSON.stringify(this._encode(object, 0), null, 2);
|
||
};
|
||
|
||
})();
|