isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
91 lines (90 loc) • 3.91 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.DisableAllSound = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const cachedClasses_1 = require("../../../core/cachedClasses");
const decorators_1 = require("../../../decorators");
const sound_1 = require("../../../functions/sound");
const Feature_1 = require("../../private/Feature");
const v = {
run: {
disableSoundSet: new Set(),
},
};
class DisableAllSound extends Feature_1.Feature {
/** @internal */
v = v;
musicWasEnabled = false;
/** @internal */
constructor() {
super();
this.callbacksUsed = [
// 2
[isaac_typescript_definitions_1.ModCallback.POST_RENDER, this.postRender],
];
}
// ModCallback.POST_RENDER (2)
postRender = () => {
if (v.run.disableSoundSet.size === 0) {
return;
}
(0, sound_1.stopAllSoundEffects)();
};
/**
* Helper function to stop muting all sound effects and music.
*
* Use this function to set things back to normal after having used `disableAllSounds`.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.DISABLE_ALL_SOUND`.
*
* @param key The name of the mod feature that is requesting the enable/disable. For example, if
* this was part of the code for a custom enemy called "Super Gaper", then you could
* use a key of "SuperGaper". The name is necessary so that multiple mod features can
* work in tandem.
*/
enableAllSound(key) {
if (!v.run.disableSoundSet.has(key)) {
return;
}
v.run.disableSoundSet.delete(key);
if (v.run.disableSoundSet.size === 0 && this.musicWasEnabled) {
cachedClasses_1.musicManager.Enable();
}
// Stop all sound effects that were initialized prior to enabling sounds (in case there was a
// sound played played previously on this render frame).
(0, sound_1.stopAllSoundEffects)();
}
/**
* Helper function to disable all sound effects and music (by constantly musting them).
*
* Use the `enableAllSounds` helper function to set things back to normal.
*
* In order to use this function, you must upgrade your mod with `ISCFeature.DISABLE_ALL_SOUND`.
*
* @param key The name of the mod feature that is requesting the enable/disable. For example, if
* this was part of the code for a custom enemy called "Super Gaper", then you could
* use a key of "SuperGaper". The name is necessary so that multiple mod features can
* work in tandem.
*/
disableAllSound(key) {
if (v.run.disableSoundSet.size === 0) {
this.musicWasEnabled = cachedClasses_1.musicManager.IsEnabled();
}
v.run.disableSoundSet.add(key);
// Stop all sound effects that were initialized prior to disabling sounds.
(0, sound_1.stopAllSoundEffects)();
}
}
exports.DisableAllSound = DisableAllSound;
__decorate([
decorators_1.Exported
], DisableAllSound.prototype, "enableAllSound", null);
__decorate([
decorators_1.Exported
], DisableAllSound.prototype, "disableAllSound", null);