isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
76 lines (75 loc) • 3.56 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollectibleItemPoolType = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedClasses_1 = require("../../../core/cachedClasses");
const decorators_1 = require("../../../decorators");
const ISCFeature_1 = require("../../../enums/ISCFeature");
const entities_1 = require("../../../functions/entities");
const pickupVariants_1 = require("../../../functions/pickupVariants");
const rooms_1 = require("../../../functions/rooms");
const Feature_1 = require("../../private/Feature");
const v = {
run: {
collectibleItemPoolTypeMap: new Map(),
},
};
class CollectibleItemPoolType extends Feature_1.Feature {
/** @internal */
v = v;
pickupIndexCreation;
/** @internal */
constructor(pickupIndexCreation) {
super();
this.featuresUsed = [ISCFeature_1.ISCFeature.PICKUP_INDEX_CREATION];
this.callbacksUsed = [
// 34
[
isaac_typescript_definitions_1.ModCallback.POST_PICKUP_INIT,
this.postPickupInitCollectible,
[isaac_typescript_definitions_1.PickupVariant.COLLECTIBLE],
],
];
this.pickupIndexCreation = pickupIndexCreation;
}
// ModCallback.POST_PICKUP_INIT (34)
// PickupVariant.COLLECTIBLE (100)
postPickupInitCollectible = (collectible) => {
const pickupIndex = this.pickupIndexCreation.getPickupIndex(collectible);
if (!v.run.collectibleItemPoolTypeMap.has(pickupIndex)) {
const itemPool = cachedClasses_1.game.GetItemPool();
const lastItemPoolType = itemPool.GetLastPool();
v.run.collectibleItemPoolTypeMap.set(pickupIndex, lastItemPoolType);
}
};
/**
* Helper function to get the item pool type that a given collectible came from. Since there is no
* native method in the API to get this, we listen in the `POST_PICKUP_INIT` callback for
* collectibles, use the `ItemPool.GetLastPool` method, and then assume that the collectible
* matches.
*
* In order to use this function, you must upgrade your mod with
* `ISCFeature.COLLECTIBLE_ITEM_POOL_TYPE`.
*
* @public
*/
getCollectibleItemPoolType(collectible) {
if (!(0, pickupVariants_1.isCollectible)(collectible)) {
const entityID = (0, entities_1.getEntityID)(collectible);
error(`The "getCollectibleItemPoolType" function was given a non-collectible: ${entityID}`);
}
const pickupIndex = this.pickupIndexCreation.getPickupIndex(collectible);
const itemPoolType = v.run.collectibleItemPoolTypeMap.get(pickupIndex);
return itemPoolType ?? (0, rooms_1.getRoomItemPoolType)();
}
}
exports.CollectibleItemPoolType = CollectibleItemPoolType;
__decorate([
decorators_1.Exported
], CollectibleItemPoolType.prototype, "getCollectibleItemPoolType", null);