Added jsdocs.

This commit is contained in:
Richard Davey 2018-02-09 15:23:33 +00:00
parent a71998d682
commit 5db058021f
9 changed files with 487 additions and 44 deletions

View file

@ -1,5 +1,3 @@
// Phaser.Physics.Impact.Body
var Class = require('../../utils/Class');
var COLLIDES = require('./COLLIDES');
var GetVelocity = require('./GetVelocity');
@ -7,10 +5,21 @@ var TYPE = require('./TYPE');
var UpdateMotion = require('./UpdateMotion');
/**
* @classdesc
* An Impact.js compatible physics body.
* This re-creates the properties you'd get on an Entity and the math needed to update them.
*
* @class Body
* @memberOf Phaser.Physics.Impact
* @constructor
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} [sx=16] - [description]
* @param {number} [sy=16] - [description]
*/
var Body = new Class({
initialize:
@ -20,51 +29,284 @@ var Body = new Class({
if (sx === undefined) { sx = 16; }
if (sy === undefined) { sy = sx; }
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#world
* @type {Phaser.Physics.Impact.World}
* @since 3.0.0
*/
this.world = world;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#gameObject
* @type {Phaser.GameObjects.GameObject}
* @default null
* @since 3.0.0
*/
this.gameObject = null;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#enabled
* @type {boolean}
* @default true
* @since 3.0.0
*/
this.enabled = true;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#parent
* @type {null}
* @since 3.0.0
*/
this.parent;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#id
* @type {integer}
* @since 3.0.0
*/
this.id = world.getNextID();
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#name
* @type {string}
* @default ''
* @since 3.0.0
*/
this.name = '';
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#size
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.size = { x: sx, y: sy };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#offset
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.offset = { x: 0, y: 0 };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#pos
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.pos = { x: x, y: y };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#last
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.last = { x: x, y: y };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#vel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.vel = { x: 0, y: 0 };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#accel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.accel = { x: 0, y: 0 };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#friction
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.friction = { x: 0, y: 0 };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#maxVel
* @type {{x: number, y: number}}
* @since 3.0.0
*/
this.maxVel = { x: world.defaults.maxVelocityX, y: world.defaults.maxVelocityY };
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#standing
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.standing = false;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#gravityFactor
* @type {number}
* @since 3.0.0
*/
this.gravityFactor = world.defaults.gravityFactor;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#bounciness
* @type {number}
* @since 3.0.0
*/
this.bounciness = world.defaults.bounciness;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#minBounceVelocity
* @type {number}
* @since 3.0.0
*/
this.minBounceVelocity = world.defaults.minBounceVelocity;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#accelGround
* @type {number}
* @default 0
* @since 3.0.0
*/
this.accelGround = 0;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#accelAir
* @type {number}
* @default 0
* @since 3.0.0
*/
this.accelAir = 0;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#jumpSpeed
* @type {number}
* @default 0
* @since 3.0.0
*/
this.jumpSpeed = 0;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#type
* @type {Phaser.Physics.Impact.TYPE}
* @since 3.0.0
*/
this.type = TYPE.NONE;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#checkAgainst
* @type {Phaser.Physics.Impact.TYPE}
* @since 3.0.0
*/
this.checkAgainst = TYPE.NONE;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#collides
* @type {Phaser.Physics.Impact.COLLIDES}
* @since 3.0.0
*/
this.collides = COLLIDES.NEVER;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#debugShowBody
* @type {boolean}
* @since 3.0.0
*/
this.debugShowBody = world.defaults.debugShowBody;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#debugShowVelocity
* @type {boolean}
* @since 3.0.0
*/
this.debugShowVelocity = world.defaults.debugShowVelocity;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#debugBodyColor
* @type {integer}
* @since 3.0.0
*/
this.debugBodyColor = world.defaults.bodyDebugColor;
/**
* [description]
*
* @name Phaser.Physics.Impact.Body#updateCallback
* @type {function}
* @since 3.0.0
*/
this.updateCallback;
// min 44 deg, max 136 deg
/**
* min 44 deg, max 136 deg
*
* @name Phaser.Physics.Impact.Body#slopeStanding
* @type {{ min: number, max: number }}
* @since 3.0.0
*/
this.slopeStanding = { min: 0.767944870877505, max: 2.3736477827122884 };
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#reset
* @since 3.0.0
*
* @param {number} x - [description]
* @param {number} y - [description]
*/
reset: function (x, y)
{
this.pos = { x: x, y: y };
@ -89,6 +331,14 @@ var Body = new Class({
this.collides = COLLIDES.NEVER;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#update
* @since 3.0.0
*
* @param {number} delta - [description]
*/
update: function (delta)
{
var pos = this.pos;
@ -125,6 +375,14 @@ var Body = new Class({
}
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#drawDebug
* @since 3.0.0
*
* @param {Phaser.GameObjects.Graphics} graphic - [description]
*/
drawDebug: function (graphic)
{
var pos = this.pos;
@ -145,16 +403,42 @@ var Body = new Class({
}
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#willDrawDebug
* @since 3.0.0
*
* @return {boolean} [description]
*/
willDrawDebug: function ()
{
return (this.debugShowBody || this.debugShowVelocity);
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#skipHash
* @since 3.0.0
*
* @return {boolean} [description]
*/
skipHash: function ()
{
return (!this.enabled || (this.type === 0 && this.checkAgainst === 0 && this.collides === 0));
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#touches
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.Body} other - [description]
*
* @return {boolean} [description]
*/
touches: function (other)
{
return !(
@ -165,6 +449,19 @@ var Body = new Class({
);
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#resetSize
* @since 3.0.0
*
* @param {number} x - [description]
* @param {number} y - [description]
* @param {number} width - [description]
* @param {number} height - [description]
*
* @return {Phaser.Physics.Impact.Body} This Body object.
*/
resetSize: function (x, y, width, height)
{
this.pos.x = x;
@ -175,6 +472,14 @@ var Body = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#toJSON
* @since 3.0.0
*
* @return {object} [description]
*/
toJSON: function ()
{
var output = {
@ -196,17 +501,40 @@ var Body = new Class({
return output;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#fromJSON
* @todo
* @since 3.0.0
*
* @param {object} config - [description]
*/
fromJSON: function (config)
{
// TODO
},
// Can be overridden by user code
/**
* Can be overridden by user code
*
* @method Phaser.Physics.Impact.Body#check
* @since 3.0.0
*
* @param {[type]} other - [description]
*/
check: function (other)
{
},
// Can be overridden by user code
/**
* Can be overridden by user code
*
* @method Phaser.Physics.Impact.Body#collideWith
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.Body} other - [description]
* @param {[type]} axis - [description]
*/
collideWith: function (other, axis)
{
if (this.parent && this.parent._collideCallback)
@ -215,12 +543,27 @@ var Body = new Class({
}
},
// Can be overridden by user code but must return a boolean
/**
* Can be overridden by user code but must return a boolean.
*
* @method Phaser.Physics.Impact.Body#handleMovementTrace
* @since 3.0.0
*
* @param {[type]} res - [description]
*
* @return {boolean} [description]
*/
handleMovementTrace: function (res)
{
return true;
},
/**
* [description]
*
* @method Phaser.Physics.Impact.Body#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.enabled = false;

View file

@ -1,17 +1,60 @@
// Collision Types - Determine if and how entities collide with each other
// In ACTIVE vs. LITE or FIXED vs. ANY collisions, only the "weak" entity moves,
// while the other one stays fixed. In ACTIVE vs. ACTIVE and ACTIVE vs. PASSIVE
// collisions, both entities are moved. LITE or PASSIVE entities don't collide
// with other LITE or PASSIVE entities at all. The behaiviour for FIXED vs.
// FIXED collisions is undefined.
/**
* Collision Types - Determine if and how entities collide with each other.
*
* In ACTIVE vs. LITE or FIXED vs. ANY collisions, only the "weak" entity moves,
* while the other one stays fixed. In ACTIVE vs. ACTIVE and ACTIVE vs. PASSIVE
* collisions, both entities are moved. LITE or PASSIVE entities don't collide
* with other LITE or PASSIVE entities at all. The behavior for FIXED vs.
* FIXED collisions is undefined.
*
* @namespace Phaser.Physics.Impact.COLLIDES
*/
module.exports = {
/**
* Never collides.
*
* @name Phaser.Physics.Impact.COLLIDES.NEVER
* @type {integer}
* @since 3.0.0
*/
NEVER: 0,
/**
* Lite collision.
*
* @name Phaser.Physics.Impact.COLLIDES.LITE
* @type {integer}
* @since 3.0.0
*/
LITE: 1,
/**
* Passive collision.
*
* @name Phaser.Physics.Impact.COLLIDES.PASSIVE
* @type {integer}
* @since 3.0.0
*/
PASSIVE: 2,
/**
* Active collision.
*
* @name Phaser.Physics.Impact.COLLIDES.ACTIVE
* @type {integer}
* @since 3.0.0
*/
ACTIVE: 4,
/**
* Fixed collision.
*
* @name Phaser.Physics.Impact.COLLIDES.FIXED
* @type {integer}
* @since 3.0.0
*/
FIXED: 8
};

View file

@ -1,4 +1,14 @@
/**
* [description]
*
* @function Phaser.Physics.Impact.SeperateX
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @param {Phaser.Physics.Impact.Body} left - [description]
* @param {Phaser.Physics.Impact.Body} right - [description]
* @param {Phaser.Physics.Impact.Body} [weak] - [description]
*/
var SeperateX = function (world, left, right, weak)
{
var nudge = left.pos.x + left.size.x - right.pos.x;

View file

@ -1,4 +1,14 @@
/**
* [description]
*
* @function Phaser.Physics.Impact.SeperateY
* @since 3.0.0
*
* @param {Phaser.Physics.Impact.World} world - [description]
* @param {Phaser.Physics.Impact.Body} top - [description]
* @param {Phaser.Physics.Impact.Body} bottom - [description]
* @param {Phaser.Physics.Impact.Body} [weak] - [description]
*/
var SeperateY = function (world, top, bottom, weak)
{
var nudge = (top.pos.y + top.size.y - bottom.pos.y);

View file

@ -1,16 +1,51 @@
// Collision Types - Determine if and how entities collide with each other
// In ACTIVE vs. LITE or FIXED vs. ANY collisions, only the "weak" entity moves,
// while the other one stays fixed. In ACTIVE vs. ACTIVE and ACTIVE vs. PASSIVE
// collisions, both entities are moved. LITE or PASSIVE entities don't collide
// with other LITE or PASSIVE entities at all. The behavior for FIXED vs.
// FIXED collisions is undefined.
/**
* Collision Types - Determine if and how entities collide with each other.
*
* In ACTIVE vs. LITE or FIXED vs. ANY collisions, only the "weak" entity moves,
* while the other one stays fixed. In ACTIVE vs. ACTIVE and ACTIVE vs. PASSIVE
* collisions, both entities are moved. LITE or PASSIVE entities don't collide
* with other LITE or PASSIVE entities at all. The behavior for FIXED vs.
* FIXED collisions is undefined.
*
* @namespace Phaser.Physics.Impact.TYPES
*/
module.exports = {
/**
* Collides with nothing.
*
* @name Phaser.Physics.Impact.TYPES.NONE
* @type {integer}
* @since 3.0.0
*/
NONE: 0,
/**
* Type A. Collides with Type B.
*
* @name Phaser.Physics.Impact.TYPES.A
* @type {integer}
* @since 3.0.0
*/
A: 1,
/**
* Type B. Collides with Type A.
*
* @name Phaser.Physics.Impact.TYPES.B
* @type {integer}
* @since 3.0.0
*/
B: 2,
/**
* Collides with both types A and B.
*
* @name Phaser.Physics.Impact.TYPES.BOTH
* @type {integer}
* @since 3.0.0
*/
BOTH: 3
};

View file

@ -1,25 +1,27 @@
// Phaser.Physics.Impact
// An Impact.js compatible physics world, body and solver, for those who are used
// to the Impact way of defining and controlling physics bodies. Also works with
// the new Loader support for Weltmeister map data.
//
// World updated to run off the Phaser main loop.
// Body extended to support additional setter functions.
//
// To create the map data you'll need Weltmeister, which comes with Impact
// and can be purchased from http://impactjs.com
//
// My thanks to Dominic Szablewski for his permission to support Impact in Phaser.
/**
* An Impact.js compatible physics world, body and solver, for those who are used
* to the Impact way of defining and controlling physics bodies. Also works with
* the new Loader support for Weltmeister map data.
*
* World updated to run off the Phaser main loop.
* Body extended to support additional setter functions.
*
* To create the map data you'll need Weltmeister, which comes with Impact
* and can be purchased from http://impactjs.com
*
* My thanks to Dominic Szablewski for his permission to support Impact in Phaser.
*
* @namespace Phaser.Physics.Impact
*/
module.exports = {
Body: require('./Body'),
Body: require('./ImpactBody'),
COLLIDES: require('./COLLIDES'),
CollisionMap: require('./CollisionMap'),
Factory: require('./Factory'),
Image: require('./ImpactImage'),
ImpactBody: require('./ImpactBody'),
ImpactPhysics: require('./ImpactPhysics'),
Sprite: require('./ImpactSprite'),
TYPE: require('./TYPE'),

View file

@ -6,7 +6,6 @@ module.exports = {
Arcade: require('./arcade'),
Impact: require('./impact'),
Matter: require('./matter-js'),
PolyDecomp: require('./poly-decomp')
Matter: require('./matter-js')
};

View file

@ -6,6 +6,7 @@ module.exports = {
Image: require('./MatterImage'),
Matter: require('./CustomMain'),
MatterPhysics: require('./MatterPhysics'),
PolyDecomp: require('./poly-decomp'),
Sprite: require('./MatterSprite'),
TileBody: require('./MatterTileBody'),
World: require('./World')