"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.spawnTrapdoorWithVariant = exports.spawnTrapdoor = exports.spawnTeleporterWithVariant = exports.spawnTeleporter = exports.spawnTNTWithVariant = exports.spawnTNT = exports.spawnSpikesWithVariant = exports.spawnSpikes = exports.spawnRockWithVariant = exports.spawnRock = exports.spawnPressurePlateWithVariant = exports.spawnPressurePlate = exports.spawnPoopWithVariant = exports.spawnPoop = exports.spawnPitWithVariant = exports.spawnPit = exports.spawnDoorWithVariant = exports.spawnDoor = exports.spawnCrawlSpaceWithVariant = exports.spawnCrawlSpace = exports.removeAllTrapdoors = exports.removeAllTeleporters = exports.removeAllTNT = exports.removeAllSpikes = exports.removeAllRocks = exports.removeAllPressurePlates = exports.removeAllPoops = exports.removeAllPits = exports.removeAllCrawlSpaces = exports.getTrapdoors = exports.getTeleporters = exports.getTNT = exports.getSpikes = exports.getRocks = exports.getPressurePlates = exports.getPoops = exports.getPits = exports.getCrawlSpaces = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const gridEntities_1 = require("./gridEntities");
const utils_1 = require("./utils");
/**
 * Helper function to get all of the grid entities of type `GridEntityType.CRAWL_SPACE` (18) in the
 * room.
 *
 * @param crawlSpaceVariant Optional. If specified, will only get the crawl spaces that match the
 *                          variant. Default is -1, which matches every variant.
 */
function getCrawlSpaces(crawlSpaceVariant = -1) {
    if (crawlSpaceVariant === -1) {
        return (0, gridEntities_1.getGridEntities)(isaac_typescript_definitions_1.GridEntityType.CRAWL_SPACE);
    }
    return (0, gridEntities_1.getMatchingGridEntities)(isaac_typescript_definitions_1.GridEntityType.CRAWL_SPACE, crawlSpaceVariant);
}
exports.getCrawlSpaces = getCrawlSpaces;
// The `getDoors` function is not located here because doors are collected via the `Room.GetDoor`
// method instead, which is faster.
/**
 * Helper function to get all of the `GridEntityPit` in the room.
 *
 * @param pitVariant Optional. If specified, will only get the pits that match the variant. Default
 *                   is -1, which matches every variant.
 */
function getPits(pitVariant = -1) {
    const pits = [];
    for (const gridEntity of (0, gridEntities_1.getGridEntities)()) {
        const pit = gridEntity.ToPit();
        if (pit !== undefined) {
            const thisPitVariant = pit.GetVariant();
            if (pitVariant === -1 || pitVariant === thisPitVariant) {
                pits.push(pit);
            }
        }
    }
    return pits;
}
exports.getPits = getPits;
/**
 * Helper function to get all of the `GridEntityPoop` in the room.
 *
 * @param poopVariant Optional. If specified, will only get the poops that match the variant.
 *                    Default is -1, which matches every variant.
 */
function getPoops(poopVariant = -1) {
    const poops = [];
    for (const gridEntity of (0, gridEntities_1.getGridEntities)()) {
        const poop = gridEntity.ToPoop();
        if (poop !== undefined) {
            const thisPoopVariant = poop.GetVariant();
            if (poopVariant === -1 || poopVariant === thisPoopVariant) {
                poops.push(poop);
            }
        }
    }
    return poops;
}
exports.getPoops = getPoops;
/**
 * Helper function to get all of the `GridEntityPressurePlate` in the room.
 *
 * @param pressurePlateVariant Optional. If specified, will only get the pressure plates that match
 *                             the variant. Default is -1, which matches every variant.
 */
function getPressurePlates(pressurePlateVariant = -1) {
    const pressurePlates = [];
    for (const gridEntity of (0, gridEntities_1.getGridEntities)()) {
        const pressurePlate = gridEntity.ToPressurePlate();
        if (pressurePlate !== undefined) {
            const thisPressurePlateVariant = pressurePlate.GetVariant();
            if (pressurePlateVariant === -1 ||
                pressurePlateVariant === thisPressurePlateVariant) {
                pressurePlates.push(pressurePlate);
            }
        }
    }
    return pressurePlates;
}
exports.getPressurePlates = getPressurePlates;
/**
 * Helper function to get all of the `GridEntityRock` in the room.
 *
 * @param variant Optional. If specified, will only get the rocks that match the variant. Default is
 *                -1, which matches every variant. Note that this is not the same thing as the
 *                `RockVariant` enum, since that only applies to `GridEntityType.ROCK`, and other
 *                types of grid entities can be the `GridEntityRock` class.
 */
function getRocks(variant = -1) {
    const rocks = [];
    for (const gridEntity of (0, gridEntities_1.getGridEntities)()) {
        const rock = gridEntity.ToRock();
        if (rock !== undefined) {
            const thisVariant = rock.GetVariant();
            if (variant === -1 || variant === thisVariant) {
                rocks.push(rock);
            }
        }
    }
    return rocks;
}
exports.getRocks = getRocks;
/** Helper function to get all of the `GridEntitySpikes` in the room. */
function getSpikes(variant = -1) {
    const spikes = [];
    for (const gridEntity of (0, gridEntities_1.getGridEntities)()) {
        const spike = gridEntity.ToSpikes();
        if (spike !== undefined) {
            const thisVariant = spike.GetVariant();
            if (variant === -1 || variant === thisVariant) {
                spikes.push(spike);
            }
        }
    }
    return spikes;
}
exports.getSpikes = getSpikes;
/** Helper function to get all of the `GridEntityTNT` in the room. */
function getTNT(variant = -1) {
    const tntArray = [];
    for (const gridEntity of (0, gridEntities_1.getGridEntities)()) {
        const tnt = gridEntity.ToTNT();
        if (tnt !== undefined) {
            const thisVariant = tnt.GetVariant();
            if (variant === -1 || variant === thisVariant) {
                tntArray.push(tnt);
            }
        }
    }
    return tntArray;
}
exports.getTNT = getTNT;
/**
 * Helper function to get all of the grid entities of type `GridEntityType.TELEPORTER` (23) in the
 * room.
 *
 * @param variant Optional. If specified, will only get the teleporters that match the variant.
 *                Default is -1, which matches every variant.
 */
function getTeleporters(variant = -1) {
    if (variant === -1) {
        return (0, gridEntities_1.getGridEntities)(isaac_typescript_definitions_1.GridEntityType.TELEPORTER);
    }
    return (0, gridEntities_1.getMatchingGridEntities)(isaac_typescript_definitions_1.GridEntityType.TELEPORTER, variant);
}
exports.getTeleporters = getTeleporters;
/**
 * Helper function to get all of the grid entities of type `GridEntityType.TRAPDOOR` (17) in the
 * room. Specify a specific trapdoor variant to select only trapdoors of that variant.
 *
 * @param trapdoorVariant Optional. If specified, will only get the trapdoors that match the
 *                        variant. Default is -1, which matches every variant.
 */
function getTrapdoors(trapdoorVariant = -1) {
    if (trapdoorVariant === -1) {
        return (0, gridEntities_1.getGridEntities)(isaac_typescript_definitions_1.GridEntityType.TRAPDOOR);
    }
    return (0, gridEntities_1.getMatchingGridEntities)(isaac_typescript_definitions_1.GridEntityType.TRAPDOOR, trapdoorVariant);
}
exports.getTrapdoors = getTrapdoors;
/**
 * Helper function to remove all of the `GridEntityType.CRAWL_SPACE` (18) in the room.
 *
 * @param crawlSpaceVariant Optional. If specified, will only remove the crawl spaces that match
 *                          this variant. Default is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the crawl spaces are removed.
 *                   Default is false. For more information, see the description of the
 *                   `removeGridEntities` helper function.
 * @param cap Optional. If specified, will only remove the given amount of crawl spaces.
 * @returns The crawl spaces that were removed.
 */
function removeAllCrawlSpaces(crawlSpaceVariant = -1, updateRoom = false, cap) {
    const crawlSpaces = getCrawlSpaces(crawlSpaceVariant);
    return (0, gridEntities_1.removeGridEntities)(crawlSpaces, updateRoom, cap);
}
exports.removeAllCrawlSpaces = removeAllCrawlSpaces;
// The `removeAllDoors` function is not located here because doors are removed via the
// `Room.RemoveDoor` method instead.
/**
 * Helper function to remove all of the `GridEntityPit` in the room.
 *
 * @param pitVariant Optional. If specified, will only remove the pits that match this variant.
 *                   Default is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the pits are removed. Default is
 *                   false. For more information, see the description of the `removeGridEntities`
 *                   helper function.
 * @param cap Optional. If specified, will only remove the given amount of pits.
 * @returns The pits that were removed.
 */
