"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeAllRedHearts = exports.isRedHeartSubType = exports.isRedHeart = exports.isChestVariant = exports.isChest = exports.getSackName = exports.getRedHearts = exports.getKeyName = exports.getHeartName = exports.getCoinValue = exports.getCoinName = exports.getChestName = exports.getBombName = exports.getBatteryName = void 0;
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;
}
exports.getBatteryName = getBatteryName;
/**
 * 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;
}
exports.getBombName = getBombName;
/**
 * 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;
}
exports.getChestName = getChestName;
/**
 * 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;
}
exports.getCoinName = getCoinName;
/**
 * 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;
}
exports.getCoinValue = getCoinValue;
/**
 * 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;
}
exports.getHeartName = getHeartName;
/**
 * 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;
}
exports.getKeyName = getKeyName;
/** 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));
}
exports.getRedHearts = getRedHearts;
/**
 * 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;
}
exports.getSackName = getSackName;
/** Helper function to test if the provided pickup matches one of the various chest variants. */
function isChest(pickup) {
    return isChestVariant(pickup.Variant);
}
exports.isChest = isChest;
/**
 * 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);
}
exports.isChestVariant = isChestVariant;
/**
 * 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);
}
exports.isRedHeart = isRedHeart;
/**
 * 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);
}
exports.isRedHeartSubType = isRedHeartSubType;
/**
 * 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);
}
exports.removeAllRedHearts = removeAllRedHearts;
