2017-11-10 02:50:25 +00:00
|
|
|
var Formats = require('./Formats');
|
|
|
|
var Parsers = require('./parsers');
|
|
|
|
|
2017-11-14 21:33:13 +00:00
|
|
|
var Parse = function (key, mapFormat, mapData, tileWidth, tileHeight, insertNull)
|
2017-11-10 02:50:25 +00:00
|
|
|
{
|
|
|
|
var newMap;
|
|
|
|
|
2017-11-11 03:38:42 +00:00
|
|
|
switch(mapFormat)
|
2017-11-10 02:50:25 +00:00
|
|
|
{
|
2017-11-11 03:38:42 +00:00
|
|
|
case (Formats.TILEMAP_2D_ARRAY):
|
2017-11-14 21:33:13 +00:00
|
|
|
newMap = Parsers.Parse2DArray(key, mapData, tileWidth, tileHeight, insertNull);
|
2017-11-11 03:38:42 +00:00
|
|
|
break;
|
2017-11-10 02:50:25 +00:00
|
|
|
case (Formats.TILEMAP_CSV):
|
2017-11-14 21:33:13 +00:00
|
|
|
newMap = Parsers.ParseCSV(key, mapData, tileWidth, tileHeight, insertNull);
|
2017-11-10 02:50:25 +00:00
|
|
|
break;
|
|
|
|
case (Formats.TILEMAP_TILED_JSON):
|
2017-11-14 21:02:19 +00:00
|
|
|
newMap = Parsers.ParseTiledJSON(key, mapData, insertNull);
|
2017-11-10 02:50:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-11-11 03:38:42 +00:00
|
|
|
console.warn('Unrecognized tilemap data format: ' + mapFormat);
|
2017-11-10 02:50:25 +00:00
|
|
|
newMap = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Parse;
|
|
|
|
|