2017-11-21 02:06:49 +00:00
|
|
|
var SetTileCollision = require('./SetTileCollision');
|
2017-11-22 01:18:34 +00:00
|
|
|
var CalculateFacesWithin = require('./CalculateFacesWithin');
|
2017-11-22 01:13:43 +00:00
|
|
|
var SetLayerCollisionIndex = require('./SetLayerCollisionIndex');
|
2017-11-21 02:06:49 +00:00
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
// Note: this only updates layer.collideIndexes for tile indexes found currently in the layer
|
2017-11-21 02:06:49 +00:00
|
|
|
var SetCollisionByExclusion = function (indexes, collides, recalculateFaces, layer)
|
|
|
|
{
|
|
|
|
if (collides === undefined) { collides = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
if (!Array.isArray(indexes)) { indexes = [ indexes ]; }
|
|
|
|
|
|
|
|
for (var ty = 0; ty < layer.height; ty++)
|
|
|
|
{
|
|
|
|
for (var tx = 0; tx < layer.width; tx++)
|
|
|
|
{
|
|
|
|
var tile = layer.data[ty][tx];
|
|
|
|
if (tile && indexes.indexOf(tile.index) === -1)
|
|
|
|
{
|
|
|
|
SetTileCollision(tile, collides);
|
2017-11-22 01:13:43 +00:00
|
|
|
SetLayerCollisionIndex(tile.index, collides, layer);
|
2017-11-21 02:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
if (recalculateFaces) { CalculateFacesWithin(0, 0, layer.width, layer.height, layer); }
|
2017-11-21 02:06:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SetCollisionByExclusion;
|