diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 168a16da3c..29e283351b 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -138,6 +138,7 @@ class SoundTrack format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; format.cbSize = 0; valid = true; + name = std::string(SDL_strrchr(fileName, '/') + 1); end: VVV_free(mem); } @@ -170,6 +171,7 @@ class SoundTrack ogg_file = mem; valid = true; + name = std::string(SDL_strrchr(fileName, '/') + 1); } void Dispose(void) @@ -364,6 +366,8 @@ class SoundTrack static FAudioSourceVoice** voices; static FAudioWaveFormatEx voice_formats[VVV_MAX_CHANNELS]; static float volume; + + std::string name; }; FAudioSourceVoice** SoundTrack::voices = NULL; FAudioWaveFormatEx SoundTrack::voice_formats[VVV_MAX_CHANNELS]; @@ -744,6 +748,8 @@ musicclass::musicclass(void) quick_fade = true; usingmmmmmm = false; + + stockSoundTracks = 0; } void musicclass::init(void) @@ -789,6 +795,31 @@ void musicclass::init(void) soundTracks.push_back(SoundTrack( "sounds/newrecord.wav" )); soundTracks.push_back(SoundTrack( "sounds/trophy.wav" )); soundTracks.push_back(SoundTrack( "sounds/rescue.wav" )); + + stockSoundTracks = soundTracks.size(); + + //Here's where we find all the custom sounds in a level's assets folder + EnumHandle handle = {}; + const char* item; + while ((item = FILESYSTEM_enumerateAssets("sounds/", &handle)) != NULL) + { + const std::string str_item = item; + bool match; + for (int j = 0; j < soundTracks.size(); j++) + { + match = (str_item == soundTracks[j].name); + if (match) + { + break; + } + } + if (!match) + { + soundTracks.push_back(SoundTrack( ("sounds/" + str_item).c_str() )); + } + } + FILESYSTEM_freeEnumerate(&handle); + #ifdef VVV_COMPILEMUSIC binaryBlob musicWriteBlob; @@ -1297,6 +1328,20 @@ void musicclass::playef(int t) soundTracks[t].Play(); } +void musicclass::playef_name(std::string& t) +{ + for (int i = 0; i < soundTracks.size(); i++) + { + size_t lastindex = soundTracks[i].name.find_last_of('.'); + std::string rawname = soundTracks[i].name.substr(0, lastindex); + if (t == rawname) + { + soundTracks[i].Play(); + return; + } + } +} + void musicclass::pauseef(void) { SoundTrack::Pause(); diff --git a/desktop_version/src/Music.h b/desktop_version/src/Music.h index 4085fb0bee..1a31a5fed3 100644 --- a/desktop_version/src/Music.h +++ b/desktop_version/src/Music.h @@ -2,6 +2,7 @@ #define MUSIC_H #include "BinaryBlob.h" +#include #define musicroom(rx, ry) ((rx) + ((ry) * 20)) @@ -92,6 +93,7 @@ class musicclass int haltedsong; void playef(int t); + void playef_name(std::string& t); void pauseef(void); void resumeef(void); @@ -117,6 +119,8 @@ class musicclass bool mmmmmm; bool usingmmmmmm; + int stockSoundTracks; + binaryBlob pppppp_blob; binaryBlob mmmmmm_blob; int num_pppppp_tracks; diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index d32a112c17..35d3003dc9 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -382,7 +382,14 @@ void scriptclass::run(void) } if (words[0] == "playef") { - music.playef(ss_toi(words[1])); + if (is_number(words[1].c_str()) && ss_toi(words[1]) >= 0 && ss_toi(words[1]) < music.stockSoundTracks) + { + music.playef(ss_toi(words[1])); + } + else + { + music.playef_name(raw_words[1]); + } } if (words[0] == "play") {