diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 5a3a8fa8..29a06388 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -795,8 +795,31 @@ void musicclass::init(void) char id[256]; SDL_snprintf(asset_filename, sizeof(asset_filename), "sounds/%s", item); - // We need an ID, so chop off the extension - SDL_strlcpy(id, item, sizeof(id)); + // Create the ID + size_t current_char = 0; + size_t item_len = SDL_strlen(item); + for (size_t i = 0; i < item_len; i++) + { + // If it's a space, we don't want to include this. + if (item[i] == ' ') + { + continue; + } + // Otherwise, add it to our ID string, lowered + id[current_char] = SDL_tolower(item[i]); + + current_char++; + + if (current_char >= 255) + { + break; + } + } + + // Null-terminate the string + id[current_char] = '\0'; + + // Chop off the extension! char* dot = SDL_strrchr(id, '.'); if (dot != NULL) { @@ -1322,26 +1345,31 @@ void musicclass::changemusicarea(int x, int y) niceplay(track); } -void musicclass::playef(int t) +bool musicclass::playef(int t) { if (!INBOUNDS_VEC(t, soundTracks)) { - return; + return false; } - soundTracks[t].Play(); + if (soundTracks[t].valid) + { + soundTracks[t].Play(); + return true; + } + return false; } -void musicclass::playefid(const char* id) +bool musicclass::playefid(const char* id) { for (size_t i = 0; i < soundTracks.size(); i++) { if (SDL_strcmp(soundTracks[i].id, id) == 0) { - playef(i); - return; + return playef(i); } } vlog_error("playefid() couldn't find sound ID: %s", id); + return false; } bool musicclass::soundidexists(const char* id) diff --git a/desktop_version/src/Music.h b/desktop_version/src/Music.h index 3705a0d7..c96c3ff5 100644 --- a/desktop_version/src/Music.h +++ b/desktop_version/src/Music.h @@ -94,8 +94,8 @@ public: int currentsong; int haltedsong; - void playef(int t); - void playefid(const char* id); + bool playef(int t); + bool playefid(const char* id); bool soundidexists(const char* id); bool soundisextra(int t); const char* getsoundid(int t); diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index a1aff414..e14066aa 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -447,13 +447,20 @@ void scriptclass::run(void) } if (words[0] == "playef") { + bool played = false; + int sound_id = help.Int(words[1].c_str(), -1); + if (music.soundidexists(words[1].c_str())) { - music.playefid(words[1].c_str()); + played = music.playefid(words[1].c_str()); } - else if (!music.soundisextra(ss_toi(words[1]))) + else if (!music.soundisextra(sound_id)) { - music.playef(ss_toi(words[1])); + played = music.playef(sound_id); + } + if (!played) + { + vlog_error("playef() couldn't play sound: %s", words[1].c_str()); } } if (words[0] == "play")