check subscription before remove, respect audio load time
parent
4870bc285a
commit
5bd229869e
|
@ -148,7 +148,12 @@ GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
GameLib.D3.ParticleEngine.prototype.remove = function() {
|
GameLib.D3.ParticleEngine.prototype.remove = function() {
|
||||||
|
|
||||||
GameLib.Event.Subscribe(
|
if (this.removeSubscription) {
|
||||||
|
console.log('already another remove subscription for ' + this.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.removeSubscription = GameLib.Event.Subscribe(
|
||||||
GameLib.Event.REMOVE_PARTICLE_ENGINE,
|
GameLib.Event.REMOVE_PARTICLE_ENGINE,
|
||||||
function(data){
|
function(data){
|
||||||
if (data.component === this) {
|
if (data.component === this) {
|
||||||
|
@ -180,6 +185,10 @@ GameLib.D3.ParticleEngine.prototype.remove = function() {
|
||||||
} else {
|
} else {
|
||||||
GameLib.Component.prototype.remove.call(this);
|
GameLib.Component.prototype.remove.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.removeSubscription.remove();
|
||||||
|
|
||||||
|
this.removeSubscription = null;
|
||||||
}
|
}
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
|
@ -75,6 +75,11 @@ GameLib.System = function(
|
||||||
componentType = GameLib.Component.COMPONENT_SYSTEM_PARTICLE;
|
componentType = GameLib.Component.COMPONENT_SYSTEM_PARTICLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (apiSystem.systemType === GameLib.System.SYSTEM_TYPE_AUDIO) {
|
||||||
|
componentType = GameLib.Component.COMPONENT_SYSTEM_AUDIO;
|
||||||
|
linkedObjects.audioComponents = [GameLib.D3.Audio];
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
componentType
|
componentType
|
||||||
|
|
|
@ -22,6 +22,8 @@ GameLib.System.Audio = function(
|
||||||
this.stopAudioSubscription = null;
|
this.stopAudioSubscription = null;
|
||||||
|
|
||||||
this.audioComponents = [];
|
this.audioComponents = [];
|
||||||
|
|
||||||
|
this.toPlay = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Audio.prototype = Object.create(GameLib.System.prototype);
|
GameLib.System.Audio.prototype = Object.create(GameLib.System.prototype);
|
||||||
|
@ -68,6 +70,17 @@ GameLib.System.Audio.prototype.start = function() {
|
||||||
GameLib.System.Audio.prototype.instanceCreated = function(data) {
|
GameLib.System.Audio.prototype.instanceCreated = function(data) {
|
||||||
if (data.component instanceof GameLib.D3.Audio) {
|
if (data.component instanceof GameLib.D3.Audio) {
|
||||||
GameLib.Utils.PushUnique(this.audioComponents, data.component);
|
GameLib.Utils.PushUnique(this.audioComponents, data.component);
|
||||||
|
|
||||||
|
var index = this.toPlay.indexOf(data.component.name);
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.PLAY_AUDIO,
|
||||||
|
{
|
||||||
|
name : data.component.name
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,10 +90,18 @@ GameLib.System.Audio.prototype.instanceCreated = function(data) {
|
||||||
*/
|
*/
|
||||||
GameLib.System.Audio.prototype.playAudio = function(data) {
|
GameLib.System.Audio.prototype.playAudio = function(data) {
|
||||||
|
|
||||||
|
var found = false;
|
||||||
|
|
||||||
this.audioComponents.map(
|
this.audioComponents.map(
|
||||||
function(audio) {
|
function(audio) {
|
||||||
if (audio.name === data.name) {
|
if (audio.name === data.name) {
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
if (!audio.instance) {
|
||||||
|
console.log('audio not ready yet');
|
||||||
|
}
|
||||||
|
|
||||||
if (audio.instance.isPlaying && audio.overplay) {
|
if (audio.instance.isPlaying && audio.overplay) {
|
||||||
audio.instance.stop();
|
audio.instance.stop();
|
||||||
}
|
}
|
||||||
|
@ -102,9 +123,15 @@ GameLib.System.Audio.prototype.playAudio = function(data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
/**
|
||||||
|
* This audio still has to load
|
||||||
|
*/
|
||||||
|
console.log('delaying play until loaded for: ' + data.name);
|
||||||
|
this.toPlay.push(data.name);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Audio.prototype.pauseAudio = function(data) {
|
GameLib.System.Audio.prototype.pauseAudio = function(data) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ GameLib.System.Particle.prototype.removeComponent = function(data) {
|
||||||
var index = this.particleEngines.indexOf(data.component);
|
var index = this.particleEngines.indexOf(data.component);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
console.log('removing particle engine from system');
|
console.log('removing particle engine from system' + data.component.name);
|
||||||
|
|
||||||
this.particleEngines.splice(index, 1);
|
this.particleEngines.splice(index, 1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue