1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RPGツクールMV セーブデータを拡張する

Posted at

RPGツクールMVのセーブデータに新たに項目を追加してみます。

セーブデータはBase64に変換されていますがやっぱりJsonです。
DataManagerの各メソッドでセーブ対象のオブジェクトを設定し、それをシリアライズして保存しているだけでシンプルです。
なので、スクリプトで各メソッドを上書きし、セーブ対象のオブジェクトにプロパティを追加すれば一緒に保存されます。

以下のスクリプトでは$gameExというセーブデータを追加しています。
$gameExは数値にしていますが、文字列でもオブジェクトでも問題ないはずです。

// 追加するセーブデータの変数
// セーブデータ類はグローバルスコープに定義されているので、クロージャ[function(){...}();]の外に出す
// 他のプラグインとかぶらないように名前を決める必要がある
// 既存の変数は全て$game〜という名前になっているので統一すると分かりやすいかも
var $gameEx = 0;

(function() {
	// 初期値の設定
	// 新しくゲームを始めた時に呼ばれる
	var createGameObjects = DataManager.createGameObjects;
	DataManager.createGameObjects = function() {
		createGameObjects.call(this);
		$gameEx = 0;
	};

	// セーブデータの生成
	// 返り値がセーブされるのでデータをcontentsに追加して返す
	var makeSaveContents = DataManager.makeSaveContents;
	DataManager.makeSaveContents = function() {
		var contents = makeSaveContents.call(this);
		contents.ex = $gameEx;
		return contents;
	};

	// セーブデータの読み込み
	// 生成時と同じ形でデータがcontentsに入っているので、変数に格納する
	var extractSaveContents = DataManager.extractSaveContents;
	DataManager.extractSaveContents = function(contents) {
		extractSaveContents.call(this, contents);
		$gameEx = contents.ex;
	};
})();
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?