#include "SoundTriggerComponent.h" #include "EntityManager.h" #include "Game.h" SoundTriggerComponent::SoundTriggerComponent(Entity* parent) : Component(parent) { const auto musicCueName = parent->GetVar(u"NDAudioMusicCue_Name"); const auto musicCueBoredomTime = parent->GetVar(u"NDAudioMusicCue_BoredomTime"); this->musicCues.push_back({ musicCueName, 1, musicCueBoredomTime }); const auto mixerName = parent->GetVar(u"NDAudioMixerProgram_Name"); this->mixerPrograms.push_back(mixerName); const auto guid2String = parent->GetVar(u"NDAudioEventGUID2"); if (!guid2String.empty()) { this->guids.emplace_back(guid2String); } } SoundTriggerComponent::~SoundTriggerComponent() = default; void SoundTriggerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { if (bIsInitialUpdate) dirty = true; outBitStream->Write(dirty); if (dirty) { outBitStream->Write(this->musicCues.size()); for (const auto& musicCue : this->musicCues) { outBitStream->Write(musicCue.name.size()); outBitStream->Write(musicCue.name.c_str(), musicCue.name.size()); outBitStream->Write(musicCue.result); outBitStream->Write(musicCue.boredomTime); } // Unknown part outBitStream->Write(0); // GUID part outBitStream->Write(this->guids.size()); for (const auto guid : this->guids) { outBitStream->Write(guid.GetData1()); outBitStream->Write(guid.GetData2()); outBitStream->Write(guid.GetData3()); for (const auto& guidSubPart : guid.GetData4()) { outBitStream->Write(guidSubPart); } outBitStream->Write(1); // Unknown } // Mixer program part outBitStream->Write(this->mixerPrograms.size()); for (const auto& mixerProgram : mixerPrograms) { outBitStream->Write(mixerProgram.size()); outBitStream->Write(mixerProgram.c_str(), mixerProgram.size()); outBitStream->Write(1); // Unknown } dirty = false; } } void SoundTriggerComponent::ActivateMusicCue(const std::string& name) { if (std::find_if(this->musicCues.begin(), this->musicCues.end(), [name](const MusicCue& musicCue) { return musicCue.name == name; }) == this->musicCues.end()) { this->musicCues.push_back({ name, 1, -1.0f }); dirty = true; EntityManager::Instance()->SerializeEntity(m_OwningEntity); } } void SoundTriggerComponent::DeactivateMusicCue(const std::string& name) { const auto musicCue = std::find_if(this->musicCues.begin(), this->musicCues.end(), [name](const MusicCue& musicCue) { return musicCue.name == name; }); if (musicCue != this->musicCues.end()) { this->musicCues.erase(musicCue); dirty = true; EntityManager::Instance()->SerializeEntity(m_OwningEntity); } }