isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
51 lines (50 loc) • 2.06 kB
JavaScript
;
/**
* This is the type that is fed to the `PRE_ITEM_PICKUP` and `POST_ITEM_PICKUP` custom callbacks.
*
* @module
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.newPickingUpItem = newPickingUpItem;
exports.resetPickingUpItem = resetPickingUpItem;
exports.isPickingUpItemNull = isPickingUpItemNull;
exports.isPickingUpItemCollectible = isPickingUpItemCollectible;
exports.isPickingUpItemTrinket = isPickingUpItemTrinket;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const ReadonlySet_1 = require("./ReadonlySet");
const DEFAULT_ITEM_TYPE = isaac_typescript_definitions_1.ItemType.NULL;
const DEFAULT_SUB_TYPE = isaac_typescript_definitions_1.CollectibleType.NULL;
function newPickingUpItem() {
return {
itemType: DEFAULT_ITEM_TYPE,
subType: DEFAULT_SUB_TYPE,
};
}
/** Helper function to reset a `PickupUpItem` object to all 0 values. */
function resetPickingUpItem(pickingUpItem) {
pickingUpItem.itemType = DEFAULT_ITEM_TYPE;
pickingUpItem.subType = DEFAULT_SUB_TYPE;
}
const COLLECTIBLE_ITEM_TYPES = new ReadonlySet_1.ReadonlySet([
isaac_typescript_definitions_1.ItemType.PASSIVE, // 1
isaac_typescript_definitions_1.ItemType.ACTIVE, // 3
isaac_typescript_definitions_1.ItemType.FAMILIAR, // 4
]);
/** Helper function to narrow the type of `PickingUpItem` to `ItemType.NULL` (0). */
function isPickingUpItemNull(pickingUpItem) {
return pickingUpItem.itemType === isaac_typescript_definitions_1.ItemType.NULL;
}
/**
* Helper function to narrow the type of `PickingUpItem` to one of the following:
*
* - `ItemType.PASSIVE` (1)
* - `ItemType.ACTIVE` (3)
* - `ItemType.FAMILIAR` (4)
*/
function isPickingUpItemCollectible(pickingUpItem) {
return COLLECTIBLE_ITEM_TYPES.has(pickingUpItem.itemType);
}
/** Helper function to narrow the type of `PickingUpItem` to `ItemType.TRINKET` (2). */
function isPickingUpItemTrinket(pickingUpItem) {
return pickingUpItem.itemType === isaac_typescript_definitions_1.ItemType.TRINKET;
}