diff --git a/Adventures in Lestoria/AdventuresInLestoria.cpp b/Adventures in Lestoria/AdventuresInLestoria.cpp index 0461e3bc..b50ab89c 100644 --- a/Adventures in Lestoria/AdventuresInLestoria.cpp +++ b/Adventures in Lestoria/AdventuresInLestoria.cpp @@ -150,6 +150,12 @@ AiL::AiL() utils::datafile::Read(DATA,CONFIG_PATH + "class_directory"_S + cl + ".txt"); } + std::string BGM_CONFIG = CONFIG_PATH + "bgm_config"_S; + utils::datafile::Read(DATA,BGM_CONFIG); + + std::string BGM_EVENTS_CONFIG = CONFIG_PATH + "event_config"_S; + utils::datafile::Read(DATA,BGM_EVENTS_CONFIG); + utils::datafile::DEBUG_ACCESS_OPTIONS="debug_access_options"_I; sAppName = "GAME_NAME"_S; diff --git a/Adventures in Lestoria/Audio.cpp b/Adventures in Lestoria/Audio.cpp index 473f1266..c7fb0ca5 100644 --- a/Adventures in Lestoria/Audio.cpp +++ b/Adventures in Lestoria/Audio.cpp @@ -40,6 +40,47 @@ All rights reserved. #include "DEFINES.h" INCLUDE_game +INCLUDE_DATA + +void Audio::Initialize(){ + Audio&instance=game->audioEngine; + for(auto&[key,data]:DATA["Events"]){ + instance.events.insert(key); + } + for(auto&[songName,data]:DATA["BGM"]){ + int channelCounter=0; + + BGM&bgm=instance.bgm[songName]; + + bgm.SetName(data["Track Name"].GetString()); + + while(data.HasProperty(std::format("channel[{}]",channelCounter))){ + bgm.AddChannel(data[std::format("channel[{}]",channelCounter)].GetString()); + channelCounter++; + } + + if(!data.HasProperty("Default Volume"))ERR(std::format("WARNING! Track {} does not have a Default Volume parameter!",bgm.GetName())); + if(data["Default Volume"].GetValueCount()!=bgm.GetChannelCount())ERR(std::format("WARNING! Default Volume parameters do not match channel count. {} != {}",data["Default Volume"].GetValueCount(),bgm.GetChannelCount())); + + VolumeList volumes; + for(int i=0;iaudioEngine.audioEngine; @@ -52,6 +93,38 @@ void Audio::PlayBGM(const std::string_view sound,const bool loop=true){ Engine().Play(std::string(sound)); }; +void Audio::BGM::SetFadeTime(const float fadeTime){ + this->fadeTime=fadeTime; +} + +void Audio::BGM::AddEventVolumes(const Event&eventName,const VolumeList&volumes){ + eventVolumes.AddEventInfo(eventName,volumes); +} + +const size_t Audio::BGM::GetChannelCount()const{ + return channelNames.size(); +} + +const SongName&Audio::BGM::GetName()const{ + return songName; +} + +void Audio::BGM::SetName(std::string_view name){ + songName=name; +} +void Audio::BGM::AddChannel(const ChannelName&name){ + channelNames.push_back(name); +} + +const VolumeList&Audio::EventData::GetVolumes(const Event&event)const{ + if(eventInfo.find(event)!=eventInfo.end())return eventInfo.at(event); + return eventInfo.at("Default Volume"); +} + +void Audio::EventData::AddEventInfo(const Event&eventName,const VolumeList&volumes){ + eventInfo[eventName]=volumes; +} + std::string operator""_SFX(const char*key,size_t length){ return "sfx_directory"_S+std::string(key,length); } diff --git a/Adventures in Lestoria/Audio.h b/Adventures in Lestoria/Audio.h index cde143d5..19e8f6c9 100644 --- a/Adventures in Lestoria/Audio.h +++ b/Adventures in Lestoria/Audio.h @@ -39,16 +39,42 @@ All rights reserved. #include "olcPGEX_MiniAudio.h" #include "config.h" +using SongName=std::string; +using Event=std::string; +using ChannelName=std::string; +using ChannelIDList=std::vector; +using VolumeList=std::vector; + class Audio{ + class EventData{ + std::mapeventInfo; + public: + void AddEventInfo(const Event&eventName,const VolumeList&volumes); + const VolumeList&GetVolumes(const Event&event)const; + }; class BGM{ - std::vectorchannels; + std::string songName; + ChannelIDList channels; + std::vectorchannelNames; + EventData eventVolumes; + float fadeTime="BGM.Default Fade Time"_F; public: - Load(); - Unload(); + void Load(); + void Unload(); + const size_t GetChannelCount()const; + const SongName&GetName()const; + void SetName(std::string_view name); + void AddChannel(const ChannelName&name); + void AddEventVolumes(const Event&eventName,const VolumeList&volumes); + void SetFadeTime(const float fadeTime); }; MiniAudio audioEngine; + SongName currentBGM; + std::mapbgm; + std::setevents; public: static MiniAudio&Engine(); + static void Initialize(); static void Play(const std::string_view sound); static void PlayBGM(const std::string_view sound,const bool loop=true); }; diff --git a/Adventures in Lestoria/TODO.txt b/Adventures in Lestoria/TODO.txt index d493d8ae..1d7dd1e5 100644 --- a/Adventures in Lestoria/TODO.txt +++ b/Adventures in Lestoria/TODO.txt @@ -18,7 +18,7 @@ Settings Menu -Upon pressing a key, check if the key is bound to another option, if so, remove that bind from the list. Up to two keys may be binded per action. -We have to save keybinds to the save file. - +-Smooth Movement January 31st ============ @@ -41,4 +41,6 @@ Story proofreading/correcting/storyboarding - Loading Screen - Title Screen setpieces -- Export/Import Save Files Online/Offline \ No newline at end of file +- Export/Import Save Files Online/Offline + +- Consider controls for fine-tuning music and how they sound during events. \ No newline at end of file diff --git a/Adventures in Lestoria/assets/config/bgm/bgm.txt b/Adventures in Lestoria/assets/config/bgm/bgm.txt index c460ae08..f676586b 100644 --- a/Adventures in Lestoria/assets/config/bgm/bgm.txt +++ b/Adventures in Lestoria/assets/config/bgm/bgm.txt @@ -1,25 +1,32 @@ -#Song title followed by filenames for individual parts -foresty1_1 +BGM { - # High - channel[0]=foresty1_1_1.mp3 - # Low - channel[1]=foresty1_1_2.mp3 + Default Fade Time = 1.0 - # Underwater High - channel[2]=foresty1_1_alt1.mp3 - # Underwater Low - channel[3]=foresty1_1_alt2.mp3 + #Song title followed by filenames for individual parts + foresty1_1 + { + Track Name = Foresty - Default Volume = 70%,50%,0%,0% + # High + channel[0]=foresty1_1_1.mp3 + # Low + channel[1]=foresty1_1_2.mp3 - # Transition time between one phase to the next. - Fade Speed = 2.0 + # Underwater High + channel[2]=foresty1_1_alt1.mp3 + # Underwater Low + channel[3]=foresty1_1_alt2.mp3 - Events - { - LowHealth = 50%,60%,20%,20% - InCombat = 90%,100%,0%,0% - Underwater = 0%,0%,100%,100% + Default Volume = 70%,50%,0%,0% + + # Transition time between one phase to the next. + Fade Time = 2.0 + + Events + { + LowHealth = 50%,60%,20%,20% + InCombat = 90%,100%,0%,0% + Underwater = 0%,0%,100%,100% + } } } \ No newline at end of file diff --git a/Adventures in Lestoria/olcUTIL_DataFile.h b/Adventures in Lestoria/olcUTIL_DataFile.h index ffcd8df8..e108bbe8 100644 --- a/Adventures in Lestoria/olcUTIL_DataFile.h +++ b/Adventures in Lestoria/olcUTIL_DataFile.h @@ -488,10 +488,10 @@ namespace olc::utils } inline auto begin(){ - return GetKeys().begin(); + return GetOrderedKeys().begin(); } inline auto end(){ - return GetKeys().end(); + return GetOrderedKeys().end(); } private: