UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

456 lines (455 loc) • 22.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCrawlSpaces = getCrawlSpaces; exports.getPits = getPits; exports.getPoops = getPoops; exports.getPressurePlates = getPressurePlates; exports.getRocks = getRocks; exports.getSpikes = getSpikes; exports.getTNT = getTNT; exports.getTeleporters = getTeleporters; exports.getTrapdoors = getTrapdoors; exports.removeAllCrawlSpaces = removeAllCrawlSpaces; exports.removeAllPits = removeAllPits; exports.removeAllPoops = removeAllPoops; exports.removeAllPressurePlates = removeAllPressurePlates; exports.removeAllRocks = removeAllRocks; exports.removeAllSpikes = removeAllSpikes; exports.removeAllTNT = removeAllTNT; exports.removeAllTeleporters = removeAllTeleporters; exports.removeAllTrapdoors = removeAllTrapdoors; exports.spawnCrawlSpace = spawnCrawlSpace; exports.spawnCrawlSpaceWithVariant = spawnCrawlSpaceWithVariant; exports.spawnDoor = spawnDoor; exports.spawnDoorWithVariant = spawnDoorWithVariant; exports.spawnPit = spawnPit; exports.spawnPitWithVariant = spawnPitWithVariant; exports.spawnPoop = spawnPoop; exports.spawnPoopWithVariant = spawnPoopWithVariant; exports.spawnPressurePlate = spawnPressurePlate; exports.spawnPressurePlateWithVariant = spawnPressurePlateWithVariant; exports.spawnRock = spawnRock; exports.spawnRockWithVariant = spawnRockWithVariant; exports.spawnSpikes = spawnSpikes; exports.spawnSpikesWithVariant = spawnSpikesWithVariant; exports.spawnTNT = spawnTNT; exports.spawnTNTWithVariant = spawnTNTWithVariant; exports.spawnTeleporter = spawnTeleporter; exports.spawnTeleporterWithVariant = spawnTeleporterWithVariant; exports.spawnTrapdoor = spawnTrapdoor; exports.spawnTrapdoorWithVariant = spawnTrapdoorWithVariant; 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); } // 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; } /** * 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; } /** * 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; } /** * 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; } /** 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; } /** 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; } /** * 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); } /** * 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); } /** * 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); } // 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); } /** * 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); } /** * 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); } /** * 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); } /** * 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); } /** * 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); } /** * 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); } /** * 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); } /** Helper function to spawn a `GridEntityType.CRAWL_SPACE` (18). */ function spawnCrawlSpace(gridIndexOrPosition) { return spawnCrawlSpaceWithVariant(isaac_typescript_definitions_1.CrawlSpaceVariant.NORMAL, gridIndexOrPosition); } /** 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); } /** Helper function to spawn a `GridEntityType.PIT` (7) with a specific variant. */ function spawnDoor(gridIndexOrPosition) { return spawnDoorWithVariant(isaac_typescript_definitions_1.DoorVariant.UNSPECIFIED, gridIndexOrPosition); } /** 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; } /** Helper function to spawn a `GridEntityType.DOOR` (16) with a specific variant. */ function spawnPit(gridIndexOrPosition) { return spawnPitWithVariant(isaac_typescript_definitions_1.PitVariant.NORMAL, gridIndexOrPosition); } /** 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; } /** Helper function to spawn a `GridEntityType.POOP` (14). */ function spawnPoop(gridIndexOrPosition) { return spawnPoopWithVariant(isaac_typescript_definitions_1.PoopGridEntityVariant.NORMAL, gridIndexOrPosition); } /** 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; } /** Helper function to spawn a `GridEntityType.PRESSURE_PLATE` (20). */ function spawnPressurePlate(gridIndexOrPosition) { return spawnPressurePlateWithVariant(isaac_typescript_definitions_1.PressurePlateVariant.PRESSURE_PLATE, gridIndexOrPosition); } /** 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; } /** Helper function to spawn a `GridEntityType.ROCK` (2). */ function spawnRock(gridIndexOrPosition) { return spawnRockWithVariant(isaac_typescript_definitions_1.RockVariant.NORMAL, gridIndexOrPosition); } /** 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; } /** Helper function to spawn a `GridEntityType.SPIKES` (8). */ function spawnSpikes(gridIndexOrPosition) { return spawnSpikesWithVariant(0, gridIndexOrPosition); } /** 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; } /** Helper function to spawn a `GridEntityType.TNT` (12). */ function spawnTNT(gridIndexOrPosition) { return spawnTNTWithVariant(0, gridIndexOrPosition); } /** 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; } /** Helper function to spawn a `GridEntityType.TELEPORTER` (23). */ function spawnTeleporter(gridIndexOrPosition) { return spawnTeleporterWithVariant(0, gridIndexOrPosition); } /** 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); } /** Helper function to spawn a `GridEntityType.TRAPDOOR` (17). */ function spawnTrapdoor(gridIndexOrPosition) { return spawnCrawlSpaceWithVariant(isaac_typescript_definitions_1.CrawlSpaceVariant.NORMAL, gridIndexOrPosition); } /** 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); }