Skip to content

Commit 6668a8d

Browse files
committed
New Events and lint fixes
1 parent b0c74f1 commit 6668a8d

4 files changed

Lines changed: 94 additions & 39 deletions

File tree

src/cameras/2d/effects/RotateTo.js

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -175,31 +175,13 @@ var RotateTo = new Class({
175175
this.shortestPath = false;
176176
},
177177

178-
/**
179-
* This event is fired when the Rotate effect begins to run on a camera.
180-
*
181-
* @event CameraRotateStartEvent
182-
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
183-
* @param {Phaser.Cameras.Scene2D.Effects.RotateTo} effect - A reference to the effect instance.
184-
* @param {integer} duration - The duration of the effect.
185-
* @param {number} angle - The destination angle in radians.
186-
*/
187-
188-
/**
189-
* This event is fired when the Rotate effect completes.
190-
*
191-
* @event CameraRotateCompleteEvent
192-
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
193-
* @param {Phaser.Cameras.Scene2D.Effects.RotateTo} effect - A reference to the effect instance.
194-
*/
195-
196178
/**
197179
* This effect will scroll the Camera so that the center of its viewport finishes at the given angle,
198180
* over the duration and with the ease specified.
199181
*
200182
* @method Phaser.Cameras.Scene2D.Effects.RotateTo#start
201-
* @fires CameraRotateStartEvent
202-
* @fires CameraRotateCompleteEvent
183+
* @fires Phaser.Cameras.Scene2D.Events#ROTATE_START
184+
* @fires Phaser.Cameras.Scene2D.Events#ROTATE_COMPLETE
203185
* @since 3.23.0
204186
*
205187
* @param {number} radians - The destination angle in radians to rotate the Camera viewport to. If the angle is positive then the rotation is clockwise else anticlockwise
@@ -221,17 +203,24 @@ var RotateTo = new Class({
221203
if (force === undefined) { force = false; }
222204
if (callback === undefined) { callback = null; }
223205
if (context === undefined) { context = this.camera.scene; }
224-
if (shortestPath === undefined) {shortestPath = false;}
206+
if (shortestPath === undefined) { shortestPath = false; }
207+
225208
this.shortestPath = shortestPath;
226209

227210
var tmpDestination = radians;
228-
if (radians < 0) {
211+
212+
if (radians < 0)
213+
{
229214
tmpDestination = -1 * radians;
230215
this.clockwise = false;
231-
} else {
216+
}
217+
else
218+
{
232219
this.clockwise = true;
233220
}
221+
234222
var maxRad = (360 * Math.PI) / 180;
223+
235224
tmpDestination = tmpDestination - (Math.floor(tmpDestination / maxRad) * maxRad);
236225

237226
var cam = this.camera;
@@ -267,27 +256,42 @@ var RotateTo = new Class({
267256
this._onUpdateScope = context;
268257

269258

270-
if (this.shortestPath === true) {
271-
// The shotest path is true so calculate the quickest direction
259+
if (this.shortestPath === true)
260+
{
261+
// The shortest path is true so calculate the quickest direction
272262
var cwDist = 0;
273263
var acwDist = 0;
274-
if (this.clockwise === false) {
264+
265+
if (this.clockwise === false)
266+
{
275267
target = this.current;
276268
current = this.destination;
277269
}
278-
if (this.destination > this.source) {
270+
271+
if (this.destination > this.source)
272+
{
279273
cwDist = Math.abs(this.destination - this.source);
280-
} else {
274+
}
275+
else
276+
{
281277
cwDist = (Math.abs(this.destination + maxRad) - this.source);
282-
}
283-
if (this.source > this.destination) {
278+
}
279+
280+
if (this.source > this.destination)
281+
{
284282
acwDist = Math.abs(this.source - this.destination);
285-
} else {
283+
}
284+
else
285+
{
286286
acwDist = (Math.abs(this.source + maxRad) - this.destination);
287-
}
288-
if (cwDist < acwDist) {
287+
}
288+
289+
if (cwDist < acwDist)
290+
{
289291
this.clockwise = true;
290-
} else if (cwDist > acwDist) {
292+
}
293+
else if (cwDist > acwDist)
294+
{
291295
this.clockwise = false;
292296
}
293297
}
@@ -330,22 +334,33 @@ var RotateTo = new Class({
330334
var maxRad = (360 * Math.PI) / 180;
331335
var target = this.destination;
332336
var current = this.current;
333-
if (this.clockwise === false) {
337+
338+
if (this.clockwise === false)
339+
{
334340
target = this.current;
335341
current = this.destination;
336342
}
337-
if (target >= current) {
343+
344+
if (target >= current)
345+
{
338346
distance = Math.abs(target - current);
339-
} else {
347+
}
348+
else
349+
{
340350
distance = (Math.abs(target + maxRad) - current);
341351
}
342352

343353
var r = 0;
344-
if (this.clockwise) {
354+
355+
if (this.clockwise)
356+
{
345357
r = (cam.rotation + (distance * v));
346-
} else {
358+
}
359+
else
360+
{
347361
r = (cam.rotation - (distance * v));
348362
}
363+
349364
cam.rotation = r;
350365

351366
if (this._onUpdate)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Camera Rotate Complete Event.
9+
*
10+
* This event is dispatched by a Camera instance when the Rotate Effect completes.
11+
*
12+
* @event Phaser.Cameras.Scene2D.Events#ROTATE_COMPLETE
13+
* @since 3.23.0
14+
*
15+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
16+
* @param {Phaser.Cameras.Scene2D.Effects.RotateTo} effect - A reference to the effect instance.
17+
*/
18+
module.exports = 'camerarotatecomplete';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* The Camera Rotate Start Event.
9+
*
10+
* This event is dispatched by a Camera instance when the Rotate Effect starts.
11+
*
12+
* @event Phaser.Cameras.Scene2D.Events#ROTATE_START
13+
* @since 3.23.0
14+
*
15+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
16+
* @param {Phaser.Cameras.Scene2D.Effects.RotateTo} effect - A reference to the effect instance.
17+
* @param {integer} duration - The duration of the effect.
18+
* @param {number} destination - The destination value.
19+
*/
20+
module.exports = 'camerarotatestart';

src/cameras/2d/events/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module.exports = {
2121
PAN_START: require('./PAN_START_EVENT'),
2222
POST_RENDER: require('./POST_RENDER_EVENT'),
2323
PRE_RENDER: require('./PRE_RENDER_EVENT'),
24+
ROTATE_COMPLETE: require('./ROTATE_COMPLETE_EVENT'),
25+
ROTATE_START: require('./ROTATE_START_EVENT'),
2426
SHAKE_COMPLETE: require('./SHAKE_COMPLETE_EVENT'),
2527
SHAKE_START: require('./SHAKE_START_EVENT'),
2628
ZOOM_COMPLETE: require('./ZOOM_COMPLETE_EVENT'),

0 commit comments

Comments
 (0)