Added jsdocs

This commit is contained in:
Richard Davey 2018-02-12 21:54:51 +00:00
parent ae3cd50356
commit ef87b33a10
5 changed files with 230 additions and 60 deletions

View file

@ -9,6 +9,18 @@ var List = require('../structs/List');
var PluginManager = require('../plugins/PluginManager');
var StableSort = require('../utils/array/StableSort');
/**
* @classdesc
* [description]
*
* @class DisplayList
* @extends Phaser.Structs.List
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var DisplayList = new Class({
Extends: List,
@ -19,10 +31,32 @@ var DisplayList = new Class({
{
List.call(this, scene);
/**
* [description]
*
* @name Phaser.GameObjects.DisplayList#sortChildrenFlag
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.sortChildrenFlag = false;
/**
* [description]
*
* @name Phaser.GameObjects.DisplayList#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* [description]
*
* @name Phaser.GameObjects.DisplayList#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
@ -31,6 +65,12 @@ var DisplayList = new Class({
}
},
/**
* [description]
*
* @method Phaser.GameObjects.DisplayList#boot
* @since 3.0.0
*/
boot: function ()
{
var eventEmitter = this.systems.events;
@ -39,13 +79,23 @@ var DisplayList = new Class({
eventEmitter.on('destroy', this.destroy, this);
},
// Force a sort of the display list on the next call to process
/**
* Force a sort of the display list on the next call to depthSort.
*
* @method Phaser.GameObjects.DisplayList#queueDepthSort
* @since 3.0.0
*/
queueDepthSort: function ()
{
this.sortChildrenFlag = true;
},
// Immediately sorts the display list if the flag is set
/**
* Immediately sorts the display list if the flag is set.
*
* @method Phaser.GameObjects.DisplayList#depthSort
* @since 3.0.0
*/
depthSort: function ()
{
if (this.sortChildrenFlag)
@ -56,13 +106,33 @@ var DisplayList = new Class({
}
},
/**
* [description]
*
* @method Phaser.GameObjects.DisplayList#sortByDepth
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject} childA - [description]
* @param {Phaser.GameObjects.GameObject} childB - [description]
*
* @return {integer} [description]
*/
sortByDepth: function (childA, childB)
{
return childA._depth - childB._depth;
},
// Given an array of Game Objects, sort the array and return it,
// so that the objects are in index order with the lowest at the bottom.
/**
* Given an array of Game Objects, sort the array and return it,
* so that the objects are in index order with the lowest at the bottom.
*
* @method Phaser.GameObjects.DisplayList#sortGameObjects
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject[]} gameObjects - [description]
*
* @return {array} [description]
*/
sortGameObjects: function (gameObjects)
{
if (gameObjects === undefined) { gameObjects = this.list; }
@ -72,7 +142,16 @@ var DisplayList = new Class({
return gameObjects.sort(this.sortIndexHandler.bind(this));
},
// Note that the given array is sorted in place, even though it isn't returned directly it will still be updated.
/**
* Note that the given array is sorted in place, even though it isn't returned directly it will still be updated.
*
* @method Phaser.GameObjects.DisplayList#getTopGameObject
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject[]} gameObjects - [description]
*
* @return {Phaser.GameObjects.GameObject} The top-most Game Object on the Display List.
*/
getTopGameObject: function (gameObjects)
{
this.sortGameObjects(gameObjects);

View file

@ -5,18 +5,108 @@
*/
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
/**
* @classdesc
* [description]
*
* @class UpdateList
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var UpdateList = new Class({
initialize:
function UpdateList ()
function UpdateList (scene)
{
/**
* [description]
*
* @name Phaser.GameObjects.UpdateList#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* [description]
*
* @name Phaser.GameObjects.UpdateList#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
/**
* [description]
*
* @name Phaser.GameObjects.UpdateList#_list
* @type {array}
* @private
* @default []
* @since 3.0.0
*/
this._list = [];
/**
* [description]
*
* @name Phaser.GameObjects.UpdateList#_pendingInsertion
* @type {array}
* @private
* @default []
* @since 3.0.0
*/
this._pendingInsertion = [];
/**
* [description]
*
* @name Phaser.GameObjects.UpdateList#_pendingRemoval
* @type {array}
* @private
* @default []
* @since 3.0.0
*/
this._pendingRemoval = [];
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#boot
* @since 3.0.0
*/
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('update', this.update, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#add
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject} child - [description]
*
* @return {Phaser.GameObjects.GameObject} [description]
*/
add: function (child)
{
// Is child already in this list?
@ -29,6 +119,15 @@ var UpdateList = new Class({
return child;
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#preUpdate
* @since 3.0.0
*
* @param {number} time - [description]
* @param {number} delta - [description]
*/
preUpdate: function (time, delta)
{
var toRemove = this._pendingRemoval.length;
@ -67,6 +166,15 @@ var UpdateList = new Class({
this._pendingInsertion.length = 0;
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#update
* @since 3.0.0
*
* @param {number} time - [description]
* @param {number} delta - [description]
*/
update: function (time, delta)
{
for (var i = 0; i < this._list.length; i++)
@ -80,6 +188,16 @@ var UpdateList = new Class({
}
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#remove
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject} child - [description]
*
* @return {Phaser.GameObjects.GameObject} [description]
*/
remove: function (child)
{
var index = this._list.indexOf(child);
@ -92,6 +210,14 @@ var UpdateList = new Class({
return child;
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#removeAll
* @since 3.0.0
*
* @return {Phaser.GameObjects.UpdateList} The UpdateList object.
*/
removeAll: function ()
{
var i = this._list.length;
@ -104,6 +230,12 @@ var UpdateList = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
this.removeAll();
@ -113,11 +245,23 @@ var UpdateList = new Class({
this._pendingInsertion.length = 0;
},
/**
* [description]
*
* @method Phaser.GameObjects.UpdateList#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.shutdown();
this.scene = undefined;
this.systems = undefined;
}
});
PluginManager.register('UpdateList', UpdateList, 'updateList');
module.exports = UpdateList;

View file

@ -1,52 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var UpdateList = require('./UpdateList');
var UpdateListPlugin = new Class({
Extends: UpdateList,
initialize:
function UpdateListPlugin (scene)
{
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
UpdateList.call(this);
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('update', this.update, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
destroy: function ()
{
this.shutdown();
this.scene = undefined;
}
});
PluginManager.register('UpdateListPlugin', UpdateListPlugin, 'updateList');
module.exports = UpdateListPlugin;

View file

@ -16,7 +16,6 @@ var GameObjects = {
LightsManager: require('./LightsManager'),
LightsPlugin: require('./LightsPlugin'),
UpdateList: require('./UpdateList'),
UpdateListPlugin: require('./UpdateListPlugin'),
Components: require('./components'),

View file

@ -18,7 +18,7 @@ var CoreScenePlugins = [
'GameObjectFactory',
'ScenePlugin',
'DisplayList',
'UpdateListPlugin'
'UpdateList'
];