"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setHasPlayer = exports.setDeletePlayer = exports.setAddPlayer = exports.mapSetPlayer = exports.mapHasPlayer = exports.mapGetPlayer = exports.mapDeletePlayer = exports.defaultMapSetPlayer = exports.defaultMapGetPlayer = void 0;
const playerIndex_1 = require("./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
 */
function defaultMapGetPlayer(map, player, ...extraArgs) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    return map.getAndSetDefault(playerIndex, ...extraArgs);
}
exports.defaultMapGetPlayer = defaultMapGetPlayer;
/**
 * 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.
 */
function defaultMapSetPlayer(
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
map, player, value) {
    mapSetPlayer(map, player, value);
}
exports.defaultMapSetPlayer = defaultMapSetPlayer;
/**
 * 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.
 */
function mapDeletePlayer(
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
map, player) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    return map.delete(playerIndex);
}
exports.mapDeletePlayer = mapDeletePlayer;
/**
 * 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);
 * }
 * ```
 */
function mapGetPlayer(map, player) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    return map.get(playerIndex);
}
exports.mapGetPlayer = mapGetPlayer;
/**
 * 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.
 */
function mapHasPlayer(map, player) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    return map.has(playerIndex);
}
exports.mapHasPlayer = mapHasPlayer;
/**
 * 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);
 * }
 * ```
 */
function mapSetPlayer(
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
map, player, value) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    map.set(playerIndex, value);
}
exports.mapSetPlayer = mapSetPlayer;
/**
 * 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.
 */
function setAddPlayer(
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
set, player) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    set.add(playerIndex);
}
exports.setAddPlayer = setAddPlayer;
/**
 * 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.
 */
function setDeletePlayer(
// eslint-disable-next-line isaacscript/prefer-readonly-parameter-types
set, player) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    return set.delete(playerIndex);
}
exports.setDeletePlayer = setDeletePlayer;
/**
 * 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.
 */
function setHasPlayer(set, player) {
    const playerIndex = (0, playerIndex_1.getPlayerIndex)(player);
    return set.has(playerIndex);
}
exports.setHasPlayer = setHasPlayer;
