mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 22:52:14 +00:00
Tidied up Class, fixed a few bounds checks and exposed the utils.
This commit is contained in:
parent
717a232526
commit
57a90997e7
9 changed files with 14 additions and 185 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '55224080-fa4e-11e6-841c-31e712585627'
|
||||
build: '9fe3a260-fd52-11e6-a8e7-7b6917f97568'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -1,55 +0,0 @@
|
|||
|
||||
// Bounds Component
|
||||
|
||||
var Bounds = {
|
||||
|
||||
fizzpop: {
|
||||
atari: true,
|
||||
model: 520
|
||||
},
|
||||
|
||||
bounds: {
|
||||
|
||||
/**
|
||||
* The amount the Game Object is visually offset from its x coordinate.
|
||||
* This is the same as `width * anchor.x`.
|
||||
* It will only be > 0 if anchor.x is not equal to zero.
|
||||
*
|
||||
* @property {number} offsetX
|
||||
* @readOnly
|
||||
*/
|
||||
offsetX: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
console.log('ox get');
|
||||
console.log(this);
|
||||
// return 123;
|
||||
return this.anchorX * this.width;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The amount the Game Object is visually offset from its y coordinate.
|
||||
* This is the same as `height * anchor.y`.
|
||||
* It will only be > 0 if anchor.y is not equal to zero.
|
||||
*
|
||||
* @property {number} offsetY
|
||||
* @readOnly
|
||||
*/
|
||||
offsetY: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
// return 456;
|
||||
return this.anchorY * this.height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Bounds;
|
|
@ -2,7 +2,6 @@ module.exports = {
|
|||
|
||||
Alpha: require('./Alpha'),
|
||||
BlendMode: require('./BlendMode'),
|
||||
Bounds: require('./Bounds'),
|
||||
Children: require('./Children'),
|
||||
Color: require('./Color'),
|
||||
Data: require('./Data'),
|
||||
|
|
|
@ -9,7 +9,6 @@ var Image = new Class({
|
|||
Mixins: [
|
||||
Components.Alpha,
|
||||
Components.BlendMode,
|
||||
Components.Bounds,
|
||||
Components.GetBounds,
|
||||
Components.ScaleMode,
|
||||
Components.Size,
|
||||
|
|
|
@ -67,7 +67,7 @@ BaseLoader.prototype = {
|
|||
|
||||
start: function ()
|
||||
{
|
||||
console.log(this.state.settings.key, ' - BaseLoader start. Files to load:', this.list.size);
|
||||
console.log(this.state.settings.key, '- BaseLoader start. Files to load:', this.list.size);
|
||||
|
||||
if (!this.isReady())
|
||||
{
|
||||
|
@ -247,7 +247,7 @@ BaseLoader.prototype = {
|
|||
|
||||
processComplete: function ()
|
||||
{
|
||||
console.log(this.state.settings.key, ' - Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
|
||||
console.log(this.state.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size);
|
||||
|
||||
this.list.clear();
|
||||
this.inflight.clear();
|
||||
|
|
|
@ -40,7 +40,9 @@ var Phaser = {
|
|||
|
||||
Utils: {
|
||||
|
||||
Align: require('./utils/align/'),
|
||||
Array: require('./utils/array/'),
|
||||
Bounds: require('./utils/bounds/'),
|
||||
Objects: require('./utils/object/'),
|
||||
String: require('./utils/string/')
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ function getProperty (definition, k, isClassDescriptor)
|
|||
def = def.value;
|
||||
}
|
||||
|
||||
// This might be a regular property, or it may be a getter / setter the user defined in a class.
|
||||
// This might be a regular property, or it may be a getter/setter the user defined in a class.
|
||||
if (def && hasGetterOrSetter(def))
|
||||
{
|
||||
if (typeof def.enumerable === 'undefined')
|
||||
|
@ -34,14 +34,7 @@ function getProperty (definition, k, isClassDescriptor)
|
|||
}
|
||||
else
|
||||
{
|
||||
// if (typeof definition[k] === 'object')
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
return false;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +60,7 @@ function hasNonConfigurable (obj, k)
|
|||
return false;
|
||||
}
|
||||
|
||||
function extend (ctor, definition, isClassDescriptor, extendCallback)
|
||||
function extend (ctor, definition, isClassDescriptor, extend)
|
||||
{
|
||||
for (var k in definition)
|
||||
{
|
||||
|
@ -76,78 +69,13 @@ function extend (ctor, definition, isClassDescriptor, extendCallback)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (typeof definition[k] === 'object')
|
||||
{
|
||||
// Here goes nothing ...
|
||||
extend(ctor, def, false, extendCallback);
|
||||
}
|
||||
|
||||
var def = getProperty(definition, k, isClassDescriptor);
|
||||
|
||||
// Object ...
|
||||
|
||||
if (def === -1)
|
||||
{
|
||||
console.log(k, def);
|
||||
|
||||
// Iterate the object, and see if any children are getters / setters
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
|
||||
|
||||
def = definition[k];
|
||||
|
||||
var entry = {};
|
||||
|
||||
entry[k] = {};
|
||||
|
||||
// ctor.prototype[k] = {};
|
||||
// Object.defineProperty(ctor.prototype, k, { value: {} });
|
||||
|
||||
console.log('iterating', def);
|
||||
|
||||
for (var key in def)
|
||||
{
|
||||
var child = def[key];
|
||||
|
||||
console.log('->', key, child);
|
||||
|
||||
if (child && hasGetterOrSetter(child))
|
||||
{
|
||||
if (typeof child.enumerable === 'undefined')
|
||||
{
|
||||
child.enumerable = true;
|
||||
}
|
||||
|
||||
if (typeof child.configurable === 'undefined')
|
||||
{
|
||||
child.configurable = true;
|
||||
}
|
||||
|
||||
Object.defineProperty(entry[k], key, child);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.defineProperty(entry[k], key, {
|
||||
value: child,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
// ctor.prototype[k][key] = { value: child };
|
||||
}
|
||||
}
|
||||
|
||||
// ctor.prototype[k] = def;
|
||||
|
||||
console.dir(entry);
|
||||
|
||||
Object.defineProperties(ctor.prototype, entry);
|
||||
}
|
||||
else if (def !== false)
|
||||
if (def !== false)
|
||||
{
|
||||
// If Extends is used, we will check its prototype to see if the final variable exists.
|
||||
|
||||
var parent = extendCallback || ctor;
|
||||
var parent = extend || ctor;
|
||||
|
||||
if (hasNonConfigurable(parent.prototype, k))
|
||||
{
|
||||
|
@ -176,8 +104,6 @@ function extend (ctor, definition, isClassDescriptor, extendCallback)
|
|||
|
||||
function mixin (myClass, mixins)
|
||||
{
|
||||
console.log(myClass);
|
||||
|
||||
if (!mixins)
|
||||
{
|
||||
return;
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
// Source object
|
||||
// The key as a string, or an array of keys, i.e. 'banner', or 'banner.hideBanner'
|
||||
// The default value to use if the key doesn't exist
|
||||
|
||||
var GetObjectValue = function (source, key, defaultValue)
|
||||
{
|
||||
if (key.indexOf('.'))
|
||||
{
|
||||
var keys = key.split('.');
|
||||
var parent = source;
|
||||
var value = defaultValue;
|
||||
|
||||
// Use for loop here so we can break early
|
||||
for (var i = 0; i < keys.length; i++)
|
||||
{
|
||||
if (parent.hasOwnProperty(keys[i]))
|
||||
{
|
||||
// Yes it has a key property, let's carry on down
|
||||
value = parent[keys[i]];
|
||||
|
||||
parent = parent[keys[i]];
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (source.hasOwnProperty(key)) ? source[key] : defaultValue;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = GetObjectValue;
|
|
@ -1,5 +1,5 @@
|
|||
var CenterX = require('./CenterX');
|
||||
var CenterY = require('./CenterY');
|
||||
var SetCenterX = require('./SetCenterX');
|
||||
var SetCenterY = require('./SetCenterY');
|
||||
|
||||
/**
|
||||
* The center x coordinate of the Game Object.
|
||||
|
@ -8,16 +8,11 @@ var CenterY = require('./CenterY');
|
|||
* @property {number} centerX
|
||||
*/
|
||||
|
||||
// Phaser.Utils.Bounds.GetCenterX(bob)
|
||||
// Phaser.Utils.Bounds.CenterOn(bob, x, y)
|
||||
// Phaser.Utils.Bounds.CenterX(bob, x)
|
||||
// Phaser.Utils.Bounds.CenterY(bob, x)
|
||||
|
||||
var CenterOn = function (gameObject, x, y)
|
||||
{
|
||||
CenterX(gameObject, x);
|
||||
SetCenterX(gameObject, x);
|
||||
|
||||
return CenterY(gameObject, y);
|
||||
return SetCenterY(gameObject, y);
|
||||
};
|
||||
|
||||
module.exports = CenterOn;
|
||||
|
|
Loading…
Reference in a new issue