Flag
Functions
Section titled “Functions”addFlag()
Section titled “addFlag()”addFlag<
T>(flags, …flagsToAdd):BitFlags<T>
Defined in: packages/isaacscript-common/src/functions/flag.ts:29
Helper function to add a bit flag to an existing set of bit flags.
This is a variadic function, so pass as many flags as you want to add.
Example 1:
// Give the player spectral tearsconst player = Isaac.GetPlayer();player.TearFlags = addFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL);Example 2:
// Give the player spectral and homing tearsconst player = Isaac.GetPlayer();player.TearFlags = addFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL, TearFlags.TEAR_HOMING);Type Parameters
Section titled “Type Parameters”T extends BitFlag | BitFlag128
Parameters
Section titled “Parameters”T | BitFlags<T>
The existing set of bit flags.
flagsToAdd
Section titled “flagsToAdd”…readonly T[]
One or more bit flags to add, each as a separate argument.
Returns
Section titled “Returns”BitFlags<T>
The combined bit flags.
bitFlags()
Section titled “bitFlags()”bitFlags<
T>(flag):BitFlags<T>
Defined in: packages/isaacscript-common/src/functions/flag.ts:55
Helper function for casting a flag enum value to a BitFlags object.
This is useful because the compiler will prevent you from assigning a specific flag to a
BitFlags field. (It does this to ensure type safety, since BitFlags can represent a zero
value or a composition of N flags.)
For example:
player.TearFlags = bitFlags(TearFlag.SPECTRAL);Type Parameters
Section titled “Type Parameters”T extends BitFlag | BitFlag128
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”BitFlags<T>
getFlagName()
Section titled “getFlagName()”getFlagName<
T>(flag,flagEnum):string|undefined
Defined in: packages/isaacscript-common/src/functions/flag.ts:66
Helper function to get the key associated with a particular flag.
(Since bit flags are represented by custom objects instead of normal TypeScript enums, you cannot use the reverse mapping to find the associated key of a given enum value. Use this helper function instead of indexing the enum directly.)
Type Parameters
Section titled “Type Parameters”T extends BitFlag | BitFlag128
Parameters
Section titled “Parameters”BitFlag
flagEnum
Section titled “flagEnum”ReadonlyRecord<string, T>
Returns
Section titled “Returns”string | undefined
hasFlag()
Section titled “hasFlag()”hasFlag<
T>(flags, …flagsToCheck):boolean
Defined in: packages/isaacscript-common/src/functions/flag.ts:97
Helper function to determine if a particular bit flag is set to true.
This is a variadic function, so pass as many flags as you want to check for. If passed multiple flags, it will only return true if all of the flags are set.
For example:
const player = Isaac.GetPlayer();if (hasFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL) { // The player currently has spectral tears}Type Parameters
Section titled “Type Parameters”T extends BitFlag | BitFlag128
Parameters
Section titled “Parameters”T | BitFlags<T>
The existing set of bit flags.
flagsToCheck
Section titled “flagsToCheck”…readonly T[]
One or more bit flags to check for, each as a separate argument.
Returns
Section titled “Returns”boolean
isEmptyFlag()
Section titled “isEmptyFlag()”isEmptyFlag(
flag):boolean
Defined in: packages/isaacscript-common/src/functions/flag.ts:118
Helper function to check if every bit in the flag is turned off.
(This is equivalent to checking if the flag is equal to 0, but this is not possible without casting the flag to a number.)
Parameters
Section titled “Parameters”BitFlag | BitFlag128
Returns
Section titled “Returns”boolean
isSelfDamage()
Section titled “isSelfDamage()”isSelfDamage(
damageFlags):boolean
Defined in: packages/isaacscript-common/src/functions/flag.ts:127
Helper function to determine whether damage to a player in the ENTITY_TAKE_DMG callback was
self-inflicted. For example, damage from a Curse Room door, a Razor, or a Blood Donation Machine
would count as self-inflicted damage.
Parameters
Section titled “Parameters”damageFlags
Section titled “damageFlags”DamageFlagValue | BitFlags<DamageFlagValue>
Returns
Section titled “Returns”boolean
removeFlag()
Section titled “removeFlag()”removeFlag<
T>(flags, …flagsToRemove):BitFlags<T>
Defined in: packages/isaacscript-common/src/functions/flag.ts:155
Helper function to remove a bit flag from an existing set of bit flags.
This is a variadic function, so pass as many flags as you want to remove.
For example:
// Remove spectral tears from the player, if presentconst player = Isaac.GetPlayer();player.TearFlags = removeFlag(player.TearFlags, TearFlags.TEAR_SPECTRAL);Type Parameters
Section titled “Type Parameters”T extends BitFlag | BitFlag128
Parameters
Section titled “Parameters”T | BitFlags<T>
The existing set of bit flags.
flagsToRemove
Section titled “flagsToRemove”…readonly T[]
One or more bit flags to remove, each as a separate argument.
Returns
Section titled “Returns”BitFlags<T>
The combined bit flags.
