mirror of
https://github.com/photonstorm/phaser
synced 2025-01-13 13:48:53 +00:00
7acd9b0381
V2 used arrays, but other places in the codebase (and users) will expect an object with XY props over an array.
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
|
|
var Pick = require('./Pick');
|
|
var ParseGID = require('./ParseGID');
|
|
|
|
var copyPoints = function (p) { return { x: p.x, y: p.y }; };
|
|
var commonObjectProps = [ 'id', 'name', 'type', 'rotation', 'properties', 'visible', 'x', 'y', 'width', 'height' ];
|
|
|
|
var ParseObject = function (tiledObject, offsetX, offsetY)
|
|
{
|
|
if (offsetX === undefined) { offsetX = 0; }
|
|
if (offsetY === undefined) { offsetY = 0; }
|
|
|
|
var parsedObject = Pick(tiledObject, commonObjectProps);
|
|
|
|
parsedObject.x += offsetX;
|
|
parsedObject.y += offsetY;
|
|
|
|
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)
|
|
{
|
|
parsedObject.polyline = tiledObject.polyline.map(copyPoints);
|
|
}
|
|
else if (tiledObject.polygon)
|
|
{
|
|
parsedObject.polygon = tiledObject.polygon.map(copyPoints);
|
|
}
|
|
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;
|