"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("../util");
const BaseForLines_1 = require("./BaseForLines");
let collisionIdCounter = 0;
class CollisionLayer extends BaseForLines_1.BaseForLines {
    constructor(source, tiles) {
        super(source);
        this.id = collisionIdCounter++;
        // Map all the Objects to the layer
        tiles.forEach((tile) => {
            tile.setCollisionLayer(this);
            tile._getDescendantTiles().forEach((subTile) => {
                subTile.setCollisionLayer(this);
            });
        });
        // build an array of Sprites so we can index to them in a BitSet
        this.sprites = [...new Set(util_1._flatten(tiles.map((t) => t.getSprites())))];
        this.sprites.forEach((sprite, index) => sprite.setCollisionLayerAndIndex(this, index));
    }
    // isInvalid(): Optional<string> {
    //     return null
    // }
    getBitSetIndexOf(sprite) {
        const index = this.sprites.indexOf(sprite);
        if (index < 0) {
            throw new Error(`BUG: Sprite is not in this CollisionLayer`);
        }
        return index;
    }
}
exports.CollisionLayer = CollisionLayer;
//# sourceMappingURL=collisionLayer.js.map