"use strict";
cc._RF.push(module, '58403/n16JCa5sZhNMjZzGo', 'AudioManager');
// Script/module/Music/AudioManager.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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 });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var AudioManager = /** @class */ (function (_super) {
    __extends(AudioManager, _super);
    function AudioManager() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        //背景音乐
        _this.audioGameBgm0 = null;
        _this.xiaochu = null;
        _this.hit = null;
        _this.down = null;
        _this.fangxiang = null;
        _this.build = null;
        _this.win = null;
        _this.lose = null;
        _this.anniu_Big = null;
        _this.anniu_little = null;
        _this.zhuan1 = null;
        _this.zhuan2 = null;
        return _this;
    }
    AudioManager_1 = AudioManager;
    AudioManager.prototype.onLoad = function () {
        if (AudioManager_1._instance == null) {
            AudioManager_1._instance = this;
            cc.fx.AudioManager = AudioManager_1;
            cc.game.addPersistRootNode(this.node);
        }
        else {
            return;
        }
        this.reward = false;
        this.finish = false;
        this.rewardCount = 0;
        this.ctor();
        this.preload();
    };
    AudioManager.prototype.ctor = function () {
        this.mAudioMap = {};
        /**
         * 默认音量大小
         * @type {number}
         */
        this.bgMusicVolume = 0.1;
        this.effectMusicVolume = 1;
        this.mMusicSwitch = 1;
        this.mEffectSwitch = 1;
    };
    AudioManager.prototype.play = function (audioSource, loop, callback, isBgMusic) {
        // if (isBgMusic && !this.mMusicSwitch) return;
        // if (!isBgMusic && !this.mEffectSwitch) return;
        var volume = isBgMusic ? this.bgMusicVolume : this.effectMusicVolume;
        // if (cc.sys.isBrowser) {
        // if(audioSource == this.brickSound){
        //     volume = 0.1;
        // } 
        volume = 1;
        cc.audioEngine.setEffectsVolume(1);
        cc.audioEngine.setMusicVolume(1);
        if (audioSource.name == "lose") {
            cc.audioEngine.setEffectsVolume(0.5);
        }
        else {
            cc.audioEngine.setEffectsVolume(1);
        }
        var context = cc.audioEngine.playEffect(audioSource, loop);
        if (callback) {
            cc.audioEngine.setFinishCallback(context, function () {
                callback.call(this);
            }.bind(this));
        }
        // cc.wwx.OutPut.log('play audio effect isBrowser: ' + context.src);
        this.mAudioMap[audioSource] = context;
        return audioSource;
        // } else {
        //     return audioSource;
        // }
    };
    AudioManager.prototype.save = function () {
        // cc.wwx.Storage.setItem(cc.wwx.Storage.Key_Setting_Music_Volume, this.mMusicSwitch);
        // cc.wwx.Storage.setItem(cc.wwx.Storage.Key_Setting_Effect_Volume, this.mEffectSwitch);
    };
    // static get Instance()
    // {
    //     if (this._instance == null)
    //     {
    //         this._instance = new AudioManager();
    //     }
    //     return this._instance;
    // }
    AudioManager.prototype.preload = function () {
        if (!(cc.sys.platform === cc.sys.WECHAT_GAME)) {
            return;
        }
        var musics = [
            this.audioGameBgm0,
        ];
        musics.forEach(function (path) {
        });
        console.log("音乐开关", cc.fx.GameConfig.GM_INFO.musicOpen);
        this.playMusicGame();
    };
    AudioManager.prototype.getAudioMusicSwitch = function () {
        return this.mMusicSwitch;
    };
    AudioManager.prototype.getAudioEffectSwitch = function () {
        return this.mEffectSwitch;
    };
    AudioManager.prototype.trunAudioSound = function (on) {
        this.switchMusic(on);
        this.switchEffect(on);
    };
    AudioManager.prototype.switchMusic = function (on) {
        if (this.mMusicSwitch != (on ? 1 : 0)) {
            this.mMusicSwitch = 1 - this.mMusicSwitch;
            // this.save();
        }
        if (on) {
            this.playMusicGame();
        }
        else {
            this.stopMusic();
        }
    };
    AudioManager.prototype.switchEffect = function (on) {
        if (this.mEffectSwitch != (on ? 1 : 0)) {
            this.mEffectSwitch = 1 - this.mEffectSwitch;
            // this.save();
        }
    };
    AudioManager.prototype.onHide = function () {
        cc.audioEngine.pauseAll();
    };
    AudioManager.prototype.onShow = function () {
        cc.audioEngine.resumeAll();
    };
    //播放音效
    AudioManager.prototype.playEffect = function (name, callback) {
        if (!cc.fx.GameConfig.GM_INFO.effectOpen) {
            return;
        }
        if (this[name])
            return this.play(this[name], false, callback, this.mEffectSwitch);
    };
    AudioManager.prototype.playMusic = function (key, callback, loop) {
        if (!cc.fx.GameConfig.GM_INFO.musicOpen) {
            return;
        }
        loop = typeof loop == 'undefined' || loop ? true : false;
        this.stopMusic();
        this.mMusicKey = this.play(key, loop, callback, true);
    };
    /**
     * 游戏背景音乐
     */
    AudioManager.prototype.playMusicGame = function () {
        this.stopMusic();
        this.playMusic(this.audioGameBgm0, {}, true);
    };
    /**
     * 停止背景音乐播放
     */
    AudioManager.prototype.stopMusic = function () {
        // cc.wwx.OutPut.log('stopMusic audio effect wx: ' + this.mMusicKey);
        cc.audioEngine.stopAll();
    };
    /**
     * 恢复被暂停的背景音乐播放
     */
    AudioManager.prototype.resumeMusic = function () {
        // 调用 cc.audioEngine 的 resumeMusic 方法恢复音乐播放
        cc.audioEngine.resumeMusic();
    };
    /*
    * 游戏开始音效
    *
    */
    AudioManager.prototype.playGameStart = function () {
    };
    /*
    * 失败的游戏结束
    */
    AudioManager.prototype.playGameOver = function () {
    };
    /*
        * 成功的游戏结束
        */
    AudioManager.prototype.playGameResultFailed = function () {
    };
    /*
    * 成功的游戏结束
    */
    AudioManager.prototype.playGameResultSuccess = function () {
    };
    /**
     * 报警的音效
     */
    /**
     * 按钮
     */
    AudioManager.prototype.playAudioButton = function () {
        // return this.play(this.audioButtonClick, false,null,this.mEffectSwitch);
    };
    var AudioManager_1;
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "audioGameBgm0", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "xiaochu", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "hit", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "down", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "fangxiang", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "build", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "win", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "lose", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "anniu_Big", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "anniu_little", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "zhuan1", void 0);
    __decorate([
        property(cc.AudioClip)
    ], AudioManager.prototype, "zhuan2", void 0);
    AudioManager = AudioManager_1 = __decorate([
        ccclass
    ], AudioManager);
    return AudioManager;
}(cc.Component));
exports.default = AudioManager;
;
// export { AudioManager };

cc._RF.pop();