isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
168 lines (167 loc) • 6.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBatteryName = getBatteryName;
exports.getBombName = getBombName;
exports.getChestName = getChestName;
exports.getCoinName = getCoinName;
exports.getCoinValue = getCoinValue;
exports.getHeartName = getHeartName;
exports.getKeyName = getKeyName;
exports.getRedHearts = getRedHearts;
exports.getSackName = getSackName;
exports.isChest = isChest;
exports.isChestVariant = isChestVariant;
exports.isRedHeart = isRedHeart;
exports.isRedHeartSubType = isRedHeartSubType;
exports.removeAllRedHearts = removeAllRedHearts;
const constants_1 = require("../core/constants");
const batteryNames_1 = require("../objects/batteryNames");
const bombNames_1 = require("../objects/bombNames");
const chestNames_1 = require("../objects/chestNames");
const coinNames_1 = require("../objects/coinNames");
const coinSubTypeToValue_1 = require("../objects/coinSubTypeToValue");
const heartNames_1 = require("../objects/heartNames");
const keyNames_1 = require("../objects/keyNames");
const sackNames_1 = require("../objects/sackNames");
const redHeartSubTypesSet_1 = require("../sets/redHeartSubTypesSet");
const entities_1 = require("./entities");
const pickupVariants_1 = require("./pickupVariants");
const pickupsSpecific_1 = require("./pickupsSpecific");
/**
* Helper function to get the name of a battery, as listed in the "entities2.xml" file. Returns
* "Unknown" if the provided battery sub-type is not valid.
*
* This function only works for vanilla battery types.
*
* For example, `getBatteryName(BatterySubType.MICRO)` would return "Micro Battery".
*/
function getBatteryName(batterySubType) {
// Handle modded hearts.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return batteryNames_1.BATTERY_NAMES[batterySubType] ?? batteryNames_1.DEFAULT_BATTERY_NAME;
}
/**
* Helper function to get the name of a bomb, as listed in the "entities2.xml" file. Returns
* "Unknown" if the provided bomb sub-type is not valid.
*
* This function only works for vanilla bomb types.
*
* For example, `getBombName(BombSubType.DOUBLE_PACK)` would return "Double Bomb".
*/
function getBombName(bombSubType) {
// Handle modded bombs.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return bombNames_1.BOMB_NAMES[bombSubType] ?? bombNames_1.DEFAULT_BOMB_NAME;
}
/**
* Helper function to get the name of a chest, as listed in the "entities2.xml" file. Returns
* "Unknown" if the pickup variant was not a chest.
*
* This function only works for vanilla chest types.
*
* For example, `getChestName(PickupVariant.SPIKED_CHEST)` would return "Spiked Chest".
*/
function getChestName(pickupVariant) {
const chestNames = chestNames_1.CHEST_NAMES;
return chestNames[pickupVariant] ?? chestNames_1.DEFAULT_CHEST_NAME;
}
/**
* Helper function to get the name of a coin, as listed in the "entities2.xml" file. Returns
* "Unknown" if the provided coin sub-type is not valid.
*
* This function only works for vanilla chest types.
*
* For example, `getCoinName(CoinSubType.DOUBLE_PACK)` would return "Double Penny".
*/
function getCoinName(coinSubType) {
// Handle modded coins.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return coinNames_1.COIN_NAMES[coinSubType] ?? coinNames_1.DEFAULT_COIN_NAME;
}
/**
* Helper function to get the corresponding coin amount from a `CoinSubType`. Returns 1 for modded
* sub-types.
*/
function getCoinValue(coinSubType) {
const value = coinSubTypeToValue_1.COIN_SUB_TYPE_TO_VALUE[coinSubType];
// Handle modded coin sub-types.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return value ?? coinSubTypeToValue_1.DEFAULT_COIN_VALUE;
}
/**
* Helper function to get the name of a heart, as listed in the "entities2.xml" file. Returns
* "Unknown" if the provided heart sub-type is not valid.
*
* This function only works for vanilla heart types.
*
* For example, `getHeartName(HeartSubType.ETERNAL)` would return "Heart (eternal)".
*/
function getHeartName(heartSubType) {
// Handle modded hearts.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return heartNames_1.HEART_NAMES[heartSubType] ?? heartNames_1.DEFAULT_HEART_NAME;
}
/**
* Helper function to get the name of a key, as listed in the "entities2.xml" file. Returns
* "Unknown" if the provided key sub-type is not valid.
*
* This function only works for vanilla key types.
*
* For example, `getKeyName(KeySubType.DOUBLE_PACK)` would return "Key Ring".
*/
function getKeyName(keySubType) {
// Handle modded bombs.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return keyNames_1.KEY_NAMES[keySubType] ?? keyNames_1.DEFAULT_KEY_NAME;
}
/** Helper function to get all of the red heart pickup entities in the room. */
function getRedHearts() {
const hearts = (0, pickupsSpecific_1.getHearts)();
return hearts.filter((heart) => redHeartSubTypesSet_1.RED_HEART_SUB_TYPES_SET.has(heart.SubType));
}
/**
* Helper function to get the name of a sack, as listed in the "entities2.xml" file. Returns
* "Unknown" if the provided sack sub-type is not valid.
*
* This function only works for vanilla sack types.
*
* For example, `getSackName(SackSubType.NORMAL)` would return "Grab Bag".
*/
function getSackName(sackSubType) {
// Handle modded hearts.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return sackNames_1.SACK_NAMES[sackSubType] ?? sackNames_1.DEFAULT_SACK_NAME;
}
/** Helper function to test if the provided pickup matches one of the various chest variants. */
function isChest(pickup) {
return isChestVariant(pickup.Variant);
}
/**
* Helper function to test if the provided pickup variant matches one of the various chest variants.
*/
function isChestVariant(pickupVariant) {
return constants_1.CHEST_PICKUP_VARIANTS_SET.has(pickupVariant);
}
/**
* Helper function to test if the provided pickup matches one of the various red heart sub-types.
*/
function isRedHeart(pickup) {
return (0, pickupVariants_1.isHeart)(pickup) && redHeartSubTypesSet_1.RED_HEART_SUB_TYPES_SET.has(pickup.SubType);
}
/**
* Helper function to test if the provided heart sub-type matches one of the various red heart
* sub-types.
*/
function isRedHeartSubType(heartSubType) {
return redHeartSubTypesSet_1.RED_HEART_SUB_TYPES_SET.has(heartSubType);
}
/**
* Helper function to remove all of the red heart pickup entities in the room.
*
* @param cap Optional. If specified, will only remove the given amount of hearts.
* @returns The red hearts that were removed.
*/
function removeAllRedHearts(cap) {
const redHearts = getRedHearts();
return (0, entities_1.removeEntities)(redHearts, cap);
}