Skip to main content

Npc Data Structures

Functions

defaultMapGetNPC

defaultMapGetNPC<V, Args>(map, npc, ...extraArgs): V

Helper function to make using default maps with an index of PtrHash easier. Use this instead of the DefaultMap.getAndSetDefault method if you have a default map of this type.

For example:

const v = {
run: {
npcsSpeedBoost: new DefaultMap<PtrHash, int>(0),
},
};

function npcUpdate(npc: EntityNPC) {
const speedBoost = defaultMapGetNPC(v.run.npcsSpeedBoost, npc);
// Do something with the speed boost.
}

Note that not all NPCs should be stored in a map with a PtrHash as an index, so only use this in the situations where that would be okay. (For example, Dark Esau should never be stored in a map like this, because the scope of PtrHash is per room and Dark Esau is persistent between rooms.)

Type parameters

NameType
VV
Argsextends unknown[]

Parameters

NameType
mapDefaultMap<PtrHash, V, Args>
npcEntityNPC
...extraArgsArgs

Returns

V

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:27


defaultMapSetNPC

defaultMapSetNPC<V>(map, npc, value): void

Helper function to make using maps with an index of PtrHash easier. Use this instead of the Map.set method if you have a map of this type.

Since Map and DefaultMap set values in the same way, this function is simply an alias for the mapSetNPC helper function.

Type parameters

Name
V

Parameters

NameType
mapMap<PtrHash, V>
npcEntityNPC
valueV

Returns

void

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:43


mapDeleteNPC

mapDeleteNPC(map, npc): boolean

Helper function to make using maps with an type of PtrHash easier. Use this instead of the Map.delete method if you have a set of this type.

Parameters

NameType
mapMap<PtrHash, unknown>
npcEntityNPC

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:56


mapGetNPC

mapGetNPC<V>(map, npc): V | undefined

Helper function to make using maps with an index of PtrHash easier. Use this instead of the Map.get method if you have a map of this type.

For example:

const v = {
run: {
npcsSpeedBoost: new Map<PtrHash, int>(),
},
};

function incrementSpeedBoost(npc: EntityNPC) {
const oldSpeedBoost = mapGetNPC(v.run.npcsSpeedBoost, npc);
const newSpeedBoost = oldSpeedBoost + 0.1;
mapSetNPC(v.run.npcsSpeedBoost, npc);
}

Type parameters

Name
V

Parameters

NameType
mapReadonlyMap<PtrHash, V>
npcEntityNPC

Returns

V | undefined

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:85


mapHasNPC

mapHasNPC<V>(map, npc): boolean

Helper function to make using maps with an index of PtrHash easier. Use this instead of the Map.has method if you have a map of this type.

Type parameters

Name
V

Parameters

NameType
mapReadonlyMap<PtrHash, V>
npcEntityNPC

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:97


mapSetNPC

mapSetNPC<V>(map, npc, value): void

Helper function to make using maps with an index of PtrHash easier. Use this instead of the Map.set method if you have a map of this type.

For example:

const v = {
run: {
npcsSpeedBoost: new Map<PtrHash, int>(),
},
};

function incrementSpeedBoost(npc: EntityNPC) {
const oldSpeedBoost = mapGetNPC(v.run.npcsSpeedBoost, npc);
const newSpeedBoost = oldSpeedBoost + 0.1;
mapSetNPC(v.run.npcsSpeedBoost, npc);
}

Type parameters

Name
V

Parameters

NameType
mapMap<PtrHash, V>
npcEntityNPC
valueV

Returns

void

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:125


setAddNPC

setAddNPC(set, npc): void

Helper function to make using sets with an type of PtrHash easier. Use this instead of the Set.add method if you have a set of this type.

Parameters

NameType
setSet<PtrHash>
npcEntityNPC

Returns

void

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:140


setDeleteNPC

setDeleteNPC(set, npc): boolean

Helper function to make using sets with an type of PtrHash easier. Use this instead of the Set.delete method if you have a set of this type.

Parameters

NameType
setSet<PtrHash>
npcEntityNPC

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:150


setHasNPC

setHasNPC(set, npc): boolean

Helper function to make using sets with an type of PtrHash easier. Use this instead of the Set.has method if you have a set of this type.

Parameters

NameType
setReadonlySet<PtrHash>
npcEntityNPC

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/npcDataStructures.ts:159