function removeAllPits(pitVariant = -1, updateRoom = false, cap) {
    const pits = getPits(pitVariant);
    return (0, gridEntities_1.removeGridEntities)(pits, updateRoom, cap);
}
exports.removeAllPits = removeAllPits;
/**
 * Helper function to remove all of the `GridEntityPoop` in the room.
 *
 * Note that poops can either be an entity or a grid entity, depending on the situation. This
 * function will only remove the grid entity poops.
 *
 * @param poopVariant Optional. If specified, will only remove the poops that match this variant.
 *                    Default is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the poops are removed. Default is
 *                   false. For more information, see the description of the `removeGridEntities`
 *                   helper function.
 * @param cap Optional. If specified, will only remove the given amount of poops.
 * @returns The poops that were removed.
 */
function removeAllPoops(poopVariant = -1, updateRoom = false, cap) {
    const poops = getPoops(poopVariant);
    return (0, gridEntities_1.removeGridEntities)(poops, updateRoom, cap);
}
exports.removeAllPoops = removeAllPoops;
/**
 * Helper function to remove all of the `GridEntityPressurePlate` in the room.
 *
 * @param pressurePlateVariant Optional. If specified, will only remove the pressure plates that
 *                             match this variant. Default is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the pressure plates are removed.
 *                   Default is false. For more information, see the description of the
 *                   `removeGridEntities` helper function.
 * @param cap Optional. If specified, will only remove the given amount of pressure plates.
 * @returns The pressure plates that were removed.
 */
function removeAllPressurePlates(pressurePlateVariant = -1, updateRoom = false, cap) {
    const pressurePlates = getPressurePlates(pressurePlateVariant);
    return (0, gridEntities_1.removeGridEntities)(pressurePlates, updateRoom, cap);
}
exports.removeAllPressurePlates = removeAllPressurePlates;
/**
 * Helper function to remove all of the `GridEntityRock` in the room.
 *
 * @param variant Optional. If specified, will only remove the rocks that match this variant.
 *                Default is -1, which matches every variant. Note that this is not the same thing
 *                as the `RockVariant` enum, since that only applies to `GridEntityType.ROCK`, and
 *                other types of grid entities can be the `GridEntityRock` class.
 * @param updateRoom Optional. Whether to update the room after the rocks are removed. Default is
 *                   false. For more information, see the description of the `removeGridEntities`
 *                   helper function.
 * @param cap Optional. If specified, will only remove the given amount of rocks.
 * @returns The rocks that were removed.
 */
function removeAllRocks(variant = -1, updateRoom = false, cap) {
    const rocks = getRocks(variant);
    return (0, gridEntities_1.removeGridEntities)(rocks, updateRoom, cap);
}
exports.removeAllRocks = removeAllRocks;
/**
 * Helper function to remove all of the `GridEntitySpikes` in the room.
 *
 * @param variant Optional. If specified, will only remove the spikes that match this variant.
 *                Default is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the spikes are removed. Default is
 *                   false. For more information, see the description of the `removeGridEntities`
 *                   helper function.
 * @param cap Optional. If specified, will only remove the given amount of spikes.
 * @returns The spikes that were removed.
 */
function removeAllSpikes(variant = -1, updateRoom = false, cap) {
    const spikes = getSpikes(variant);
    return (0, gridEntities_1.removeGridEntities)(spikes, updateRoom, cap);
}
exports.removeAllSpikes = removeAllSpikes;
/**
 * Helper function to remove all of the `GridEntityTNT` in the room.
 *
 * @param variant Optional. If specified, will only remove the TNTs that match this variant. Default
 *                is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the TNTs are removed. Default is
 *                   false. For more information, see the description of the `removeGridEntities`
 *                   helper function.
 * @param cap Optional. If specified, will only remove the given amount of TNTs.
 * @returns The TNTs that were removed.
 */
function removeAllTNT(variant = -1, updateRoom = false, cap) {
    const tnt = getTNT(variant);
    return (0, gridEntities_1.removeGridEntities)(tnt, updateRoom, cap);
}
exports.removeAllTNT = removeAllTNT;
/**
 * Helper function to remove all of the `GridEntityType.TELEPORTER` (23) in the room.
 *
 * @param variant Optional. If specified, will only remove the teleporters that match this variant.
 *                Default is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the teleporters are removed. Default
 *                   is false. For more information, see the description of the `removeGridEntities`
 *                   helper function.
 * @param cap Optional. If specified, will only remove the given amount of teleporters.
 * @returns The teleporters that were removed.
 */
