Sun_moves/library/imports/58/58403fe7-d7a2-426b-9b19-84d3236731a8.js

287 lines
9.5 KiB
JavaScript

"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.audioButtonClick = null;
//落地上
_this.audioWarning = null;
//碰撞
_this.audioWin = null;
//落方块上
_this.luodui = null;
return _this;
}
AudioManager_1 = AudioManager;
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;
var context = cc.audioEngine.play(audioSource, loop, volume);
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);
};
AudioManager.prototype.onLoad = function () {
if (AudioManager_1._instance == null) {
AudioManager_1._instance = this;
cc.game.addPersistRootNode(this.node);
}
else {
this.node.destroy();
return;
}
this.reward = false;
this.finish = false;
this.rewardCount = 0;
this.ctor();
this.preload();
};
AudioManager.prototype.preload = function () {
if (!(cc.sys.platform === cc.sys.WECHAT_GAME)) {
return;
}
var musics = [
this.audioGameBgm0,
];
musics.forEach(function (path) {
// var musicPath = wxDownloader.REMOTE_SERVER_ROOT + path;
// if (musicPath != wxDownloader.REMOTE_SERVER_ROOT && musicPath.endsWith('.mp3')) {
// cc.loader.load(musicPath, function(err, remoteUrl) {
// if (err) {
// cc.error(err.message || err);
// return;
// }
// });
// }
});
};
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();
// if (CC_JSB) {
// } else {
// for (var key in this.mAudioMap) {
// if (key === this.mMusicKey) {
// this.mAudioMap[key].pause();
// } else {
// this.mAudioMap[key].stop();
// }
// }
// }
};
AudioManager.prototype.onShow = function () {
cc.audioEngine.resumeAll();
// if (CC_JSB) {
// } else {
// if (!this.mMusicSwitch) return;
// var context = this.mAudioMap[this.mMusicKey];
// if (context) {
// context.play();
// }
// }
};
AudioManager.prototype.playMusic = function (key, callback, loop) {
loop = typeof loop == 'undefined' || loop ? true : false;
this.stopMusic();
this.mMusicKey = this.play(key, loop, callback, true);
};
/**
* 游戏背景音乐
*/
AudioManager.prototype.playMusicGame = function () {
this.playMusic(this.audioGameBgm0, {}, true);
};
/**
* 停止背景音乐播放
*/
AudioManager.prototype.stopMusic = function () {
// cc.wwx.OutPut.log('stopMusic audio effect wx: ' + this.mMusicKey);
var context = this.mAudioMap[this.mMusicKey];
if (typeof (context) != 'undefined') {
if (cc.sys.isBrowser) {
cc.audioEngine.stop(context);
}
else {
context.stop();
}
cc.audioEngine.stop(context);
}
};
// 炸弹、火箭爆炸音效
AudioManager.prototype.playJump = function () {
};
//激光音效
AudioManager.prototype.playLuo = function () {
return this.play(this.luodui, false, null, this.mEffectSwitch);
};
//技能音效
AudioManager.prototype.playGround = function () {
};
//技能音效
AudioManager.prototype.playPz = function () {
};
/*
* 游戏开始音效
*
*/
AudioManager.prototype.playGameStart = function () {
};
/*
* 失败的游戏结束
*/
AudioManager.prototype.playGameOver = function () {
};
/*
* 成功的游戏结束
*/
AudioManager.prototype.playGameResultFailed = function () {
};
/*
* 成功的游戏结束
*/
AudioManager.prototype.playGameResultSuccess = function () {
};
/**
* 报警的音效
*/
AudioManager.prototype.playWarning = function () {
return this.play(this.audioWarning, false, null, this.mEffectSwitch);
};
/*
* 方块碰撞的声音
*/
AudioManager.prototype.playBrick = function () {
// return this.play(this.brickSound,false);
};
//方块破碎的声音
AudioManager.prototype.brickBoom = function () {
};
/**
* 按钮
*/
AudioManager.prototype.playAudioButton = function () {
return this.play(this.audioButtonClick, false, null, this.mEffectSwitch);
};
AudioManager.prototype.playWin = function () {
return this.play(this.audioWin, false, null, this.mEffectSwitch);
};
AudioManager.prototype.playRandomMatch = function () {
this.playMusic(this.audioGameBgm0, {}, true);
};
AudioManager.prototype.playMatchFoundSound = function () {
this.stopMusic();
// return this.play(this.matchFoundSound, false);
};
var AudioManager_1;
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioGameBgm0", void 0);
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioButtonClick", void 0);
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioWarning", void 0);
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "audioWin", void 0);
__decorate([
property(cc.AudioClip)
], AudioManager.prototype, "luodui", void 0);
AudioManager = AudioManager_1 = __decorate([
ccclass
], AudioManager);
return AudioManager;
}(cc.Component));
exports.default = AudioManager;
;
// export { AudioManager };
cc._RF.pop();