UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

89 lines (88 loc) 4.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPlayerTransformations = getPlayerTransformations; exports.getTransformationName = getTransformationName; exports.getTransformationsForCollectibleType = getTransformationsForCollectibleType; exports.hasFlyingTransformation = hasFlyingTransformation; exports.isTransformationFlying = isTransformationFlying; const isaac_typescript_definitions_1 = require("isaac-typescript-definitions"); const cachedEnumValues_1 = require("../cachedEnumValues"); const transformationNames_1 = require("../objects/transformationNames"); const ReadonlyMap_1 = require("../types/ReadonlyMap"); const ReadonlySet_1 = require("../types/ReadonlySet"); const collectibles_1 = require("./collectibles"); const flag_1 = require("./flag"); const TRANSFORMATION_TO_TAG_MAP = new ReadonlyMap_1.ReadonlyMap([ [isaac_typescript_definitions_1.PlayerForm.GUPPY, isaac_typescript_definitions_1.ItemConfigTag.GUPPY], // 0 [isaac_typescript_definitions_1.PlayerForm.BEELZEBUB, isaac_typescript_definitions_1.ItemConfigTag.FLY], // 1 [isaac_typescript_definitions_1.PlayerForm.FUN_GUY, isaac_typescript_definitions_1.ItemConfigTag.MUSHROOM], // 2 [isaac_typescript_definitions_1.PlayerForm.SERAPHIM, isaac_typescript_definitions_1.ItemConfigTag.ANGEL], // 3 [isaac_typescript_definitions_1.PlayerForm.BOB, isaac_typescript_definitions_1.ItemConfigTag.BOB], // 4 [isaac_typescript_definitions_1.PlayerForm.SPUN, isaac_typescript_definitions_1.ItemConfigTag.SYRINGE], // 5 [isaac_typescript_definitions_1.PlayerForm.YES_MOTHER, isaac_typescript_definitions_1.ItemConfigTag.MOM], // 6 [isaac_typescript_definitions_1.PlayerForm.CONJOINED, isaac_typescript_definitions_1.ItemConfigTag.BABY], // 7 [isaac_typescript_definitions_1.PlayerForm.LEVIATHAN, isaac_typescript_definitions_1.ItemConfigTag.DEVIL], // 8 [isaac_typescript_definitions_1.PlayerForm.OH_CRAP, isaac_typescript_definitions_1.ItemConfigTag.POOP], // 9 [isaac_typescript_definitions_1.PlayerForm.BOOKWORM, isaac_typescript_definitions_1.ItemConfigTag.BOOK], // 10 // PlayerForm.ADULTHOOD (11) is based on pill usage. [isaac_typescript_definitions_1.PlayerForm.SPIDER_BABY, isaac_typescript_definitions_1.ItemConfigTag.SPIDER], // 12 // PlayerForm.STOMPY (13) is based on size. ]); const TRANSFORMATIONS_THAT_GRANT_FLYING = new ReadonlySet_1.ReadonlySet([ isaac_typescript_definitions_1.PlayerForm.GUPPY, // 0 isaac_typescript_definitions_1.PlayerForm.BEELZEBUB, // 1 isaac_typescript_definitions_1.PlayerForm.SERAPHIM, // 3 isaac_typescript_definitions_1.PlayerForm.LEVIATHAN, // 8 ]); /** Returns a set of the player's current transformations. */ function getPlayerTransformations(player) { const transformations = new Set(); for (const playerForm of cachedEnumValues_1.PLAYER_FORM_VALUES) { if (player.HasPlayerForm(playerForm)) { transformations.add(playerForm); } } return transformations; } /** * Helper function to get a transformation name from a PlayerForm enum. * * For example: * * ```ts * const transformationName = getTransformationName(PlayerForm.LORD_OF_THE_FLIES); * // transformationName is "Beelzebub" * ``` */ function getTransformationName(playerForm) { return transformationNames_1.TRANSFORMATION_NAMES[playerForm]; } /** * Returns a set containing all of the transformations that the given collectible types contribute * towards. */ function getTransformationsForCollectibleType(collectibleType) { const itemConfigTags = (0, collectibles_1.getCollectibleTags)(collectibleType); const transformationSet = new Set(); for (const playerForm of cachedEnumValues_1.PLAYER_FORM_VALUES) { const itemConfigTag = TRANSFORMATION_TO_TAG_MAP.get(playerForm); if (itemConfigTag === undefined) { continue; } if ((0, flag_1.hasFlag)(itemConfigTags, itemConfigTag)) { transformationSet.add(playerForm); } } return transformationSet; } function hasFlyingTransformation(player) { for (const playerForm of TRANSFORMATIONS_THAT_GRANT_FLYING) { if (player.HasPlayerForm(playerForm)) { return true; } } return false; } function isTransformationFlying(playerForm) { return TRANSFORMATIONS_THAT_GRANT_FLYING.has(playerForm); }