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');
|
2017-12-01 19:24:37 +00:00
|
|
|
var ParseObject = require('./ParseObject');
|
2018-01-27 14:27:56 +00:00
|
|
|
var ObjectLayer = require('../../mapdata/ObjectLayer');
|
2017-12-01 19:24:37 +00:00
|
|
|
|
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
|
|
|
*/
|
2017-12-02 00:08:58 +00:00
|
|
|
var ParseObjectLayers = function (json)
|
2017-12-01 19:24:37 +00:00
|
|
|
{
|
2018-01-27 14:27:56 +00:00
|
|
|
var objectLayers = [];
|
2017-12-01 19:24:37 +00:00
|
|
|
|
|
|
|
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);
|
2018-01-27 14:27:56 +00:00
|
|
|
var objects = [];
|
2017-12-01 19:24:37 +00:00
|
|
|
|
|
|
|
for (var j = 0; j < curo.objects.length; j++)
|
|
|
|
{
|
|
|
|
var parsedObject = ParseObject(curo.objects[j], offsetX, offsetY);
|
|
|
|
|
2018-01-27 14:27:56 +00:00
|
|
|
objects.push(parsedObject);
|
2017-12-01 19:24:37 +00:00
|
|
|
}
|
2018-01-27 14:27:56 +00:00
|
|
|
|
|
|
|
var objectLayer = new ObjectLayer(curo);
|
|
|
|
objectLayer.objects = objects;
|
|
|
|
|
|
|
|
objectLayers.push(objectLayer);
|
2017-12-01 19:24:37 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 14:27:56 +00:00
|
|
|
return objectLayers;
|
2017-12-01 19:24:37 +00:00
|
|
|
};
|
|
|
|
|
2017-12-02 00:08:58 +00:00
|
|
|
module.exports = ParseObjectLayers;
|