audio system pause updates

beta.r3js.org
-=yb4f310 2017-11-25 11:15:39 +01:00
parent ddfdbd29cc
commit e4a5554c56
6 changed files with 122 additions and 58 deletions

26
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)
var __DATE__ = "Sat Nov 25 2017 08:16:31 GMT+0100 (CET)";
var __DATE__ = "Sat Nov 25 2017 11:12:58 GMT+0100 (CET)";
// END COMPILE TIME DEFINITIONS
/**
@ -3774,6 +3774,7 @@ GameLib.D3.API.Audio = function(
volume,
camera,
overplay,
paused,
parentEntity
) {
@ -3812,6 +3813,11 @@ GameLib.D3.API.Audio = function(
}
this.overplay = overplay;
if (GameLib.Utils.UndefinedOrNull(paused)) {
paused = false;
}
this.paused = paused;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
@ -3845,6 +3851,7 @@ GameLib.D3.API.Audio.FromObject = function(objectAudio) {
objectAudio.volume,
apiCamera,
objectAudio.overplay,
objectAudio.paused,
objectAudio.parentEntity
);
@ -9065,6 +9072,7 @@ GameLib.D3.Audio = function(
apiAudio.volume,
apiAudio.camera,
apiAudio.overplay,
apiAudio.pause,
apiAudio.parentEntity
);
@ -9120,7 +9128,7 @@ GameLib.D3.Audio.prototype.createInstance = function() {
//Load a sound and set it as the Audio object's buffer
audioLoader.load(
this.apiUrl + this.path,
this.apiUrl + this.path + '?ts=' + Date.now(),
function( buffer ) {
this.instance.setBuffer( buffer );
this.instance.setLoop( this.loop );
@ -9143,6 +9151,14 @@ GameLib.D3.Audio.prototype.updateInstance = function(property) {
this.instance.setVolume(this.volume);
}
if (property === 'paused') {
if (this.paused) {
this.instance.pause();
} else {
this.instance.play();
}
}
};
/**
@ -9159,6 +9175,7 @@ GameLib.D3.Audio.prototype.toApiObject = function() {
this.volume,
GameLib.Utils.IdOrNull(this.camera),
this.overplay,
this.paused,
GameLib.Utils.IdOrNull(this.parentEntity)
);
@ -25649,18 +25666,33 @@ GameLib.System.Audio.prototype.start = function() {
* @param data
*/
GameLib.System.Audio.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.D3.Audio) {
GameLib.Utils.PushUnique(this.audioComponents, data.component);
data.component.instance.onEnded = function() {
this.isPlaying = false;
GameLib.Event.Emit(
GameLib.Event.AUDIO_ENDED,
{
audio : data.component
}
);
};
var index = this.toPlay.indexOf(data.component.name);
if (index !== -1) {
GameLib.Event.Emit(
GameLib.Event.PLAY_AUDIO,
{
name : data.component.name
}
)
);
this.toPlay.splice(index, 1);
}
}
};
@ -25683,25 +25715,14 @@ GameLib.System.Audio.prototype.playAudio = function(data) {
console.log('audio not ready yet');
}
if (audio.instance.isPlaying && audio.overplay) {
audio.instance.stop();
}
if (!audio.instance.isPlaying) {
audio.instance.play();
audio.instance.onEnded = function() {
this.isPlaying = false;
GameLib.Event.Emit(
GameLib.Event.AUDIO_ENDED,
{
audio : audio
}
);
if (audio.overplay) {
if (audio.instance.isPlaying) {
audio.instance.stop();
}
audio.instance.offset = 0;
audio.instance.play();
} else if (!audio.instance.isPlaying) {
audio.instance.play();
}
}
}
@ -25723,8 +25744,11 @@ GameLib.System.Audio.prototype.pauseAllAudio = function(data) {
this.audioComponents.map(
function(audio) {
if (audio.instance.isPlaying) {
audio.instance.pause();
this.paused.push(audio);
// audio.currentTime = audio.instance.context.currentTime;
audio.paused = true;
audio.updateInstance('paused');
}
}.bind(this)
)
@ -25734,10 +25758,14 @@ GameLib.System.Audio.prototype.continueAllAudio = function(data) {
this.paused.map(
function(audio) {
audio.instance.play();
// audio.instance.context.currentTime = audio.currentTime;
audio.paused = false;
audio.updateInstance('paused');
}
);
this.paused = [];
};
GameLib.System.Audio.prototype.stopAllAudio = function(data) {
@ -30541,6 +30569,10 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
this.renderers.push(data.component);
}
if (data.component instanceof GameLib.D3.Stats) {
console.log('new stats');
this.statistics.push(data.component);
}
};
/**

View File

@ -18,6 +18,7 @@ GameLib.D3.API.Audio = function(
volume,
camera,
overplay,
paused,
parentEntity
) {
@ -56,6 +57,11 @@ GameLib.D3.API.Audio = function(
}
this.overplay = overplay;
if (GameLib.Utils.UndefinedOrNull(paused)) {
paused = false;
}
this.paused = paused;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
@ -89,6 +95,7 @@ GameLib.D3.API.Audio.FromObject = function(objectAudio) {
objectAudio.volume,
apiCamera,
objectAudio.overplay,
objectAudio.paused,
objectAudio.parentEntity
);

View File

@ -29,6 +29,7 @@ GameLib.D3.Audio = function(
apiAudio.volume,
apiAudio.camera,
apiAudio.overplay,
apiAudio.pause,
apiAudio.parentEntity
);
@ -84,7 +85,7 @@ GameLib.D3.Audio.prototype.createInstance = function() {
//Load a sound and set it as the Audio object's buffer
audioLoader.load(
this.apiUrl + this.path,
this.apiUrl + this.path + '?ts=' + Date.now(),
function( buffer ) {
this.instance.setBuffer( buffer );
this.instance.setLoop( this.loop );
@ -107,6 +108,14 @@ GameLib.D3.Audio.prototype.updateInstance = function(property) {
this.instance.setVolume(this.volume);
}
if (property === 'paused') {
if (this.paused) {
this.instance.pause();
} else {
this.instance.play();
}
}
};
/**
@ -123,6 +132,7 @@ GameLib.D3.Audio.prototype.toApiObject = function() {
this.volume,
GameLib.Utils.IdOrNull(this.camera),
this.overplay,
this.paused,
GameLib.Utils.IdOrNull(this.parentEntity)
);

View File

@ -93,18 +93,33 @@ GameLib.System.Audio.prototype.start = function() {
* @param data
*/
GameLib.System.Audio.prototype.instanceCreated = function(data) {
if (data.component instanceof GameLib.D3.Audio) {
GameLib.Utils.PushUnique(this.audioComponents, data.component);
data.component.instance.onEnded = function() {
this.isPlaying = false;
GameLib.Event.Emit(
GameLib.Event.AUDIO_ENDED,
{
audio : data.component
}
);
};
var index = this.toPlay.indexOf(data.component.name);
if (index !== -1) {
GameLib.Event.Emit(
GameLib.Event.PLAY_AUDIO,
{
name : data.component.name
}
)
);
this.toPlay.splice(index, 1);
}
}
};
@ -127,25 +142,14 @@ GameLib.System.Audio.prototype.playAudio = function(data) {
console.log('audio not ready yet');
}
if (audio.instance.isPlaying && audio.overplay) {
audio.instance.stop();
}
if (!audio.instance.isPlaying) {
audio.instance.play();
audio.instance.onEnded = function() {
this.isPlaying = false;
GameLib.Event.Emit(
GameLib.Event.AUDIO_ENDED,
{
audio : audio
}
);
if (audio.overplay) {
if (audio.instance.isPlaying) {
audio.instance.stop();
}
audio.instance.offset = 0;
audio.instance.play();
} else if (!audio.instance.isPlaying) {
audio.instance.play();
}
}
}
@ -167,8 +171,11 @@ GameLib.System.Audio.prototype.pauseAllAudio = function(data) {
this.audioComponents.map(
function(audio) {
if (audio.instance.isPlaying) {
audio.instance.pause();
this.paused.push(audio);
// audio.currentTime = audio.instance.context.currentTime;
audio.paused = true;
audio.updateInstance('paused');
}
}.bind(this)
)
@ -178,10 +185,14 @@ GameLib.System.Audio.prototype.continueAllAudio = function(data) {
this.paused.map(
function(audio) {
audio.instance.play();
// audio.instance.context.currentTime = audio.currentTime;
audio.paused = false;
audio.updateInstance('paused');
}
);
this.paused = [];
};
GameLib.System.Audio.prototype.stopAllAudio = function(data) {

View File

@ -58,6 +58,10 @@ GameLib.System.Render.prototype.instanceCreated = function(data) {
this.renderers.push(data.component);
}
if (data.component instanceof GameLib.D3.Stats) {
console.log('new stats');
this.statistics.push(data.component);
}
};
/**