isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
102 lines • 3.84 kB
TypeScript
import type { DefaultMap } from "../classes/DefaultMap";
/**
* 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:
*
* ```ts
* 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.)
*/
export declare function defaultMapGetNPC<V, Args extends unknown[]>(map: DefaultMap<PtrHash, V, Args>, npc: EntityNPC, ...extraArgs: Args): V;
/**
* 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.
*/
export declare function defaultMapSetNPC<V>(map: Map<PtrHash, V>, npc: EntityNPC, value: V): void;
/**
* 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.
*/
export declare function mapDeleteNPC(map: Map<PtrHash, unknown>, npc: EntityNPC): boolean;
/**
* 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:
*
* ```ts
* 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);
* }
* ```
*/
export declare function mapGetNPC<V>(map: ReadonlyMap<PtrHash, V>, npc: EntityNPC): V | undefined;
/**
* 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.
*/
export declare function mapHasNPC<V>(map: ReadonlyMap<PtrHash, V>, npc: EntityNPC): boolean;
/**
* 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:
*
* ```ts
* 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);
* }
* ```
*/
export declare function mapSetNPC<V>(map: Map<PtrHash, V>, npc: EntityNPC, value: V): 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.
*/
export declare function setAddNPC(set: Set<PtrHash>, npc: EntityNPC): void;
/**
* 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.
*/
export declare function setDeleteNPC(set: Set<PtrHash>, npc: EntityNPC): 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.
*/
export declare function setHasNPC(set: ReadonlySet<PtrHash>, npc: EntityNPC): boolean;
//# sourceMappingURL=npcDataStructures.d.ts.map