refactor(component): the sound trigger reads its level config in LoadConfigData

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-01 08:10:56 -05:00
parent e5607ff0c7
commit 7a0013696b
2 changed files with 12 additions and 7 deletions

View File

@@ -26,32 +26,35 @@ void MixerProgram::Serialize(RakNet::BitStream& outBitStream){
outBitStream.Write(result);
}
SoundTriggerComponent::SoundTriggerComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
}
const auto musicCueName = parent->GetVar<std::string>(u"NDAudioMusicCue_Name");
// The level config: music cues and parameters, ambient sounds and mixer programs
void SoundTriggerComponent::LoadConfigData() {
const auto musicCueName = m_Parent->GetVar<std::string>(u"NDAudioMusicCue_Name");
if (!musicCueName.empty()) {
auto newCue = MusicCue(musicCueName);
const auto musicCueBoredomTime = parent->GetVar<float>(u"NDAudioMusicCue_BoredomTime");
const auto musicCueBoredomTime = m_Parent->GetVar<float>(u"NDAudioMusicCue_BoredomTime");
if (musicCueBoredomTime) newCue.boredomTime = musicCueBoredomTime;
this->m_MusicCues.push_back(newCue);
}
const auto musicParameterName = parent->GetVar<std::string>(u"NDAudioMusicParameter_Name");
const auto musicParameterName = m_Parent->GetVar<std::string>(u"NDAudioMusicParameter_Name");
if (!musicParameterName.empty()) {
auto newParams = MusicParameter(musicParameterName);
const auto musicParameterValue = parent->GetVar<float>(u"NDAudioMusicParameter_Value");
const auto musicParameterValue = m_Parent->GetVar<float>(u"NDAudioMusicParameter_Value");
if (musicParameterValue) newParams.value = musicParameterValue;
this->m_MusicParameters.push_back(newParams);
}
const auto guidString = parent->GetVar<std::string>(u"NDAudioEventGUID");
const auto guidString = m_Parent->GetVar<std::string>(u"NDAudioEventGUID");
if (!guidString.empty())
this->m_2DAmbientSounds.push_back(GUIDResults(guidString));
const auto guid2String = parent->GetVar<std::string>(u"NDAudioEventGUID2");
const auto guid2String = m_Parent->GetVar<std::string>(u"NDAudioEventGUID2");
if (!guid2String.empty())
this->m_3DAmbientSounds.push_back(GUIDResults(guid2String));
const auto mixerName = parent->GetVar<std::string>(u"NDAudioMixerProgram_Name");
const auto mixerName = m_Parent->GetVar<std::string>(u"NDAudioMixerProgram_Name");
if (!mixerName.empty()) this->m_MixerPrograms.push_back(MixerProgram(mixerName));
}

View File

@@ -61,6 +61,8 @@ class SoundTriggerComponent : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_TRIGGER;
explicit SoundTriggerComponent(Entity* parent, const int32_t componentID);
void LoadConfigData() override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void ActivateMusicCue(const std::string& name, float bordemTime = -1.0);
void DeactivateMusicCue(const std::string& name);