function removeAllTeleporters(variant = -1, updateRoom = false, cap) {
    const teleporters = getTeleporters(variant);
    return (0, gridEntities_1.removeGridEntities)(teleporters, updateRoom, cap);
}
exports.removeAllTeleporters = removeAllTeleporters;
/**
 * Helper function to remove all of the `GridEntityType.TRAPDOOR` (17) in the room.
 *
 * @param trapdoorVariant Optional. If specified, will only remove the trapdoors that match this
 *                        variant. Default is -1, which matches every variant.
 * @param updateRoom Optional. Whether to update the room after the trapdoors are removed. Default
 *                   is false. For more information, see the description of the `removeGridEntities`
 *                   helper function.
 * @param cap Optional. If specified, will only remove the given amount of trapdoors.
 * @returns The trapdoors that were removed.
 */
function removeAllTrapdoors(trapdoorVariant = -1, updateRoom = false, cap) {
    const trapdoors = getTrapdoors(trapdoorVariant);
    return (0, gridEntities_1.removeGridEntities)(trapdoors, updateRoom, cap);
}
exports.removeAllTrapdoors = removeAllTrapdoors;
/** Helper function to spawn a `GridEntityType.CRAWL_SPACE` (18). */
function spawnCrawlSpace(gridIndexOrPosition) {
    return spawnCrawlSpaceWithVariant(isaac_typescript_definitions_1.CrawlSpaceVariant.NORMAL, gridIndexOrPosition);
}
exports.spawnCrawlSpace = spawnCrawlSpace;
/** Helper function to spawn a `GridEntityType.CRAWL_SPACE` (18) with a specific variant. */
function spawnCrawlSpaceWithVariant(crawlSpaceVariant, gridIndexOrPosition) {
    return (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.CRAWL_SPACE, crawlSpaceVariant, gridIndexOrPosition);
}
exports.spawnCrawlSpaceWithVariant = spawnCrawlSpaceWithVariant;
/** Helper function to spawn a `GridEntityType.PIT` (7) with a specific variant. */
function spawnDoor(gridIndexOrPosition) {
    return spawnDoorWithVariant(isaac_typescript_definitions_1.DoorVariant.UNSPECIFIED, gridIndexOrPosition);
}
exports.spawnDoor = spawnDoor;
/** Helper function to spawn a `GridEntityType.DOOR` (16). */
function spawnDoorWithVariant(doorVariant, gridIndexOrPosition) {
    const gridEntity = (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.DOOR, doorVariant, gridIndexOrPosition);
    if (gridEntity === undefined) {
        return undefined;
    }
    const door = gridEntity.ToDoor();
    (0, utils_1.assertDefined)(door, "Failed to spawn a door.");
    return door;
}
exports.spawnDoorWithVariant = spawnDoorWithVariant;
/** Helper function to spawn a `GridEntityType.DOOR` (16) with a specific variant. */
function spawnPit(gridIndexOrPosition) {
    return spawnPitWithVariant(isaac_typescript_definitions_1.PitVariant.NORMAL, gridIndexOrPosition);
}
exports.spawnPit = spawnPit;
/** Helper function to spawn a `GridEntityType.PIT` (7) with a specific variant. */
function spawnPitWithVariant(pitVariant, gridIndexOrPosition) {
    const gridEntity = (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.PIT, pitVariant, gridIndexOrPosition);
    if (gridEntity === undefined) {
        return undefined;
    }
    const pit = gridEntity.ToPit();
    (0, utils_1.assertDefined)(pit, "Failed to spawn a pit.");
    return pit;
}
exports.spawnPitWithVariant = spawnPitWithVariant;
/** Helper function to spawn a `GridEntityType.POOP` (14). */
function spawnPoop(gridIndexOrPosition) {
    return spawnPoopWithVariant(isaac_typescript_definitions_1.PoopGridEntityVariant.NORMAL, gridIndexOrPosition);
}
exports.spawnPoop = spawnPoop;
/** Helper function to spawn a `GridEntityType.POOP` (14) with a specific variant. */
function spawnPoopWithVariant(poopVariant, gridIndexOrPosition) {
    const gridEntity = (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.POOP, poopVariant, gridIndexOrPosition);
    if (gridEntity === undefined) {
        return undefined;
    }
    const poop = gridEntity.ToPoop();
    (0, utils_1.assertDefined)(poop, "Failed to spawn a poop.");
    return poop;
}
exports.spawnPoopWithVariant = spawnPoopWithVariant;
/** Helper function to spawn a `GridEntityType.PRESSURE_PLATE` (20). */
function spawnPressurePlate(gridIndexOrPosition) {
    return spawnPressurePlateWithVariant(isaac_typescript_definitions_1.PressurePlateVariant.PRESSURE_PLATE, gridIndexOrPosition);
}
exports.spawnPressurePlate = spawnPressurePlate;
/** Helper function to spawn a `GridEntityType.PRESSURE_PLATE` (20) with a specific variant. */
function spawnPressurePlateWithVariant(pressurePlateVariant, gridIndexOrPosition) {
    const gridEntity = (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.PRESSURE_PLATE, pressurePlateVariant, gridIndexOrPosition);
    if (gridEntity === undefined) {
        return undefined;
    }
    const pressurePlate = gridEntity.ToPressurePlate();
    (0, utils_1.assertDefined)(pressurePlate, "Failed to spawn a pressure plate.");
    return pressurePlate;
}
exports.spawnPressurePlateWithVariant = spawnPressurePlateWithVariant;
/** Helper function to spawn a `GridEntityType.ROCK` (2). */
function spawnRock(gridIndexOrPosition) {
    return spawnRockWithVariant(isaac_typescript_definitions_1.RockVariant.NORMAL, gridIndexOrPosition);
}
exports.spawnRock = spawnRock;
/** Helper function to spawn a `GridEntityType.ROCK` (2) with a specific variant. */
function spawnRockWithVariant(rockVariant, gridIndexOrPosition) {
    const gridEntity = (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.ROCK, rockVariant, gridIndexOrPosition);
    if (gridEntity === undefined) {
        return undefined;
    }
    const rock = gridEntity.ToRock();
    (0, utils_1.assertDefined)(rock, "Failed to spawn a rock.");
    return rock;
}
exports.spawnRockWithVariant = spawnRockWithVariant;
/** Helper function to spawn a `GridEntityType.SPIKES` (8). */
function spawnSpikes(gridIndexOrPosition) {
    return spawnSpikesWithVariant(0, gridIndexOrPosition);
}
exports.spawnSpikes = spawnSpikes;
/** Helper function to spawn a `GridEntityType.SPIKES` (8) with a specific variant. */
function spawnSpikesWithVariant(variant, gridIndexOrPosition) {
    const gridEntity = (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.SPIKES, variant, gridIndexOrPosition);
    if (gridEntity === undefined) {
        return undefined;
    }
    const spikes = gridEntity.ToSpikes();
    (0, utils_1.assertDefined)(spikes, "Failed to spawn spikes.");
    return spikes;
}
exports.spawnSpikesWithVariant = spawnSpikesWithVariant;
/** Helper function to spawn a `GridEntityType.TNT` (12). */
function spawnTNT(gridIndexOrPosition) {
    return spawnTNTWithVariant(0, gridIndexOrPosition);
}
exports.spawnTNT = spawnTNT;
/** Helper function to spawn a `GridEntityType.TNT` (12) with a specific variant. */
function spawnTNTWithVariant(variant, gridIndexOrPosition) {
    const gridEntity = (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.TNT, variant, gridIndexOrPosition);
    if (gridEntity === undefined) {
        return undefined;
    }
    const tnt = gridEntity.ToTNT();
    (0, utils_1.assertDefined)(tnt, "Failed to spawn TNT.");
    return tnt;
}
exports.spawnTNTWithVariant = spawnTNTWithVariant;
/** Helper function to spawn a `GridEntityType.TELEPORTER` (23). */
function spawnTeleporter(gridIndexOrPosition) {
    return spawnTeleporterWithVariant(0, gridIndexOrPosition);
}
exports.spawnTeleporter = spawnTeleporter;
/** Helper function to spawn a `GridEntityType.TELEPORTER` (23) with a specific variant. */
function spawnTeleporterWithVariant(variant, gridIndexOrPosition) {
    return (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.TELEPORTER, variant, gridIndexOrPosition);
}
exports.spawnTeleporterWithVariant = spawnTeleporterWithVariant;
/** Helper function to spawn a `GridEntityType.TRAPDOOR` (17). */
function spawnTrapdoor(gridIndexOrPosition) {
    return spawnCrawlSpaceWithVariant(isaac_typescript_definitions_1.CrawlSpaceVariant.NORMAL, gridIndexOrPosition);
}
exports.spawnTrapdoor = spawnTrapdoor;
/** Helper function to spawn a `GridEntityType.TRAPDOOR` (17) with a specific variant. */
function spawnTrapdoorWithVariant(trapdoorVariant, gridIndexOrPosition) {
    return (0, gridEntities_1.spawnGridEntityWithVariant)(isaac_typescript_definitions_1.GridEntityType.TRAPDOOR, trapdoorVariant, gridIndexOrPosition);
}
exports.spawnTrapdoorWithVariant = spawnTrapdoorWithVariant;
