UNPKG

isaacscript-common

Version:

Helper functions and features for IsaacScript mods.

99 lines 3.82 kB
import type { DefaultMap } from "../classes/DefaultMap"; import type { PlayerIndex } from "../types/PlayerIndex"; /** * Helper function to make using default maps with an index of `PlayerIndex` easier. Use this * instead of the `DefaultMap.getAndSetDefault` method if you have a default map of this type. * * For example: * * ```ts * const v = { * run: { * playersSpeedBoost: new DefaultMap<PlayerIndex, int>(0), * }, * }; * * function evaluateCacheSpeed(player: EntityPlayer) { * player.MoveSpeed = defaultMapGetPlayer(v.run.playersSpeedBoost, player); * } * ``` * * @allowEmptyVariadic */ export declare function defaultMapGetPlayer<V, Args extends unknown[]>(map: DefaultMap<PlayerIndex, V, Args>, player: EntityPlayer, ...extraArgs: Args): V; /** * Helper function to make using maps with an index of `PlayerIndex` 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 * `mapSetPlayer` helper function. */ export declare function defaultMapSetPlayer<V>(map: Map<PlayerIndex, V>, player: EntityPlayer, value: V): void; /** * Helper function to make using maps with an type of `PlayerIndex` easier. Use this instead of the * `Map.delete` method if you have a set of this type. */ export declare function mapDeletePlayer(map: Map<PlayerIndex, unknown>, player: EntityPlayer): boolean; /** * Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the * `Map.get` method if you have a map of this type. * * For example: * * ```ts * const v = { * run: { * playersSpeedBoost: new Map<PlayerIndex, int>(), * }, * }; * * function incrementSpeedBoost(player: EntityPlayer) { * const oldSpeedBoost = mapGetPlayer(v.run.playersSpeedBoost, player); * const newSpeedBoost = oldSpeedBoost + 0.1; * mapSetPlayer(v.run.playersSpeedBoost, player); * } * ``` */ export declare function mapGetPlayer<V>(map: ReadonlyMap<PlayerIndex, V>, player: EntityPlayer): V | undefined; /** * Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the * `Map.has` method if you have a map of this type. */ export declare function mapHasPlayer<V>(map: ReadonlyMap<PlayerIndex, V>, player: EntityPlayer): boolean; /** * Helper function to make using maps with an index of `PlayerIndex` easier. Use this instead of the * `Map.set` method if you have a map of this type. * * For example: * * ```ts * const v = { * run: { * playersSpeedBoost: new Map<PlayerIndex, int>(), * }, * }; * * function incrementSpeedBoost(player: EntityPlayer) { * const oldSpeedBoost = mapGetPlayer(v.run.playersSpeedBoost, player); * const newSpeedBoost = oldSpeedBoost + 0.1; * mapSetPlayer(v.run.playersSpeedBoost, player); * } * ``` */ export declare function mapSetPlayer<V>(map: Map<PlayerIndex, V>, player: EntityPlayer, value: V): void; /** * Helper function to make using sets with an type of `PlayerIndex` easier. Use this instead of the * `Set.add` method if you have a set of this type. */ export declare function setAddPlayer(set: Set<PlayerIndex>, player: EntityPlayer): void; /** * Helper function to make using sets with an type of `PlayerIndex` easier. Use this instead of the * `Set.delete` method if you have a set of this type. */ export declare function setDeletePlayer(set: Set<PlayerIndex>, player: EntityPlayer): boolean; /** * Helper function to make using sets with an type of `PlayerIndex` easier. Use this instead of the * `Set.has` method if you have a set of this type. */ export declare function setHasPlayer(set: ReadonlySet<PlayerIndex>, player: EntityPlayer): boolean; //# sourceMappingURL=playerDataStructures.d.ts.map