2017-11-16 19:09:07 +00:00
|
|
|
var Tile = require('../Tile');
|
|
|
|
var IsInLayerBounds = require('./IsInLayerBounds');
|
|
|
|
|
|
|
|
// Remove and return Tile with option for placing a -1 index tile or null.
|
2017-11-18 22:11:51 +00:00
|
|
|
var RemoveTileAt = function (tileX, tileY, replaceWithNull, layer)
|
2017-11-16 19:09:07 +00:00
|
|
|
{
|
|
|
|
if (replaceWithNull === undefined) { replaceWithNull = false; }
|
|
|
|
|
|
|
|
if (!IsInLayerBounds(tileX, tileY, layer)) { return null; }
|
|
|
|
|
|
|
|
var tile = layer.data[tileY][tileX];
|
|
|
|
if (tile === null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
layer.data[tileY][tileX] = replaceWithNull
|
|
|
|
? null
|
|
|
|
: new Tile(layer, -1, tileX, tileY, tile.width, tile.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: re-calculate faces
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
};
|
|
|
|
|
2017-11-18 22:11:51 +00:00
|
|
|
module.exports = RemoveTileAt;
|