mute audio

beta.r3js.org
-=yb4f310 2017-11-22 16:10:58 +01:00
parent 61400ed6c2
commit 9ee97f187a
5 changed files with 97 additions and 13 deletions

24
build/game-lib-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
// COMPILE TIME DEFINITIONS (Generated via gulp) // COMPILE TIME DEFINITIONS (Generated via gulp)
var __DATE__ = "Tue Nov 21 2017 15:24:50 GMT+0100 (CET)"; var __DATE__ = "Wed Nov 22 2017 16:08:49 GMT+0100 (CET)";
// END COMPILE TIME DEFINITIONS // END COMPILE TIME DEFINITIONS
/** /**
@ -179,6 +179,7 @@ GameLib.Event.PARTICLE_INSTANCE_UPDATED = 0x61;
GameLib.Event.GAME_DATA = 0x62; GameLib.Event.GAME_DATA = 0x62;
GameLib.Event.PAUSE_ALL_AUDIO = 0x63; GameLib.Event.PAUSE_ALL_AUDIO = 0x63;
GameLib.Event.CONTINUE_ALL_AUDIO = 0x64; GameLib.Event.CONTINUE_ALL_AUDIO = 0x64;
GameLib.Event.MUTE_AUDIO = 0x65;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -289,6 +290,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x62 : return 'game_data'; case 0x62 : return 'game_data';
case 0x63 : return 'pause_all_audio'; case 0x63 : return 'pause_all_audio';
case 0x64 : return 'continue_all_audio'; case 0x64 : return 'continue_all_audio';
case 0x65 : return 'mute_audio';
break; break;
} }
@ -9685,6 +9687,8 @@ GameLib.D3.Camera.prototype.updateInstance = function(property) {
property === 'aspect' || property === 'aspect' ||
property === 'minX' || property === 'minX' ||
property === 'maxX' || property === 'maxX' ||
property === 'minY' ||
property === 'maxY' ||
property === 'minZ' || property === 'minZ' ||
property === 'maxZ' || property === 'maxZ' ||
property === 'offsetX' || property === 'offsetX' ||
@ -25550,6 +25554,8 @@ GameLib.System.Audio = function(
this.pauseAllAudioSubscription = null; this.pauseAllAudioSubscription = null;
this.muteAudioSubscription = null;
this.continueAllAudioSubscription = null; this.continueAllAudioSubscription = null;
this.stopAudioSubscription = null; this.stopAudioSubscription = null;
@ -25595,6 +25601,10 @@ GameLib.System.Audio.prototype.start = function() {
this.pauseAllAudio.bind(this) this.pauseAllAudio.bind(this)
); );
this.muteAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.MUTE_AUDIO,
this.muteAudio.bind(this)
);
this.continueAllAudioSubscription = GameLib.Event.Subscribe( this.continueAllAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.CONTINUE_ALL_AUDIO, GameLib.Event.CONTINUE_ALL_AUDIO,
@ -25737,6 +25747,37 @@ GameLib.System.Audio.prototype.removeComponent = function(data) {
}; };
GameLib.System.Audio.prototype.muteAudio = function() {
this.mute = !this.mute;
if (this.mute) {
this.audioVolumes = this.audioComponents.reduce(
function(result, audio) {
result.push(
{
audio : audio,
volume : audio.volume
}
);
audio.volume = 0;
audio.updateInstance('volume');
return result;
},
[]
)
} else {
this.audioVolumes.map(
function(audioVolume) {
audioVolume.audio.volume = audioVolume.volume;
audioVolume.audio.updateInstance('volume');
}
)
}
};
/** /**
* Stop this system (remove all event listeners) * Stop this system (remove all event listeners)
@ -25749,6 +25790,7 @@ GameLib.System.Audio.prototype.stop = function() {
this.removeComponentSubscription.remove(); this.removeComponentSubscription.remove();
this.playAudioSubscription.remove(); this.playAudioSubscription.remove();
this.pauseAllAudioSubscription.remove(); this.pauseAllAudioSubscription.remove();
this.muteAudioSubscription.remove();
this.continueAllAudioSubscription.remove(); this.continueAllAudioSubscription.remove();
this.stopAudioSubscription.remove(); this.stopAudioSubscription.remove();
this.stopAllAudioSubscription.remove(); this.stopAllAudioSubscription.remove();

View File

@ -115,6 +115,7 @@ GameLib.Event.PARTICLE_INSTANCE_UPDATED = 0x61;
GameLib.Event.GAME_DATA = 0x62; GameLib.Event.GAME_DATA = 0x62;
GameLib.Event.PAUSE_ALL_AUDIO = 0x63; GameLib.Event.PAUSE_ALL_AUDIO = 0x63;
GameLib.Event.CONTINUE_ALL_AUDIO = 0x64; GameLib.Event.CONTINUE_ALL_AUDIO = 0x64;
GameLib.Event.MUTE_AUDIO = 0x65;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -225,6 +226,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x62 : return 'game_data'; case 0x62 : return 'game_data';
case 0x63 : return 'pause_all_audio'; case 0x63 : return 'pause_all_audio';
case 0x64 : return 'continue_all_audio'; case 0x64 : return 'continue_all_audio';
case 0x65 : return 'mute_audio';
break; break;
} }

View File

@ -165,6 +165,8 @@ GameLib.D3.Camera.prototype.updateInstance = function(property) {
property === 'aspect' || property === 'aspect' ||
property === 'minX' || property === 'minX' ||
property === 'maxX' || property === 'maxX' ||
property === 'minY' ||
property === 'maxY' ||
property === 'minZ' || property === 'minZ' ||
property === 'maxZ' || property === 'maxZ' ||
property === 'offsetX' || property === 'offsetX' ||

View File

@ -19,6 +19,8 @@ GameLib.System.Audio = function(
this.pauseAllAudioSubscription = null; this.pauseAllAudioSubscription = null;
this.muteAudioSubscription = null;
this.continueAllAudioSubscription = null; this.continueAllAudioSubscription = null;
this.stopAudioSubscription = null; this.stopAudioSubscription = null;
@ -64,6 +66,10 @@ GameLib.System.Audio.prototype.start = function() {
this.pauseAllAudio.bind(this) this.pauseAllAudio.bind(this)
); );
this.muteAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.MUTE_AUDIO,
this.muteAudio.bind(this)
);
this.continueAllAudioSubscription = GameLib.Event.Subscribe( this.continueAllAudioSubscription = GameLib.Event.Subscribe(
GameLib.Event.CONTINUE_ALL_AUDIO, GameLib.Event.CONTINUE_ALL_AUDIO,
@ -206,6 +212,37 @@ GameLib.System.Audio.prototype.removeComponent = function(data) {
}; };
GameLib.System.Audio.prototype.muteAudio = function() {
this.mute = !this.mute;
if (this.mute) {
this.audioVolumes = this.audioComponents.reduce(
function(result, audio) {
result.push(
{
audio : audio,
volume : audio.volume
}
);
audio.volume = 0;
audio.updateInstance('volume');
return result;
},
[]
)
} else {
this.audioVolumes.map(
function(audioVolume) {
audioVolume.audio.volume = audioVolume.volume;
audioVolume.audio.updateInstance('volume');
}
)
}
};
/** /**
* Stop this system (remove all event listeners) * Stop this system (remove all event listeners)
@ -218,6 +255,7 @@ GameLib.System.Audio.prototype.stop = function() {
this.removeComponentSubscription.remove(); this.removeComponentSubscription.remove();
this.playAudioSubscription.remove(); this.playAudioSubscription.remove();
this.pauseAllAudioSubscription.remove(); this.pauseAllAudioSubscription.remove();
this.muteAudioSubscription.remove();
this.continueAllAudioSubscription.remove(); this.continueAllAudioSubscription.remove();
this.stopAudioSubscription.remove(); this.stopAudioSubscription.remove();
this.stopAllAudioSubscription.remove(); this.stopAllAudioSubscription.remove();