UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

582 lines (581 loc) • 26.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBombs = getBombs; exports.getEffects = getEffects; exports.getFamiliars = getFamiliars; exports.getKnives = getKnives; exports.getLasers = getLasers; exports.getNPCs = getNPCs; exports.getPickups = getPickups; exports.getProjectiles = getProjectiles; exports.getSlots = getSlots; exports.getTears = getTears; exports.removeAllBombs = removeAllBombs; exports.removeAllEffects = removeAllEffects; exports.removeAllFamiliars = removeAllFamiliars; exports.removeAllKnives = removeAllKnives; exports.removeAllLasers = removeAllLasers; exports.removeAllNPCs = removeAllNPCs; exports.removeAllPickups = removeAllPickups; exports.removeAllProjectiles = removeAllProjectiles; exports.removeAllSlots = removeAllSlots; exports.removeAllTears = removeAllTears; exports.spawnBomb = spawnBomb; exports.spawnBombWithSeed = spawnBombWithSeed; exports.spawnEffect = spawnEffect; exports.spawnEffectWithSeed = spawnEffectWithSeed; exports.spawnFamiliar = spawnFamiliar; exports.spawnFamiliarWithSeed = spawnFamiliarWithSeed; exports.spawnKnife = spawnKnife; exports.spawnKnifeWithSeed = spawnKnifeWithSeed; exports.spawnLaser = spawnLaser; exports.spawnLaserWithSeed = spawnLaserWithSeed; exports.spawnNPC = spawnNPC; exports.spawnNPCWithSeed = spawnNPCWithSeed; exports.spawnPickup = spawnPickup; exports.spawnPickupWithSeed = spawnPickupWithSeed; exports.spawnProjectile = spawnProjectile; exports.spawnProjectileWithSeed = spawnProjectileWithSeed; exports.spawnSlot = spawnSlot; exports.spawnSlotWithSeed = spawnSlotWithSeed; exports.spawnTear = spawnTear; exports.spawnTearWithSeed = spawnTearWithSeed; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const constants_1 = require("../core/constants"); const entities_1 = require("./entities"); const utils_1 = require("./utils"); /** * Helper function to get all of the bombs in the room. (Specifically, this refers to the * `EntityBomb` class, not bomb pickups.) * * For example: * * ```ts * // Make all of the bombs in the room invisible. * for (const bomb of getBombs()) { * bomb.Visible = false; * } * ``` * * @param bombVariant Optional. If specified, will only get the bombs that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only get the bombs that match the sub-type. Default * is -1, which matches every sub-type. */ function getBombs(bombVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.BOMB, bombVariant, subType); const bombs = []; for (const entity of entities) { const bomb = entity.ToBomb(); if (bomb !== undefined) { bombs.push(bomb); } } return bombs; } /** * Helper function to get all of the effects in the room. * * For example: * * ```ts * // Make all of the effects in the room invisible. * for (const effect of getEffects()) { * effect.Visible = false; * } * ``` * * @param effectVariant Optional. If specified, will only get the effects that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only get the effects that match the sub-type. Default * is -1, which matches every sub-type. */ function getEffects(effectVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.EFFECT, effectVariant, subType); const effects = []; for (const entity of entities) { const effect = entity.ToEffect(); if (effect !== undefined) { effects.push(effect); } } return effects; } /** * Helper function to get all of the familiars in the room. * * For example: * * ```ts * // Make all of the familiars in the room invisible. * for (const familiar of getFamiliars()) { * familiar.Visible = false; * } * ``` * * @param familiarVariant Optional. If specified, will only get the familiars that match the * variant. Default is -1, which matches every variant. * @param subType Optional. If specified, will only get the familiars that match the sub-type. * Default is -1, which matches every sub-type. */ function getFamiliars(familiarVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.FAMILIAR, familiarVariant, subType); const familiars = []; for (const entity of entities) { const familiar = entity.ToFamiliar(); if (familiar !== undefined) { familiars.push(familiar); } } return familiars; } /** * Helper function to get all of the knives in the room. * * For example: * * ```ts * // Make all of the knives in the room invisible. * for (const knife of getKnives()) { * knife.Visible = false; * } * ``` * * @param knifeVariant Optional. If specified, will only get the knives that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only get the knives that match the sub-type. Default * is -1, which matches every sub-type. */ function getKnives(knifeVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.KNIFE, knifeVariant, subType); const knives = []; for (const entity of entities) { const knife = entity.ToKnife(); if (knife !== undefined) { knives.push(knife); } } return knives; } /** * Helper function to get all of the lasers in the room. * * For example: * * ```ts * // Make all of the lasers in the room invisible. * for (const laser of getLasers()) { * laser.Visible = false; * } * ``` * * @param laserVariant Optional. If specified, will only get the lasers that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only get the lasers that match the sub-type. Default * is -1, which matches every sub-type. */ function getLasers(laserVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.LASER, laserVariant, subType); const lasers = []; for (const entity of entities) { const laser = entity.ToLaser(); if (laser !== undefined) { lasers.push(laser); } } return lasers; } /** * Helper function to get all of the NPCs in the room. * * @param entityType Optional. If specified, will only get the NPCs that match the type. Default is * -1, which matches every entity type. * @param variant Optional. If specified, will only get the NPCs that match the variant. Default is * -1, which matches every entity type. * @param subType Optional. If specified, will only get the bombs that match the sub-type. Default * is -1, which matches every sub-type. * @param ignoreFriendly Optional. If set to true, it will exclude friendly NPCs from being * returned. Default is false. Will only be taken into account if the * `entityType` is specified. */ function getNPCs(entityType = -1, variant = -1, subType = -1, ignoreFriendly = false) { const entities = (0, entities_1.getEntities)(entityType, variant, subType, ignoreFriendly); const npcs = []; for (const entity of entities) { const npc = entity.ToNPC(); if (npc !== undefined) { npcs.push(npc); } } return npcs; } /** * Helper function to get all of the pickups in the room. * * For example: * * ```ts * // Make all of the pickups in the room invisible. * for (const pickup of getPickups()) { * pickup.Visible = false; * } * ``` * * @param pickupVariant Optional. If specified, will only get the pickups that match the variant. * Default is -1, which matches every entity type. * @param subType Optional. If specified, will only get the pickups that match the sub-type. Default * is -1, which matches every sub-type. */ function getPickups(pickupVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.PICKUP, pickupVariant, subType); const pickups = []; for (const entity of entities) { const pickup = entity.ToPickup(); if (pickup !== undefined) { pickups.push(pickup); } } return pickups; } /** * Helper function to get all of the projectiles in the room. * * For example: * * ```ts * // Make all of the projectiles in the room invisible. * for (const projectile of getProjectiles()) { * projectile.Visible = false; * } * ``` * * @param projectileVariant Optional. If specified, will only get the projectiles that match the * variant. Default is -1, which matches every entity type. * @param subType Optional. If specified, will only get the projectiles that match the sub-type. * Default is -1, which matches every sub-type. */ function getProjectiles(projectileVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.PROJECTILE, projectileVariant, subType); const projectiles = []; for (const entity of entities) { const projectile = entity.ToProjectile(); if (projectile !== undefined) { projectiles.push(projectile); } } return projectiles; } /** * Helper function to get all of the slots in the room. * * For example: * * ```ts * // Make all of the slots in the room invisible. * for (const slot of getSlots()) { * slot.Visible = false; * } * ``` * * @param slotVariant Optional. If specified, will only get the slots that match the variant. * Default is -1, which matches every entity type. * @param subType Optional. If specified, will only get the slots that match the sub-type. Default * is -1, which matches every sub-type. */ function getSlots(slotVariant = -1, subType = -1) { const slots = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.SLOT, slotVariant, subType); return slots; } /** * Helper function to get all of the tears in the room. * * For example: * * ```ts * // Make all of the tears in the room invisible. * for (const tear of getTears()) { * tear.Visible = false; * } * ``` * * @param tearVariant Optional. If specified, will only get the tears that match the variant. * Default is -1, which matches every entity type. * @param subType Optional. If specified, will only get the tears that match the sub-type. Default * is -1, which matches every sub-type. */ function getTears(tearVariant = -1, subType = -1) { const entities = (0, entities_1.getEntities)(isaac_typescript_definitions_1.EntityType.TEAR, tearVariant, subType); const tears = []; for (const entity of entities) { const tear = entity.ToTear(); if (tear !== undefined) { tears.push(tear); } } return tears; } /** * Helper function to remove all of the bombs in the room. (Specifically, this refers to the * `EntityBomb` class, not bomb pickups.) * * @param bombVariant Optional. If specified, will only remove the bombs that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove the bombs that match the sub-type. * Default is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of bombs. * @returns An array of the bombs that were removed. */ function removeAllBombs(bombVariant = -1, subType = -1, cap) { const bombs = getBombs(bombVariant, subType); return (0, entities_1.removeEntities)(bombs, cap); } /** * Helper function to remove all of the effects in the room. * * @param effectVariant Optional. If specified, will only remove the effects that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove the effects that match the sub-type. * Default is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of effects. * @returns An array of the effects that were removed. */ function removeAllEffects(effectVariant = -1, subType = -1, cap) { const effects = getEffects(effectVariant, subType); return (0, entities_1.removeEntities)(effects, cap); } /** * Helper function to remove all of the familiars in the room. * * @param familiarVariant Optional. If specified, will only remove the familiars that match the * variant. Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove the familiars that match the sub-type. * Default is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of familiars. * @returns An array of the familiars that were removed. */ function removeAllFamiliars(familiarVariant = -1, subType = -1, cap) { const familiars = getFamiliars(familiarVariant, subType); return (0, entities_1.removeEntities)(familiars, cap); } /** * Helper function to remove all of the knives in the room. * * @param knifeVariant Optional. If specified, will only remove the knives that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove the knives that match the sub-type. * Default is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of knives. * @returns An array of the knives that were removed. */ function removeAllKnives(knifeVariant = -1, subType = -1, cap) { const knives = getKnives(knifeVariant, subType); return (0, entities_1.removeEntities)(knives, cap); } /** * Helper function to remove all of the lasers in the room. * * @param laserVariant Optional. If specified, will only remove the lasers that match the variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove the lasers that match the sub-type. * Default is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of lasers. * @returns An array of the lasers that were removed. */ function removeAllLasers(laserVariant = -1, subType = -1, cap) { const lasers = getLasers(laserVariant, subType); return (0, entities_1.removeEntities)(lasers, cap); } /** * Helper function to remove all of the NPCs in the room. * * @param entityType Optional. If specified, will only remove the NPCs that match the type. Default * is -1, which matches every type. * @param variant Optional. If specified, will only remove the NPCs that match the variant. Default * is -1, which matches every variant. * @param subType Optional. If specified, will only remove the NPCs that match the sub-type. Default * is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of NPCs. * @returns An array of the NPCs that were removed. */ function removeAllNPCs(entityType = -1, variant = -1, subType = -1, cap) { const npcs = getNPCs(entityType, variant, subType); return (0, entities_1.removeEntities)(npcs, cap); } /** * Helper function to remove all of the pickups in the room. * * @param pickupVariant Optional. If specified, will only remove pickups that match this variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove pickups that match this sub-type. Default * is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of pickups. * @returns An array of the pickups that were removed. */ function removeAllPickups(pickupVariant = -1, subType = -1, cap) { const pickups = getPickups(pickupVariant, subType); return (0, entities_1.removeEntities)(pickups, cap); } /** * Helper function to remove all of the projectiles in the room. * * @param projectileVariant Optional. If specified, will only remove projectiles that match this * variant. Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove projectiles that match this sub-type. * Default is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of projectiles. * @returns An array of the projectiles that were removed. */ function removeAllProjectiles(projectileVariant = -1, subType = -1, cap) { const projectiles = getProjectiles(projectileVariant, subType); return (0, entities_1.removeEntities)(projectiles, cap); } /** * Helper function to remove all of the slots in the room. * * @param slotVariant Optional. If specified, will only remove slots that match this variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove slots that match this sub-type. Default * is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of slots. * @returns An array of the slots that were removed. */ function removeAllSlots(slotVariant = -1, subType = -1, cap) { const slots = getSlots(slotVariant, subType); return (0, entities_1.removeEntities)(slots, cap); } /** * Helper function to remove all of the tears in the room. * * @param tearVariant Optional. If specified, will only remove tears that match this variant. * Default is -1, which matches every variant. * @param subType Optional. If specified, will only remove tears that match this sub-type. Default * is -1, which matches every sub-type. * @param cap Optional. If specified, will only remove the given amount of tears. * @returns An array of the tears that were removed. */ function removeAllTears(tearVariant = -1, subType = -1, cap) { const tears = getTears(tearVariant, subType); return (0, entities_1.removeEntities)(tears, cap); } /** Helper function to spawn a `EntityType.BOMB` (4). */ function spawnBomb(bombVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.BOMB, bombVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const bomb = entity.ToBomb(); (0, utils_1.assertDefined)(bomb, "Failed to spawn a bomb."); return bomb; } /** Helper function to spawn a `EntityType.BOMB` (4) with a specific seed. */ function spawnBombWithSeed(bombVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnBomb(bombVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.EFFECT` (1000). */ function spawnEffect(effectVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.EFFECT, effectVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const effect = entity.ToEffect(); (0, utils_1.assertDefined)(effect, "Failed to spawn an effect."); return effect; } /** Helper function to spawn a `EntityType.EFFECT` (1000) with a specific seed. */ function spawnEffectWithSeed(effectVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnEffect(effectVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** * Helper function to spawn a `EntityType.FAMILIAR` (3). * * If you are trying to implement a custom familiar, you probably want to use the * `checkFamiliarFromCollectibles` helper function instead. */ function spawnFamiliar(familiarVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.FAMILIAR, familiarVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const familiar = entity.ToFamiliar(); (0, utils_1.assertDefined)(familiar, "Failed to spawn a familiar."); return familiar; } /** Helper function to spawn a `EntityType.FAMILIAR` (3) with a specific seed. */ function spawnFamiliarWithSeed(familiarVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnFamiliar(familiarVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.KNIFE` (8). */ function spawnKnife(knifeVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.KNIFE, knifeVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const knife = entity.ToKnife(); (0, utils_1.assertDefined)(knife, "Failed to spawn a knife."); return knife; } /** Helper function to spawn a `EntityType.KNIFE` (8) with a specific seed. */ function spawnKnifeWithSeed(knifeVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnKnife(knifeVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.LASER` (7). */ function spawnLaser(laserVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.LASER, laserVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const laser = entity.ToLaser(); (0, utils_1.assertDefined)(laser, "Failed to spawn a laser."); return laser; } /** Helper function to spawn a `EntityType.LASER` (7) with a specific seed. */ function spawnLaserWithSeed(laserVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnLaser(laserVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** * Helper function to spawn an NPC. * * Note that if you pass a non-NPC `EntityType` to this function, it will cause a run-time error, * since the `Entity.ToNPC` method will return undefined. */ function spawnNPC(entityType, variant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(entityType, variant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const npc = entity.ToNPC(); (0, utils_1.assertDefined)(npc, "Failed to spawn an NPC."); return npc; } /** * Helper function to spawn an NPC with a specific seed. * * Note that if you pass a non-NPC `EntityType` to this function, it will cause a run-time error, * since the `Entity.ToNPC` method will return undefined. */ function spawnNPCWithSeed(entityType, variant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnNPC(entityType, variant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.PICKUP` (5). */ function spawnPickup(pickupVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.PICKUP, pickupVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const pickup = entity.ToPickup(); (0, utils_1.assertDefined)(pickup, "Failed to spawn a pickup."); return pickup; } /** Helper function to spawn a `EntityType.PICKUP` (5) with a specific seed. */ function spawnPickupWithSeed(pickupVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnPickup(pickupVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.PROJECTILE` (9). */ function spawnProjectile(projectileVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.PROJECTILE, projectileVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const projectile = entity.ToProjectile(); (0, utils_1.assertDefined)(projectile, "Failed to spawn a projectile."); return projectile; } /** Helper function to spawn a `EntityType.PROJECTILE` (9) with a specific seed. */ function spawnProjectileWithSeed(projectileVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnProjectile(projectileVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.SLOT` (6). */ function spawnSlot(slotVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { return (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.SLOT, slotVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.SLOT` (6) with a specific seed. */ function spawnSlotWithSeed(slotVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnSlot(slotVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); } /** Helper function to spawn a `EntityType.TEAR` (2). */ function spawnTear(tearVariant, subType, positionOrGridIndex, velocity = constants_1.VectorZero, spawner, seedOrRNG) { const entity = (0, entities_1.spawn)(isaac_typescript_definitions_1.EntityType.TEAR, tearVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); const tear = entity.ToTear(); (0, utils_1.assertDefined)(tear, "Failed to spawn a tear."); return tear; } /** Helper function to spawn a `EntityType.EntityType` (2) with a specific seed. */ function spawnTearWithSeed(tearVariant, subType, positionOrGridIndex, seedOrRNG, velocity = constants_1.VectorZero, spawner) { return spawnTear(tearVariant, subType, positionOrGridIndex, velocity, spawner, seedOrRNG); }