-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMrTS_GlobalSavesData.js
154 lines (136 loc) · 5.09 KB
/
MrTS_GlobalSavesData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//=============================================================================
// MrTS_GlobalSavesData.js
//=============================================================================
/*:
* @plugindesc Allows player to set and change variables that affect all saves.
* @author Mr. Trivel
*
* @help
* --------------------------------------------------------------------------------
* Terms of Use
* --------------------------------------------------------------------------------
* Don't remove the header or claim that you wrote this plugin.
* Credit Mr. Trivel if using this plugin in your project.
* Free for commercial non-commercial projects.
* --------------------------------------------------------------------------------
* Version 1.0
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* GlobalVar Set [NAME] [VALUE] - Sets variable to [VALUE]
* GlobalVar Add [NAME] [VALUE] - Adds [VALUE] to variable
* GlobalVar Sub [NAME] [VALUE] - Subtracts [VALUE] from value
*
* [NAME] - Variable name, case sensitive
* [VALUE] - Value of variable a number or true/false
*
* Examples:
* GlobalVar Set Glasses true
*
* GlobalVar Set GameCompleted 1
* GlobalVar Add GameCompleted 1
* GlobalVar Sub GameCompleted 2
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Script Calls - for use in switches, variables, branches and script calls
* --------------------------------------------------------------------------------
* DataManager.getGlobalVar(NAME) - returns global variable of NAME
*
* Example:
* DataManager.getGlobalVar(Glasses)
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.0 - Release
*/
(function() {
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "globalvar") {
switch (args[0].toUpperCase())
{
case 'SET':
{
DataManager.setGlobalVar(args[1], eval(args[2]))
} break;
case 'ADD':
{
DataManager.addGlobalVar(args[1], Number(args[2]))
} break;
case 'SUB':
{
DataManager.setGlobalVar(args[1], Number(args[2]))
} break;
}
}
};
//--------------------------------------------------------------------------
// StorageManager
//
var _StorageManager_localFilePath = StorageManager.localFilePath;
StorageManager.localFilePath = function(key) {
if (key === 'globalsavedata') return this.localFileDirectoryPath() + 'globalSaveData.rpgsave';
else return _StorageManager_localFilePath.call(this, key);
};
var _StorageManager_webStorageKey = StorageManager.webStorageKey;
StorageManager.webStorageKey = function(key) {
if (key === 'globalsavedata') return 'RPG GlobalSaveData';
else return _StorageManager_webStorageKey.call(this, key);
};
//--------------------------------------------------------------------------
// DataManager
//
var _DataManager_loadGameWithoutRescue = DataManager.loadGameWithoutRescue;
DataManager.loadGameWithoutRescue = function(savefileId) {
var success = _DataManager_loadGameWithoutRescue.call(this, savefileId);
if (success) this._globalSaveData = this.loadGlobalSaveData();
return success;
};
var _DataManager_setupNewgame = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
_DataManager_setupNewgame.call(this);
this._globalSaveData = this.loadGlobalSaveData();
};
DataManager.setGlobalVar = function(name, value) {
this._globalSaveData[name] = value;
};
DataManager.addGlobalVar = function(name, value) {
if (!this._globalSaveData[name]) this._globalSaveData[name] = 0;
this._globalSaveData[name] += value;
};
DataManager.subGlobalVar = function(name, value) {
this.addGlobalVar(name, -value);
};
DataManager.getGlobalVar = function(name) {
if (!this._globalSaveData[name]) this._globalSaveData[name] = 0;
return this._globalSaveData[name];
};
DataManager.loadGlobalSaveData = function() {
var data = StorageManager.load('globalsavedata');
if (data)
{
return JsonEx.parse(data);
}
else return {};
};
var _DataManager_saveGameWithoutRescue = DataManager.saveGameWithoutRescue;
DataManager.saveGameWithoutRescue = function(savefileId) {
var saved = _DataManager_saveGameWithoutRescue.call(this, savefileId);
if (saved) {
this.saveGlobalSaveData(this._globalSaveData);
}
return saved;
};
DataManager.saveGlobalSaveData = function(data) {
StorageManager.save('globalsavedata', JSON.stringify(data));
};
})();