forked from triacontane/RPGMakerMV
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChangeMapTouchPolicy.js
274 lines (259 loc) · 10.6 KB
/
ChangeMapTouchPolicy.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//=============================================================================
// ChangeMapTouchPolicy.js
// ----------------------------------------------------------------------------
// (C)2015-2018 Triacontane
// This plugin is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
// ----------------------------------------------------------------------------
// Version
// 1.1.0 2018/03/01 パラメータの型指定機能に対応。マップタッチ移動時の強制ダッシュを無効にする機能を追加。
// 1.0.1 2016/09/11 レベル「簡易」の時の押し続け判定を変更
// 1.0.0 2015/11/18 初版
// ----------------------------------------------------------------------------
// [Blog] : https://triacontane.blogspot.jp/
// [Twitter]: https://twitter.com/triacontane/
// [GitHub] : https://github.com/triacontane/
//=============================================================================
/*:
* @plugindesc Plugin that change policy of 'map touch'
* @author triacontane
*
* @param initPolicyLevel
* @desc Initial value of policy level
* @option 1 : invalid
* @value 1
* @option 2 : simple
* @value 2
* @option 3 : normal
* @value 3
* @option 4 : excessive
* @value 4
*
* @param invalidForceDash
* @desc マップタッチ移動時の強制ダッシュを無効にしてShiftキーを押している間のみダッシュします。スマホ版は除く。
* @default false
* @type boolean
*
* @help Plugin that change policy of 'map touch'
* There are four stages
*
* 1 : 'map touch' become invalid
* 2 : 'map touch' become simple(move one step)
* 3 : 'map touch' become normal(default policy)
* 4 : 'map touch' become excessive(auto track to pointer)
*
* Plugin Command
* CHANGE_MTP [policy level] : change policy of 'map touch'
* ex:CHANGE_MTP 3
*
* This plugin is released under the MIT License.
*/
/*:ja
* @plugindesc マップタッチ仕様変更プラグイン
* @author トリアコンタン
*
* @param initPolicyLevel
* @text 仕様レベル初期値
* @desc 初期状態でのマップタッチの仕様レベル
* @default 3
* @type select
* @option 1 : 無効
* @value 1
* @option 2 : 簡易
* @value 2
* @option 3 : 通常
* @value 3
* @option 4 : 過剰
* @value 4
*
* @param invalidForceDash
* @text 強制ダッシュ無効
* @desc マップタッチ移動時の強制ダッシュを無効にしてShiftキーを押している間のみダッシュします。スマホ版は除く。
* @default false
* @type boolean
*
* @help マップをタッチした際の移動の仕方を4種類から変更できます。
* パラメータの「仕様レベル初期値」を設定してください。
* 1 : 無効「マップをタッチしてもプレイヤーは動きません」
* 2 : 簡易「マップをタッチするとプレイヤーが一マスだけ動きます」
* (指定位置へは移動しません。タッチし続けると移動を続けます)
* 3 : 通常「マップをタッチするとその位置へプレイヤーが動きます」
* (もともとの仕様です)
* 4 : 過剰「一度でもマップクリックすると以後、プレイヤーがポインタを追跡します」
* (もう一度クリックすると移動を止めます)
*
* プラグインコマンド詳細
* イベントコマンド「プラグインコマンド」から実行。
* (引数の間は半角スペースで区切る)
*
* CHANGE_MTP [仕様レベル] : マップタッチの仕様レベルを変更します。
* 例:CHANGE_MTP 3
*
* 利用規約:
* 作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
* についても制限はありません。
* このプラグインはもうあなたのものです。
*/
(function () {
var getArgNumber = function (arg, min, max) {
if (arguments.length < 2) min = -Infinity;
if (arguments.length < 3) max = Infinity;
return (parseInt(convertEscapeCharacters(arg)) || 0).clamp(min, max);
};
var convertEscapeCharacters = function(text) {
if (text == null) text = '';
var windowLayer = SceneManager._scene._windowLayer;
return windowLayer ? windowLayer.children[0].convertEscapeCharacters(text) : text;
};
/**
* Create plugin parameter. param[paramName] ex. param.commandPrefix
* @param pluginName plugin name(EncounterSwitchConditions)
* @returns {Object} Created parameter
*/
var createPluginParameter = function(pluginName) {
var paramReplacer = function(key, value) {
if (value === 'null') {
return value;
}
if (value[0] === '"' && value[value.length - 1] === '"') {
return value;
}
try {
return JSON.parse(value);
} catch (e) {
return value;
}
};
var parameter = JSON.parse(JSON.stringify(PluginManager.parameters(pluginName), paramReplacer));
PluginManager.setParameters(pluginName, parameter);
return parameter;
};
var param = createPluginParameter('ChangeMapTouchPolicy');
//=============================================================================
// Game_Interpreter
// プラグインコマンド[CHANGE_MTP]などを追加定義します。
//=============================================================================
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
_Game_Interpreter_pluginCommand.apply(this, arguments);
if (command.toUpperCase() === 'CHANGE_MTP') {
$gameSystem._mapTouchPolicy = getArgNumber(args[0], 1, 4);
}
};
//=============================================================================
// Game_Temp
// 移動開始フラグを追加定義します。
//=============================================================================
var _Game_Temp_initialize = Game_Temp.prototype.initialize;
Game_Temp.prototype.initialize = function() {
_Game_Temp_initialize.apply(this, arguments);
this._moveStart = false;
};
//=============================================================================
// Game_System
// 仕様レベルの初期値を追加定義します。
//=============================================================================
var _Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_Game_System_initialize.apply(this, arguments);
this._mapTouchPolicy = param.initPolicyLevel;
};
var _Game_Player_updateDashing = Game_Player.prototype.updateDashing;
Game_Player.prototype.updateDashing = function() {
_Game_Player_updateDashing.apply(this, arguments);
if (!param.invalidForceDash || Utils.isMobileDevice() || this.isMoving()) {
return;
}
if (this.canMove() && !this.isInVehicle() && !$gameMap.isDashDisabled()) {
this._dashing = this.isDashButtonPressed();
}
};
//=============================================================================
// Scene_Map
// 仕様レベルによってマップタッチの挙動を変更します。
//=============================================================================
var _Scene_Map_isMapTouchOk = Scene_Map.prototype.isMapTouchOk;
Scene_Map.prototype.isMapTouchOk = function() {
var result = $gameSystem._mapTouchPolicy !== 1 && _Scene_Map_isMapTouchOk.call(this);
if (!result) $gameTemp._moveStart = false;
return result;
};
var _Scene_Map_processMapTouch = Scene_Map.prototype.processMapTouch;
Scene_Map.prototype.processMapTouch = function() {
switch ($gameSystem._mapTouchPolicy) {
case 2:
this.processMapTouchLevel2();
break;
case 3:
_Scene_Map_processMapTouch.call(this);
break;
case 4:
this.processMapTouchLevel4();
break;
}
};
Scene_Map.prototype.processMapTouchLevel2 = function() {
if (TouchInput.isTriggered() || TouchInput.isLongPressed()) {
var px = $gamePlayer.x;
var py = $gamePlayer.y;
var deltaX = $gameMap.deltaX($gameMap.canvasToMapX(TouchInput.x), px);
var deltaY = $gameMap.deltaY($gameMap.canvasToMapY(TouchInput.y), py);
var d = 0;
if (Math.abs(deltaX) < Math.abs(deltaY)) {
if (deltaY > 0) d = 2;
if (deltaY < 0) d = 8;
} else {
if (deltaX > 0) d = 6;
if (deltaX < 0) d = 4;
}
if (d === 0) return;
if (!$gamePlayer.isMapPassable(px, py, d)) {
if (Math.abs(deltaX) < Math.abs(deltaY)) {
if (deltaX > 0) d = 6;
if (deltaX < 0) d = 4;
} else {
if (deltaY > 0) d = 2;
if (deltaY < 0) d = 8;
}
}
if (d === 0) return;
if ($gamePlayer.isMapPassable(px, py, d)) {
switch (d) {
case 2:
py++;
break;
case 4:
px--;
break;
case 6:
px++;
break;
case 8:
py--;
break;
}
$gameTemp.setDestination(px, py);
$gameTemp._moveStart = true;
}
}
};
Scene_Map.prototype.processMapTouchLevel4 = function() {
var x = $gameMap.canvasToMapX(TouchInput.x);
var y = $gameMap.canvasToMapY(TouchInput.y);
if (TouchInput.isTriggered()) $gameTemp._moveStart = !$gameTemp._moveStart;
if ($gameTemp._moveStart) {
$gameTemp.setDestination(x, y);
} else {
$gameTemp.clearDestination();
}
};
//=============================================================================
// TouchInput
// ポインタ移動時にマウス位置の記録を常に行うように元の処理を上書き
//=============================================================================
TouchInput._onMouseMove = function(event) {
var x = Graphics.pageToCanvasX(event.pageX);
var y = Graphics.pageToCanvasY(event.pageY);
this._onMove(x, y);
};
})();