2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-03-19 18:35:08 +00:00
|
|
|
/**
|
2018-06-06 13:23:39 +00:00
|
|
|
* Build a JSON representation of the given Game Object.
|
2018-06-01 13:08:35 +00:00
|
|
|
*
|
|
|
|
* This is typically extended further by Game Object specific implementations.
|
2018-03-19 18:35:08 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Components.ToJSON
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-06 13:23:39 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to export as JSON.
|
2018-03-19 18:35:08 +00:00
|
|
|
*
|
2019-02-13 12:35:12 +00:00
|
|
|
* @return {Phaser.GameObjects.Types.JSONGameObject} A JSON representation of the Game Object.
|
2018-03-19 18:35:08 +00:00
|
|
|
*/
|
2017-04-12 23:05:21 +00:00
|
|
|
var ToJSON = function (gameObject)
|
|
|
|
{
|
|
|
|
var out = {
|
|
|
|
name: gameObject.name,
|
|
|
|
type: gameObject.type,
|
2017-04-12 23:35:27 +00:00
|
|
|
x: gameObject.x,
|
|
|
|
y: gameObject.y,
|
2017-09-14 02:12:00 +00:00
|
|
|
depth: gameObject.depth,
|
2017-04-12 23:05:21 +00:00
|
|
|
scale: {
|
|
|
|
x: gameObject.scaleX,
|
|
|
|
y: gameObject.scaleY
|
|
|
|
},
|
|
|
|
origin: {
|
|
|
|
x: gameObject.originX,
|
|
|
|
y: gameObject.originY
|
|
|
|
},
|
2017-04-12 23:35:27 +00:00
|
|
|
flipX: gameObject.flipX,
|
|
|
|
flipY: gameObject.flipY,
|
2017-04-12 23:05:21 +00:00
|
|
|
rotation: gameObject.rotation,
|
|
|
|
alpha: gameObject.alpha,
|
|
|
|
visible: gameObject.visible,
|
|
|
|
scaleMode: gameObject.scaleMode,
|
|
|
|
blendMode: gameObject.blendMode,
|
|
|
|
textureKey: '',
|
2017-04-12 23:35:27 +00:00
|
|
|
frameKey: '',
|
|
|
|
data: {}
|
2017-04-12 23:05:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (gameObject.texture)
|
|
|
|
{
|
|
|
|
out.textureKey = gameObject.texture.key;
|
2017-04-12 23:35:27 +00:00
|
|
|
out.frameKey = gameObject.frame.name;
|
2017-04-12 23:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ToJSON;
|