isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
37 lines (36 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCurseIDByName = getCurseIDByName;
exports.hasCurse = hasCurse;
const cachedClasses_1 = require("../core/cachedClasses");
const flag_1 = require("./flag");
/**
* Helper function to get the actual bit flag for modded curses.
*
* Will throw a run-time error if the provided curse does not exist.
*
* Use this over the `Isaac.GetCurseIdByName` method because that will return an integer instead of
* a bit flag.
*/
function getCurseIDByName(name) {
const curseID = Isaac.GetCurseIdByName(name);
if (curseID === -1) {
error(`Failed to get the curse ID corresponding to the curse name of "${curseID}". Does this name match what you put in the "content/curses.xml" file?`);
}
// For example, the final vanilla curse is "Curse of the Giant", which has an ID of 8. This
// corresponds to `LevelCurse.GIANT`, which has a value of `1 << 7`.
return (1 << (curseID - 1));
}
/**
* Helper function to check if the current floor has a particular curse.
*
* This function is variadic, meaning that you can specify as many curses as you want. The function
* will return true if the level has one or more of the curses.
*
* Under the hood, this function uses the `Level.GetCurses` method.
*/
function hasCurse(...curses) {
const level = cachedClasses_1.game.GetLevel();
const levelCurses = level.GetCurses();
return curses.some((curse) => (0, flag_1.hasFlag)(levelCurses, curse));
}