Tilemap parsers: remove width & height parameters since they are inferred

This commit is contained in:
Michael Hadley 2017-11-14 15:33:13 -06:00
parent bf19553135
commit 3f08689c44
3 changed files with 13 additions and 9 deletions

View file

@ -1,17 +1,17 @@
var Formats = require('./Formats');
var Parsers = require('./parsers');
var Parse = function (key, mapFormat, mapData, tileWidth, tileHeight, width, height, insertNull)
var Parse = function (key, mapFormat, mapData, tileWidth, tileHeight, insertNull)
{
var newMap;
switch(mapFormat)
{
case (Formats.TILEMAP_2D_ARRAY):
newMap = Parsers.Parse2DArray(key, mapData, tileWidth, tileHeight, width, height, insertNull);
newMap = Parsers.Parse2DArray(key, mapData, tileWidth, tileHeight, insertNull);
break;
case (Formats.TILEMAP_CSV):
newMap = Parsers.ParseCSV(key, mapData, tileWidth, tileHeight, width, height, insertNull);
newMap = Parsers.ParseCSV(key, mapData, tileWidth, tileHeight, insertNull);
break;
case (Formats.TILEMAP_TILED_JSON):
newMap = Parsers.ParseTiledJSON(key, mapData, insertNull);

View file

@ -14,7 +14,8 @@ GameObjectCreator.register('tilemap', function (config)
// tileHeight: 32,
// width: 10,
// height: 10,
// data: null (2D array of tile indices)
// data: null (2D array of tile indices),
// insertNull: false
// }
var key = GetFastValue(config, 'key', null);
@ -22,12 +23,13 @@ GameObjectCreator.register('tilemap', function (config)
var tileHeight = GetFastValue(config, 'tileHeight', 32);
var width = GetFastValue(config, 'width', 10);
var height = GetFastValue(config, 'height', 10);
var insertNull = GetFastValue(config, 'insertNull', false);
var data = GetFastValue(config, 'data', null);
var parsedData = null;
if (key === null && Array.isArray(data))
{
parsedData = Parse(key, Formats.TILEMAP_2D_ARRAY, data, tileWidth, tileHeight, width, height);
parsedData = Parse(key, Formats.TILEMAP_2D_ARRAY, data, tileWidth, tileHeight, insertNull);
}
else if (key !== null)
{
@ -39,7 +41,7 @@ GameObjectCreator.register('tilemap', function (config)
}
else
{
parsedData = Parse(key, tilemapData.format, tilemapData.data, tileWidth, tileHeight, width, height);
parsedData = Parse(key, tilemapData.format, tilemapData.data, tileWidth, tileHeight, insertNull);
}
}

View file

@ -21,7 +21,8 @@ GameObjectFactory.register('tilemap', function (config)
// tileHeight: 32,
// width: 10,
// height: 10,
// data: null (2D array of tile indices)
// data: null (2D array of tile indices),
// insertNull: false
// }
var key = GetFastValue(config, 'key', null);
@ -29,12 +30,13 @@ GameObjectFactory.register('tilemap', function (config)
var tileHeight = GetFastValue(config, 'tileHeight', 32);
var width = GetFastValue(config, 'width', 10);
var height = GetFastValue(config, 'height', 10);
var insertNull = GetFastValue(config, 'insertNull', false);
var data = GetFastValue(config, 'data', null);
var parsedData = null;
if (key === null && Array.isArray(data))
{
parsedData = Parse(key, Formats.TILEMAP_2D_ARRAY, data, tileWidth, tileHeight, width, height);
parsedData = Parse(key, Formats.TILEMAP_2D_ARRAY, data, tileWidth, tileHeight, insertNull);
}
else if (key !== null)
{
@ -46,7 +48,7 @@ GameObjectFactory.register('tilemap', function (config)
}
else
{
parsedData = Parse(key, tilemapData.format, tilemapData.data, tileWidth, tileHeight, width, height);
parsedData = Parse(key, tilemapData.format, tilemapData.data, tileWidth, tileHeight, insertNull);
}
}