2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-11-24 14:22:55 +00:00
|
|
|
var Pick = require('./Pick');
|
|
|
|
var ParseGID = require('./ParseGID');
|
|
|
|
|
2018-01-27 14:34:11 +00:00
|
|
|
var copyPoints = function (p) { return { x: p.x, y: p.y }; };
|
2018-02-10 01:50:48 +00:00
|
|
|
|
2017-11-29 04:40:48 +00:00
|
|
|
var commonObjectProps = [ 'id', 'name', 'type', 'rotation', 'properties', 'visible', 'x', 'y', 'width', 'height' ];
|
2017-11-24 14:22:55 +00:00
|
|
|
|
2018-02-10 01:50:48 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @function Phaser.Tilemaps.Parsers.Tiled.ParseObject
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {object} tiledObject - [description]
|
|
|
|
* @param {number} [offsetX=0] - [description]
|
|
|
|
* @param {number} [offsetY=0] - [description]
|
|
|
|
*
|
|
|
|
* @return {object} [description]
|
|
|
|
*/
|
2017-11-24 14:59:36 +00:00
|
|
|
var ParseObject = function (tiledObject, offsetX, offsetY)
|
2017-11-24 14:22:55 +00:00
|
|
|
{
|
2017-11-24 14:59:36 +00:00
|
|
|
if (offsetX === undefined) { offsetX = 0; }
|
|
|
|
if (offsetY === undefined) { offsetY = 0; }
|
|
|
|
|
2017-11-24 14:22:55 +00:00
|
|
|
var parsedObject = Pick(tiledObject, commonObjectProps);
|
|
|
|
|
2017-11-24 14:59:36 +00:00
|
|
|
parsedObject.x += offsetX;
|
|
|
|
parsedObject.y += offsetY;
|
|
|
|
|
2017-11-24 14:22:55 +00:00
|
|
|
if (tiledObject.gid)
|
|
|
|
{
|
|
|
|
// Object tiles
|
|
|
|
var gidInfo = ParseGID(tiledObject.gid);
|
|
|
|
parsedObject.gid = gidInfo.gid;
|
|
|
|
parsedObject.flippedHorizontal = gidInfo.flippedHorizontal;
|
|
|
|
parsedObject.flippedVertical = gidInfo.flippedVertical;
|
|
|
|
parsedObject.flippedAntiDiagonal = gidInfo.flippedAntiDiagonal;
|
|
|
|
}
|
|
|
|
else if (tiledObject.polyline)
|
|
|
|
{
|
2018-01-27 14:34:11 +00:00
|
|
|
parsedObject.polyline = tiledObject.polyline.map(copyPoints);
|
2017-11-24 14:22:55 +00:00
|
|
|
}
|
|
|
|
else if (tiledObject.polygon)
|
|
|
|
{
|
2018-01-27 14:34:11 +00:00
|
|
|
parsedObject.polygon = tiledObject.polygon.map(copyPoints);
|
2017-11-24 14:22:55 +00:00
|
|
|
}
|
|
|
|
else if (tiledObject.ellipse)
|
|
|
|
{
|
|
|
|
parsedObject.ellipse = tiledObject.ellipse;
|
|
|
|
parsedObject.width = tiledObject.width;
|
|
|
|
parsedObject.height = tiledObject.height;
|
|
|
|
}
|
|
|
|
else if (tiledObject.text)
|
|
|
|
{
|
|
|
|
parsedObject.width = tiledObject.width;
|
|
|
|
parsedObject.height = tiledObject.height;
|
|
|
|
parsedObject.text = tiledObject.text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Otherwise, assume it is a rectangle
|
|
|
|
parsedObject.rectangle = true;
|
|
|
|
parsedObject.width = tiledObject.width;
|
|
|
|
parsedObject.height = tiledObject.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ParseObject;
|