UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

117 lines (116 loc) 4.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clearChallenge = clearChallenge; exports.getChallengeBoss = getChallengeBoss; exports.getChallengeCharacter = getChallengeCharacter; exports.getChallengeCollectibleTypes = getChallengeCollectibleTypes; exports.getChallengeName = getChallengeName; exports.getChallengeTrinketType = getChallengeTrinketType; exports.onAnyChallenge = onAnyChallenge; exports.onChallenge = onChallenge; exports.setChallenge = setChallenge; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const challengeBosses_1 = require("../objects/challengeBosses"); const challengeCharacters_1 = require("../objects/challengeCharacters"); const challengeCollectibleTypes_1 = require("../objects/challengeCollectibleTypes"); const challengeNames_1 = require("../objects/challengeNames"); const challengeTrinketType_1 = require("../objects/challengeTrinketType"); const log_1 = require("./log"); /** * Helper function to clear the current challenge, which will restart the run on a new random * non-challenge seed with the current character. * * If the player is not in a challenge already, this function will do nothing. * * Under the hood, this function executes the `challenge 0` console command. */ function clearChallenge() { if (onAnyChallenge()) { const command = `challenge ${isaac_typescript_definitions_1.Challenge.NULL}`; (0, log_1.log)(`Restarting the run to clear the current challenge with a console command of: ${command}`); Isaac.ExecuteCommand(command); } } /** * Get the final boss of a challenge. This will only work for vanilla challenges. * * For modded challenges, `BossID.MOM` (6) will be returned. * * Note that for `Challenge.BACKASSWARDS` (31), this function will return `BossID.MEGA_SATAN` (55), * but this is not actually the final boss. (There is no final boss for this challenge.) */ function getChallengeBoss(challenge) { const challengeBossID = challengeBosses_1.CHALLENGE_BOSSES[challenge]; // Handle modded challenges. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition return challengeBossID ?? challengeBosses_1.DEFAULT_CHALLENGE_BOSS_ID; } /** * Get the starting character of a challenge. This will only work for vanilla challenges. * * For modded challenges, `PlayerType.ISAAC` (0) will be returned. */ function getChallengeCharacter(challenge) { const challengeCharacter = challengeCharacters_1.CHALLENGE_CHARACTERS[challenge]; // Handle modded challenges. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition return challengeCharacter ?? challengeCharacters_1.DEFAULT_CHALLENGE_CHARACTER; } /** * Get the extra starting collectibles for a challenge. This will only work for vanilla challenges. * * For modded challenges, an empty array will be returned. */ function getChallengeCollectibleTypes(challenge) { return challengeCollectibleTypes_1.CHALLENGE_COLLECTIBLE_TYPES[challenge]; } /** * Get the proper name for a `Challenge` enum. This will only work for vanilla challenges. * * For modded challenges, "Unknown" will be returned. */ function getChallengeName(challenge) { const challengeName = challengeNames_1.CHALLENGE_NAMES[challenge]; // Handle modded challenges. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition return challengeName ?? challengeNames_1.DEFAULT_CHALLENGE_NAME; } /** * Get the extra starting trinket for a challenge. This will only work for vanilla challenges. * * If a challenge does not grant a starting trinket, `undefined` will be returned. * * For modded challenges, `undefined` will be returned. */ function getChallengeTrinketType(challenge) { return challengeTrinketType_1.CHALLENGE_TRINKET_TYPE[challenge]; } /** Helper function to see if the player is playing any challenge. */ function onAnyChallenge() { const challenge = Isaac.GetChallenge(); return challenge !== isaac_typescript_definitions_1.Challenge.NULL; } /** * Helper function to check to see if the player is playing a particular challenge. * * This function is variadic, meaning that you can specify as many challenges as you want to check * for. */ function onChallenge(...challenges) { const challenge = Isaac.GetChallenge(); return challenges.includes(challenge); } /** * Helper function to restart the run on a particular challenge. * * If the player is already in the particular challenge, this function will do nothing. * * Under the hood, this function executes the `challenge 0` console command. */ function setChallenge(challenge) { if (!onChallenge(challenge)) { const command = `challenge ${challenge}`; (0, log_1.log)(`Restarting the run to set a challenge with a console command of: ${command}`); Isaac.ExecuteCommand(command); } }