-
Notifications
You must be signed in to change notification settings - Fork 25
/
TTK_DraggableCamera.js
233 lines (199 loc) · 7.04 KB
/
TTK_DraggableCamera.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
//=============================================================================
// TTK - Draggable Camera (v1.1.4)
// by Fogomax
//=============================================================================
/*:
* @author Fogomax
* @plugindesc This plugin allows the player to drag and move the camera
* with the mouse or touch
*
<TTK DraggableCamera>
* @help
* ===========================================================================
* * Explanation
* ===========================================================================
* This plugins allows the player to drag and move the camera with the mouse
* or touch
*
* ===========================================================================
* * Use
* ===========================================================================
* To turn on/off the plugin, user the following plugin command:
* - DraggableCamera setEnabled x
* Here "x" can be "true" (on) or "false" (off), without the ("). Example:
* - DraggableCamera setEnabled true
@param Start On
@desc If the screen is draggable in the begin of game
@default true
@param Cancel Player Move
@desc Cancel the player move when the camera is moved
@default true
@param Speed
@desc Speed of move (the higher the faster). E. g.: 2.3.
@default 1
@param Distance Limit
@desc The max distance that a single drag can move, this prevents unexpected moves.
@default 10
*/
"use strict";
var Imported = Imported || {};
Imported["TTK_DraggableCamera"] = "1.1.4";
var TTK = TTK || {};
TTK.DraggableCamera = {};
(function($) {
$.Params = $plugins.filter(function(p) { return p.description.contains('<TTK DraggableCamera>'); })[0].parameters;
//-----------------------------------------------------------------------------
// Plugin global variables
//
$.cancelPlayerMove = ($.Params["Cancel Player Move"].toLowerCase() === 'true');
$.enabled = ($.Params["Start On"].toLowerCase() === 'true');
$.speed = parseFloat($.Params["Speed"]);
$.distanceLimit = parseInt($.Params['Distance Limit']);
$.denyMove = false;
//-----------------------------------------------------------------------------
// TouchInput
//
var _TouchInput_clear = TouchInput.clear;
TouchInput.clear = function() {
_TouchInput_clear.call(this);
this._lastCameraX = 0;
this._lastCameraY = 0;
this._cameraAccX = 0;
this._cameraAccY = 0;
this._storForceX = 0;
this._storForceY = 0;
};
if (TTK.SwipeMove && $.enabled) {
var _TouchInput_update = TouchInput.update;
TouchInput.update = function() {
_TouchInput_update.call(this);
if (this._cameraAccX && $gameMap) {
if (this._cameraAccX > 0) {
$gameMap._displayX -= this._cameraAccX / 48;
this._cameraAccX = (this._cameraAccX - this._storForceX < 0) ? (0) : (this._cameraAccX - this._storForceX);
}
if (this._cameraAccX < 0) {
$gameMap._displayX -= this._cameraAccX / 48;
this._cameraAccX = (this._cameraAccX - this._storForceX > 0) ? (0) : (this._cameraAccX - this._storForceX);
}
}
if (this._cameraAccY && $gameMap) {
if (this._cameraAccY > 0) {
$gameMap._displayY -= this._cameraAccY / 48;
this._cameraAccY = (this._cameraAccY - this._storForceY < 0) ? (0) : (this._cameraAccY - this._storForceY);
}
if (this._cameraAccY < 0) {
$gameMap._displayY -= this._cameraAccY / 48;
this._cameraAccY = (this._cameraAccY - this._storForceY > 0) ? (0) : (this._cameraAccY - this._storForceY);
}
}
};
}
var _TouchInput_onTrigger = TouchInput._onTrigger;
TouchInput._onTrigger = function(x, y) {
if (this.isMoved()) return;
_TouchInput_onTrigger.call(this, x, y);
this._lastCameraX = this.x;
this._lastCameraY = this.y;
};
var _TouchInput_onMove = TouchInput._onMove;
TouchInput._onMove = function(x, y) {
if ($.cancelPlayerMove)
$.denyMove = true;
this._lastCameraX = this.x;
this._lastCameraY = this.y;
_TouchInput_onMove.call(this, x, y);
};
var _TouchInput_onRelease = TouchInput._onRelease;
TouchInput._onRelease = function(x, y) {
_TouchInput_onRelease.call(this, x, y);
if (TTK.SwipeMove) {
this._cameraAccX = this._forceX;
this._cameraAccY = this._forceY;
this._storForceX = this._forceX / 48;
this._storForceY = this._forceY / 48;
}
if ($.denyMove) $.denyMove = false;
};
//-----------------------------------------------------------------------------
// Scene_Map
//
var _Scene_Map_initialize = Scene_Map.prototype.initialize;
Scene_Map.prototype.initialize = function() {
_Scene_Map_initialize.call(this);
};
var _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
if (TouchInput.isMoved() && $.enabled) {
var newX = ((TouchInput._lastCameraX - TouchInput.x) / 48) * $.speed;
var newY = ((TouchInput._lastCameraY - TouchInput.y) / 48) * $.speed;
if (newX) $gameMap._displayX += Math.min(newX, $.distanceLimit);
if (newY) $gameMap._displayY += Math.min(newY, $.distanceLimit);
}
if ((TouchInput.isMoved() || TouchInput._cameraAccX || TouchInput._cameraAccY) && $.enabled) {
if ($gameMap._displayX + Graphics.width / 48 >= $dataMap.width) {
$gameMap._displayX = $dataMap.width - Graphics.width / 48;
if (TTK.SwipeMove) {
TouchInput._cameraAccX = 0;
TouchInput._storForceX = 0;
}
}
else if ($gameMap._displayX <= 0) {
$gameMap._displayX = 0;
if (TTK.SwipeMove) {
TouchInput._cameraAccX = 0;
TouchInput._storForceX = 0;
}
}
if ($gameMap._displayY + Graphics.height / 48 >= $dataMap.height) {
$gameMap._displayY = $dataMap.height - Graphics.height / 48;
if (TTK.SwipeMove) {
TouchInput._cameraAccY = 0;
TouchInput._storForceY = 0;
}
} else if ($gameMap._displayY <= 0) {
$gameMap._displayY = 0;
if (TTK.SwipeMove) {
TouchInput._cameraAccY = 0;
TouchInput._storForceY = 0;
}
}
}
};
//-----------------------------------------------------------------------------
// Game_Player
//
var _Game_Player_moveByInput = Game_Player.prototype.moveByInput;
Game_Player.prototype.moveByInput = function() {
if ($.cancelPlayerMove && $.enabled) {
if (!this.isMoving() && this.canMove() && !$.denyMove) {
var direction = this.getInputDirection();
if (direction > 0) {
$gameTemp.clearDestination();
} else if ($gameTemp.isDestinationValid()) {
var x = $gameTemp.destinationX();
var y = $gameTemp.destinationY();
direction = this.findDirectionTo(x, y);
}
if (direction > 0) {
this.executeMove(direction);
}
}
} else {
_Game_Player_moveByInput.call(this);
}
};
//-----------------------------------------------------------------------------
// Plugin command
//
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() === "draggablecamera") {
if (args[0].toLowerCase() === "setenabled") {
$.enabled = (args[1].toLowerCase() === 'true');
}
}
};
})(TTK.DraggableCamera);