isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
61 lines (60 loc) • 2.72 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.UnlockAchievementsDetection = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const constants_1 = require("../../../core/constants");
const decorators_1 = require("../../../decorators");
const ModCallbackCustom_1 = require("../../../enums/ModCallbackCustom");
const entitiesSpecific_1 = require("../../../functions/entitiesSpecific");
const Feature_1 = require("../../private/Feature");
const v = {
run: {
canRunUnlockAchievements: true,
},
};
class UnlockAchievementsDetection extends Feature_1.Feature {
/** @internal */
v = v;
/** @internal */
constructor() {
super();
this.customCallbacksUsed = [
[
ModCallbackCustom_1.ModCallbackCustom.POST_GAME_STARTED_REORDERED,
this.postGameStartedReordered,
],
];
}
// ModCallbackCustom.POST_GAME_STARTED_REORDERED
postGameStartedReordered = () => {
const greedDonationMachine = (0, entitiesSpecific_1.spawnSlot)(isaac_typescript_definitions_1.SlotVariant.GREED_DONATION_MACHINE, 0, constants_1.VectorZero);
v.run.canRunUnlockAchievements = greedDonationMachine.Exists();
greedDonationMachine.Remove();
};
/**
* Helper function to see if the current run can unlock achievements. For example, if playing on a
* set seed or in a victory lap, achievements are disabled.
*
* Under the hood, this is determined by spawning a Greed Donation Machine at the beginning of the
* run and then seeing if it exists before removing it. (The results are cached for the entire
* run.)
*
* In order to use this function, you must upgrade your mod with
* `ISCFeature.UNLOCK_ACHIEVEMENTS_DETECTION`.
*
* @public
*/
canRunUnlockAchievements() {
return v.run.canRunUnlockAchievements;
}
}
exports.UnlockAchievementsDetection = UnlockAchievementsDetection;
__decorate([
decorators_1.Exported
], UnlockAchievementsDetection.prototype, "canRunUnlockAchievements", null);