private void TestAddRemoveListenerImpl(Game game) { var audio = game.Audio; var notAddedToEntityListener = new AudioListenerComponent(); var addedToEntityListener = new AudioListenerComponent(); // Add a listenerComponent not present in the entity system yet and check that it is correctly added to the AudioSystem internal data structures Assert.DoesNotThrow(() => audio.AddListener(notAddedToEntityListener), "Adding a listener not present in the entity system failed"); Assert.IsTrue(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem does not contains the notAddedToEntityListener."); // Add a listenerComponent already present in the entity system and check that it is correctly added to the AudioSystem internal data structures var entity = new Entity("Test"); entity.Add(addedToEntityListener); throw new NotImplementedException("TODO: UPDATE TO USE Scene and Graphics Composer"); //game.Entities.Add(entity); Assert.DoesNotThrow(() => audio.AddListener(addedToEntityListener), "Adding a listener present in the entity system failed"); Assert.IsTrue(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem does not contains the addedToEntityListener."); // Add a listenerComponent already added to audio System and check that it does not crash Assert.DoesNotThrow(()=>audio.AddListener(addedToEntityListener), "Adding a listener already added to the audio system failed."); // Remove the listeners from the AudioSystem and check that they are removed from internal data structures. Assert.DoesNotThrow(() => audio.RemoveListener(notAddedToEntityListener), "Removing an listener not present in the entity system failed."); Assert.IsFalse(audio.Listeners.ContainsKey(notAddedToEntityListener), "The list of listeners of AudioSystem still contains the notAddedToEntityListener."); Assert.DoesNotThrow(() => audio.RemoveListener(addedToEntityListener), "Removing an listener present in the entity system fails"); Assert.IsFalse(audio.Listeners.ContainsKey(addedToEntityListener), "The list of listeners of AudioSystem still contains the addedToEntityListener."); // Remove a listener not present in the AudioSystem anymore and check the thrown exception Assert.Throws<ArgumentException>(() => audio.RemoveListener(addedToEntityListener), "Removing the a non-existing listener did not throw ArgumentException."); }
/// <summary> /// Remove a <see cref="AudioListenerComponent" /> from the Audio System. /// After this call sounds played via <see cref="AudioEmitterSoundController" />s will not be heard by this listener anymore. /// </summary> /// <param name="listener">The listener to remove from the audio system.</param> /// <exception cref="System.ArgumentException">The provided listener was not present in the Audio System.</exception> public void RemoveListener(AudioListenerComponent listener) { if(!Listeners.ContainsKey(listener)) throw new ArgumentException("The provided listener was not present in the Audio System."); Listeners.Remove(listener); }
/// <summary> /// Add and activate a <see cref="AudioListenerComponent" /> to the Audio System. /// After this call sounds played via <see cref="AudioEmitterSoundController" />s will be heard by this listener. /// </summary> /// <param name="listener">The listener to add to the audio system.</param> /// <remarks>Adding a listener already added as no effects.</remarks> public void AddListener(AudioListenerComponent listener) { if (!Listeners.ContainsKey(listener)) { Listeners[listener] = null; } }
private void CreateAndComponentToEntities() { listComp1 = new AudioListenerComponent(); listComp2 = new AudioListenerComponent(); listComp1Entity.Add(listComp1); listComp2Entity.Add(listComp2); }
/// <summary> /// Remove a <see cref="AudioListenerComponent" /> from the Audio System. /// After this call sounds played via <see cref="AudioEmitterSoundController" />s will not be heard by this listener anymore. /// </summary> /// <param name="listener">The listener to remove from the audio system.</param> /// <exception cref="System.ArgumentException">The provided listener was not present in the Audio System.</exception> public void RemoveListener(AudioListenerComponent listener) { if (!Listeners.ContainsKey(listener)) { throw new ArgumentException("The provided listener was not present in the Audio System."); } Listeners.Remove(listener); }
/// <summary> /// Add and activate a <see cref="AudioListenerComponent" /> to the Audio System. /// After this call sounds played via <see cref="AudioEmitterSoundController" />s will be heard by this listener. /// </summary> /// <param name="listener">The listener to add to the audio system.</param> /// <remarks>Adding a listener already added as no effects.</remarks> public void AddListener(AudioListenerComponent listener) { if(!Listeners.ContainsKey(listener)) Listeners[listener] = null; }