Skip to content

Commit ff7119d

Browse files
authored
Merge pull request phaserjs#3422 from orblazer/fix-types
Fix types and begin object TypeDef
2 parents 4de9719 + 45158c2 commit ff7119d

35 files changed

Lines changed: 348 additions & 270 deletions

src/animations/Animation.js

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,58 @@ var Class = require('../utils/Class');
88
var Frame = require('./AnimationFrame');
99
var GetValue = require('../utils/object/GetValue');
1010

11+
/**
12+
* @typedef {object} JSONAnimation
13+
*
14+
* @property {string} key - [description]
15+
* @property {string} type - A frame based animation (as opposed to a bone based animation)
16+
* @property {JSONAnimationFrame[]} frames - [description]
17+
* @property {integer} frameRate - The frame rate of playback in frames per second (default 24 if duration is null)
18+
* @property {integer} duration - How long the animation should play for.
19+
* @property {boolean} skipMissedFrames - Skip frames if the time lags, or always advanced anyway?
20+
* @property {integer} delay - Delay before starting playback (in seconds)
21+
* @property {integer} repeat - Number of times to repeat the animation (-1 for infinity)
22+
* @property {integer} repeatDelay - Delay before the repeat starts (in seconds)
23+
* @property {boolean} yoyo - Should the animation yoyo? (reverse back down to the start) before repeating?
24+
* @property {boolean} showOnStart - Should sprite.visible = true when the animation starts to play?
25+
* @property {boolean} hideOnComplete - Should sprite.visible = false when the animation finishes?
26+
*/
27+
28+
/**
29+
* @typedef {object} AnimationFrameConfig
30+
*
31+
* @property {string} key - [description]
32+
* @property {string|number} frame - [description]
33+
* @property {float} [duration=0] - [description]
34+
* @property {boolean} [visible] - [description]
35+
* @property {function} [onUpdate] - [description]
36+
*/
37+
38+
/**
39+
* @typedef {object} AnimationConfig // TODO 19/03/2018 fix type
40+
*
41+
* @property {AnimationFrameConfig[]} [frames] - [description]
42+
* @property {string} [defaultTextureKey=null] - [description]
43+
* @property {integer} [frameRate] - The frame rate of playback in frames per second (default 24 if duration is null)
44+
* @property {integer} [duration] - How long the animation should play for.
45+
* @property {boolean} [skipMissedFrames=true] - Skip frames if the time lags, or always advanced anyway?
46+
* @property {integer} [delay=0] - Delay before starting playback (in seconds)
47+
* @property {integer} [repeat=0] - Number of times to repeat the animation (-1 for infinity)
48+
* @property {integer} [repeatDelay=0] - Delay before the repeat starts (in seconds)
49+
* @property {boolean} [yoyo=false] - Should the animation yoyo? (reverse back down to the start) before repeating?
50+
* @property {boolean} [showOnStart=false] - Should sprite.visible = true when the animation starts to play?
51+
* @property {boolean} [hideOnComplete=false] - Should sprite.visible = false when the animation finishes?
52+
* @property {object} [callbackScope] - [description]
53+
* @property {boolean} [onStart=false] - [description]
54+
* @property {array} [onStartParams] - [description]
55+
* @property {boolean} [onRepeat=false] - [description]
56+
* @property {array} [onRepeatParams] - [description]
57+
* @property {boolean} [onUpdate=false] - [description]
58+
* @property {array} [onUpdateParams] - [description]
59+
* @property {boolean} [onComplete=false] - [description]
60+
* @property {array} [onCompleteParams] - [description]
61+
*/
62+
1163
/**
1264
* @classdesc
1365
* A Frame based Animation.
@@ -25,7 +77,7 @@ var GetValue = require('../utils/object/GetValue');
2577
*
2678
* @param {Phaser.Animations.AnimationManager} manager - [description]
2779
* @param {string} key - [description]
28-
* @param {object} config - [description]
80+
* @param {AnimationConfig} config - [description]
2981
*/
3082
var Animation = new Class({
3183

@@ -65,7 +117,7 @@ var Animation = new Class({
65117
* Extract all the frame data into the frames array
66118
*
67119
* @name Phaser.Animations.Animation#frames
68-
* @type {array}
120+
* @type {Phaser.Animations.AnimationFrame[]}
69121
* @since 3.0.0
70122
*/
71123
this.frames = this.getFrames(
@@ -290,11 +342,6 @@ var Animation = new Class({
290342
this.manager.on('resumeall', this.resume.bind(this));
291343
},
292344

293-
// config = Array of Animation config objects, like:
294-
// [
295-
// { key: 'gems', frame: 'diamond0001', [duration], [visible], [onUpdate] }
296-
// ]
297-
298345
// Add frames to the end of the animation
299346

300347
/**
@@ -303,7 +350,7 @@ var Animation = new Class({
303350
* @method Phaser.Animations.Animation#addFrame
304351
* @since 3.0.0
305352
*
306-
* @param {string|object[]} config - [description]
353+
* @param {string|AnimationFrameConfig[]} config - [description]
307354
*
308355
* @return {Phaser.Animations.Animation} This Animation object.
309356
*/
@@ -312,11 +359,6 @@ var Animation = new Class({
312359
return this.addFrameAt(this.frames.length, config);
313360
},
314361

315-
// config = Array of Animation config objects, like:
316-
// [
317-
// { key: 'gems', frame: 'diamond0001', [duration], [visible], [onUpdate] }
318-
// ]
319-
320362
// Add frame/s into the animation
321363

322364
/**
@@ -326,7 +368,7 @@ var Animation = new Class({
326368
* @since 3.0.0
327369
*
328370
* @param {integer} index - [description]
329-
* @param {string|object[]} config - [description]
371+
* @param {string|AnimationFrameConfig[]} config - [description]
330372
*
331373
* @return {Phaser.Animations.Animation} This Animation object.
332374
*/
@@ -436,20 +478,13 @@ var Animation = new Class({
436478
* @since 3.0.0
437479
*
438480
* @param {Phaser.Textures.TextureManager} textureManager - [description]
439-
* @param {string|object[]} frames - [description]
481+
* @param {string|AnimationFrameConfig[]} frames - [description]
440482
* @param {string} [defaultTextureKey] - [description]
441483
*
442484
* @return {Phaser.Animations.AnimationFrame[]} [description]
443485
*/
444486
getFrames: function (textureManager, frames, defaultTextureKey)
445487
{
446-
// frames: [
447-
// { key: textureKey, frame: textureFrame },
448-
// { key: textureKey, frame: textureFrame, duration: float },
449-
// { key: textureKey, frame: textureFrame, onUpdate: function }
450-
// { key: textureKey, frame: textureFrame, visible: boolean }
451-
// ],
452-
453488
var out = [];
454489
var prev;
455490
var animationFrame;
@@ -779,7 +814,7 @@ var Animation = new Class({
779814
* @method Phaser.Animations.Animation#toJSON
780815
* @since 3.0.0
781816
*
782-
* @return {object} [description]
817+
* @return {JSONAnimation} [description]
783818
*/
784819
toJSON: function ()
785820
{

src/animations/AnimationFrame.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
var Class = require('../utils/Class');
88

9+
/**
10+
* @typedef {object} JSONAnimationFrame
11+
*
12+
* @property {string} key - The key of the Texture this AnimationFrame uses.
13+
* @property {string|integer} frame - The key of the Frame within the Texture that this AnimationFrame uses.
14+
* @property {number} duration - Additional time (in ms) that this frame should appear for during playback.
15+
*/
16+
917
/**
1018
* @classdesc
1119
* A single frame in an Animation sequence.
@@ -151,8 +159,8 @@ var AnimationFrame = new Class({
151159
*
152160
* @method Phaser.Animations.AnimationFrame#toJSON
153161
* @since 3.0.0
154-
*
155-
* @return {object} The AnimationFrame data.
162+
*
163+
* @return {JSONAnimationFrame} The AnimationFrame data.
156164
*/
157165
toJSON: function ()
158166
{

src/animations/AnimationManager.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,29 @@ var EventEmitter = require('eventemitter3');
1111
var GetValue = require('../utils/object/GetValue');
1212
var Pad = require('../utils/string/Pad');
1313

14+
/**
15+
* @typedef {object} JSONAnimationManager
16+
*
17+
* @property {JSONAnimation[]} anims - [description]
18+
* @property {number} globalTimeScale - [description]
19+
*/
20+
1421
/**
1522
* @classdesc
1623
* The Animation Manager.
17-
*
24+
*
1825
* Animations are managed by the global Animation Manager. This is a singleton class that is
1926
* responsible for creating and delivering animations and their corresponding data to all Game Objects.
2027
* Unlike plugins it is owned by the Game instance, not the Scene.
21-
*
28+
*
2229
* Sprites and other Game Objects get the data they need from the AnimationManager.
2330
*
2431
* @class AnimationManager
2532
* @extends EventEmitter
2633
* @memberOf Phaser.Animations
2734
* @constructor
2835
* @since 3.0.0
29-
*
36+
*
3037
* @param {Phaser.Game} game - [description]
3138
*/
3239
var AnimationManager = new Class({
@@ -120,10 +127,10 @@ var AnimationManager = new Class({
120127
* @method Phaser.Animations.AnimationManager#add
121128
* @fires AddAnimationEvent
122129
* @since 3.0.0
123-
*
130+
*
124131
* @param {string} key - [description]
125132
* @param {Phaser.Animations.Animation} animation - [description]
126-
*
133+
*
127134
* @return {Phaser.Animations.AnimationManager} This Animation Manager.
128135
*/
129136
add: function (key, animation)
@@ -149,9 +156,9 @@ var AnimationManager = new Class({
149156
* @method Phaser.Animations.AnimationManager#create
150157
* @fires AddAnimationEvent
151158
* @since 3.0.0
152-
*
153-
* @param {object} config - [description]
154-
*
159+
*
160+
* @param {AnimationConfig} config - [description]
161+
*
155162
* @return {Phaser.Animations.Animation} The Animation that was created.
156163
*/
157164
create: function (config)
@@ -178,10 +185,10 @@ var AnimationManager = new Class({
178185
*
179186
* @method Phaser.Animations.AnimationManager#fromJSON
180187
* @since 3.0.0
181-
*
188+
*
182189
* @param {string|object} data - [description]
183190
* @param {boolean} [clearCurrentAnimations=false] - [description]
184-
*
191+
*
185192
* @return {Phaser.Animations.Animation[]} An array containing all of the Animation objects that were created as a result of this call.
186193
*/
187194
fromJSON: function (data, clearCurrentAnimations)
@@ -227,7 +234,7 @@ var AnimationManager = new Class({
227234
*
228235
* @method Phaser.Animations.AnimationManager#generateFrameNames
229236
* @since 3.0.0
230-
*
237+
*
231238
* @param {string} key - [description]
232239
* @param {object} config - [description]
233240
* @param {string} [config.prefix=''] - [description]
@@ -237,8 +244,8 @@ var AnimationManager = new Class({
237244
* @param {integer} [config.zeroPad=0] - [description]
238245
* @param {array} [config.outputArray=[]] - [description]
239246
* @param {boolean} [config.frames=false] - [description]
240-
*
241-
* @return {object[]} [description]
247+
*
248+
* @return {AnimationFrameConfig[]} [description]
242249
*/
243250
generateFrameNames: function (key, config)
244251
{
@@ -299,16 +306,16 @@ var AnimationManager = new Class({
299306
*
300307
* @method Phaser.Animations.AnimationManager#generateFrameNumbers
301308
* @since 3.0.0
302-
*
309+
*
303310
* @param {string} key - [description]
304311
* @param {object} config - [description]
305312
* @param {integer} [config.start=0] - [description]
306313
* @param {integer} [config.end=-1] - [description]
307314
* @param {boolean} [config.first=false] - [description]
308315
* @param {array} [config.outputArray=[]] - [description]
309316
* @param {boolean} [config.frames=false] - [description]
310-
*
311-
* @return {object[]} [description]
317+
*
318+
* @return {AnimationFrameConfig[]} [description]
312319
*/
313320
generateFrameNumbers: function (key, config)
314321
{
@@ -369,9 +376,9 @@ var AnimationManager = new Class({
369376
*
370377
* @method Phaser.Animations.AnimationManager#get
371378
* @since 3.0.0
372-
*
379+
*
373380
* @param {string} key - [description]
374-
*
381+
*
375382
* @return {Phaser.Animations.Animation} [description]
376383
*/
377384
get: function (key)
@@ -384,11 +391,11 @@ var AnimationManager = new Class({
384391
*
385392
* @method Phaser.Animations.AnimationManager#load
386393
* @since 3.0.0
387-
*
394+
*
388395
* @param {Phaser.GameObjects.GameObject} child - [description]
389396
* @param {string} key - [description]
390397
* @param {string|integer} [startFrame] - [description]
391-
*
398+
*
392399
* @return {Phaser.GameObjects.GameObject} [description]
393400
*/
394401
load: function (child, key, startFrame)
@@ -409,7 +416,7 @@ var AnimationManager = new Class({
409416
* @method Phaser.Animations.AnimationManager#pauseAll
410417
* @fires PauseAllAnimationEvent
411418
* @since 3.0.0
412-
*
419+
*
413420
* @return {Phaser.Animations.AnimationManager} This Animation Manager.
414421
*/
415422
pauseAll: function ()
@@ -429,10 +436,10 @@ var AnimationManager = new Class({
429436
*
430437
* @method Phaser.Animations.AnimationManager#play
431438
* @since 3.0.0
432-
*
439+
*
433440
* @param {string} key - [description]
434441
* @param {Phaser.GameObjects.GameObject} child - [description]
435-
*
442+
*
436443
* @return {Phaser.Animations.AnimationManager} This Animation Manager.
437444
*/
438445
play: function (key, child)
@@ -463,9 +470,9 @@ var AnimationManager = new Class({
463470
* @method Phaser.Animations.AnimationManager#remove
464471
* @fires RemoveAnimationEvent
465472
* @since 3.0.0
466-
*
473+
*
467474
* @param {string} key - [description]
468-
*
475+
*
469476
* @return {Phaser.Animations.Animation} [description]
470477
*/
471478
remove: function (key)
@@ -488,7 +495,7 @@ var AnimationManager = new Class({
488495
* @method Phaser.Animations.AnimationManager#resumeAll
489496
* @fires ResumeAllAnimationEvent
490497
* @since 3.0.0
491-
*
498+
*
492499
* @return {Phaser.Animations.AnimationManager} This Animation Manager.
493500
*/
494501
resumeAll: function ()
@@ -508,11 +515,11 @@ var AnimationManager = new Class({
508515
*
509516
* @method Phaser.Animations.AnimationManager#staggerPlay
510517
* @since 3.0.0
511-
*
518+
*
512519
* @param {string} key - [description]
513520
* @param {Phaser.GameObjects.GameObject} child - [description]
514521
* @param {number} [stagger=0] - [description]
515-
*
522+
*
516523
* @return {Phaser.Animations.AnimationManager} This Animation Manager.
517524
*/
518525
staggerPlay: function (key, child, stagger)
@@ -544,10 +551,10 @@ var AnimationManager = new Class({
544551
*
545552
* @method Phaser.Animations.AnimationManager#toJSON
546553
* @since 3.0.0
547-
*
554+
*
548555
* @param {string} key - [description]
549-
*
550-
* @return {object} [description]
556+
*
557+
* @return {JSONAnimationManager} [description]
551558
*/
552559
toJSON: function (key)
553560
{

0 commit comments

Comments
 (0)