phaser/src/tilemaps/parsers/tiled/ParseObjectLayers.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

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}
*/
2018-02-07 17:10:01 +00:00
var GetFastValue = require('../../../utils/object/GetFastValue');
var ParseObject = require('./ParseObject');
var ObjectLayer = require('../../mapdata/ObjectLayer');
2018-02-10 01:50:48 +00:00
/**
2018-10-19 11:32:43 +00:00
* Parses a Tiled JSON object into an array of ObjectLayer objects.
2018-02-10 01:50:48 +00:00
*
* @function Phaser.Tilemaps.Parsers.Tiled.ParseObjectLayers
* @since 3.0.0
*
2018-10-19 11:32:43 +00:00
* @param {object} json - The Tiled JSON object.
2018-02-10 01:50:48 +00:00
*
2018-10-19 11:32:43 +00:00
* @return {array} An array of all object layers in the tilemap as `ObjectLayer`s.
2018-02-10 01:50:48 +00:00
*/
var ParseObjectLayers = function (json)
{
var objectLayers = [];
for (var i = 0; i < json.layers.length; i++)
{
if (json.layers[i].type !== 'objectgroup')
{
continue;
}
var curo = json.layers[i];
var offsetX = GetFastValue(curo, 'offsetx', 0);
var offsetY = GetFastValue(curo, 'offsety', 0);
var objects = [];
for (var j = 0; j < curo.objects.length; j++)
{
var parsedObject = ParseObject(curo.objects[j], offsetX, offsetY);
objects.push(parsedObject);
}
var objectLayer = new ObjectLayer(curo);
objectLayer.objects = objects;
objectLayers.push(objectLayer);
}
return objectLayers;
};
module.exports = ParseObjectLayers;