Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 9bb5ffb

Browse files
committed
Added SoundSet RemoveSound method, for removing sounds from soundsets (and their sub soundsets)
Also cleaned up a few soundset-y places
1 parent dbde28b commit 9bb5ffb

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
625625
`soundSet.SubSoundSets` (Lua R) - An iterator over the sub `SoundSets` of this `SoundSet`, allowing you to manipulate them as you would any `SoundSet`.
626626
`soundSet:HasAnySounds(includeSubSoundSets)` (Lua) - Whether or not this `SoundSet` has any sounds, optionally including its sub `SoundSets`.
627627
`soundSet:SelectNextSounds()` (Lua) - Selects the next sounds for this `SoundSet`. Note that playing a `SoundContainer` will always also do this, so this is only really useful to allow you to skip sounds when `SoundSelectionCycleMode` is set to `FORWARDS`.
628-
`soundSet:AddSound("Path/to/sound")` (Lua) - Adds the sound at the given path with no offset, 0 minimum audible distance, and default attenuation start distance.
629-
`soundSet:AddSound("Path/to/sound", offset, minimumAudibleDistance, attenuationStartDistance)` (Lua) - Adds the sound at the given path with the given parameters.
628+
`soundSet:AddSound("Path/to/sound.flac")` (Lua) - Adds the sound at the given path with no offset, 0 minimum audible distance, and default attenuation start distance.
629+
`soundSet:AddSound("Path/to/sound.flac", offset, minimumAudibleDistance, attenuationStartDistance)` (Lua) - Adds the sound at the given path with the given parameters.
630630
`soundSet:AddSoundSet(soundSetToAdd)` (Lua) - Adds the given `SoundSet` as a sub `SoundSet` of this `SoundSet`.
631+
`soundSet:RemoveSound("Path/to/sound.flac")` (Lua) - Removes any sounds with the given filepath from the `SoundSet`, returning whether or not any where removed. Does not remove sounds from sub-`SoundSet`s.
632+
`soundSet:RemoveSound("Path/to/sound.flac", removeFromSubSoundSets)` (Lua) - Removes any sounds with the given filepath from the `SoundSet`, returning whether or not any where removed. Optionally removes matching sounds from any sub-`SoundSet`s and their sub-`SoundSet`s and so on.
631633

632634
Additionally, `AddSound` and `AddSoundSet` INI properties work for `SoundSets`. They are exactly the same as they are for `SoundContainers`.
633635

Entities/SoundSet.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ namespace RTE {
175175
m_SoundData.push_back({soundFile, soundObject, offset, minimumAudibleDistance, attenuationStartDistance});
176176
}
177177

178+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179+
180+
bool SoundSet::RemoveSound(const std::string &soundFilePath, bool removeFromSubSoundSets) {
181+
auto soundsToRemove = std::remove_if(m_SoundData.begin(), m_SoundData.end(), [&soundFilePath](const SoundSet::SoundData &soundData) { return soundData.SoundFile.GetDataPath() == soundFilePath; });
182+
bool anySoundsToRemove = soundsToRemove != m_SoundData.end();
183+
if (anySoundsToRemove) { m_SoundData.erase(soundsToRemove, m_SoundData.end()); }
184+
if (removeFromSubSoundSets) {
185+
for (SoundSet subSoundSet : m_SubSoundSets) { anySoundsToRemove |= RemoveSound(soundFilePath, removeFromSubSoundSets); }
186+
}
187+
return anySoundsToRemove;
188+
}
189+
178190
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179191

180192
bool SoundSet::HasAnySounds(bool includeSubSoundSets) const {

Entities/SoundSet.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,26 @@ namespace RTE {
120120
/// <param name="abortGameForInvalidSound">Whether to abort the game if the sound couldn't be added, or just show a console error.</param>
121121
void AddSound(const std::string &soundFilePath, const Vector &offset, float minimumAudibleDistance, float attenuationStartDistance, bool abortGameForInvalidSound);
122122

123+
/// <summary>
124+
/// Removes all instances of the sound with the given filepath from this SoundSet. Does not remove it from any sub-SoundSets.
125+
/// </summary>
126+
/// <param name="soundFilePath">The path to the sound to be removed from this SoundSet.</param>
127+
/// <returns>Whether or not a sound with the given filepath was found in this SoundSet.</returns>
128+
bool RemoveSound(const std::string &soundFilePath) { return RemoveSound(soundFilePath, false); }
129+
130+
/// <summary>
131+
/// Removes all instances of the sound with the given filepath from this SoundSet, optionally removing it from all sub-SoundSets as well.
132+
/// </summary>
133+
/// <param name="soundFilePath">The path to the sound to be removed from this SoundSet.</param>
134+
/// <param name="removeFromSubSoundSets">Whether or not to remove the sound from any sub-SoundSets as well as this SoundSet.</param>
135+
/// <returns>Whether or not a sound with the given filepath was found in this SoundSet or, if set to remove from sub-SoundSets, any of its sub-SoundSets.</returns>
136+
bool RemoveSound(const std::string &soundFilePath, bool removeFromSubSoundSets);
137+
123138
/// <summary>
124139
/// Adds a copy of the given SoundData to this SoundSet.
125140
/// </summary>
126141
/// <param name="soundDataToAdd">The SoundData to copy to this SoundSet.</param>
127-
void AddSoundData(SoundData soundDataToAdd) { m_SoundData.push_back(soundDataToAdd); }
142+
void AddSoundData(const SoundData &soundDataToAdd) { m_SoundData.push_back(soundDataToAdd); }
128143

129144
/// <summary>
130145
/// Adds a copy of the passed in SoundSet as a sub SoundSet of this SoundSet. Ownership IS transferred!

Lua/LuaBindingsEntities.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,8 +1145,10 @@ namespace RTE {
11451145

11461146
.def("HasAnySounds", &SoundSet::HasAnySounds)
11471147
.def("SelectNextSounds", &SoundSet::SelectNextSounds)
1148-
.def("AddSound", (void (SoundSet:: *)(std::string const &soundFilePath)) &SoundSet::AddSound)
1149-
.def("AddSound", (void (SoundSet:: *)(std::string const &soundFilePath, const Vector &offset, float minimumAudibleDistance, float attenuationStartDistance)) &SoundSet::AddSound)
1148+
.def("AddSound", (void (SoundSet:: *)(const std::string &soundFilePath)) &SoundSet::AddSound)
1149+
.def("AddSound", (void (SoundSet:: *)(const std::string &soundFilePath, const Vector &offset, float minimumAudibleDistance, float attenuationStartDistance)) &SoundSet::AddSound)
1150+
.def("RemoveSound", (bool (SoundSet:: *)(const std::string &soundFilePath)) &SoundSet::RemoveSound)
1151+
.def("RemoveSound", (bool (SoundSet:: *)(const std::string &soundFilePath, bool removeFromSubSoundSets)) &SoundSet::RemoveSound)
11501152
.def("AddSoundSet", &SoundSet::AddSoundSet)
11511153

11521154
.enum_("SoundSelectionCycleMode")[

0 commit comments

Comments
 (0)