1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 10:09:43 +01:00

Added custom sound effect functionality to playef()

This commit is contained in:
Fussmatte 2023-02-17 16:02:30 -05:00
parent 2ac85e6929
commit b0eb97fa53
3 changed files with 50 additions and 1 deletions

View file

@ -121,6 +121,7 @@ public:
format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
format.cbSize = 0;
valid = true;
name = std::string(SDL_strrchr(fileName, '/') + 1);
end:
VVV_free(mem);
}
@ -244,6 +245,8 @@ end:
static FAudioSourceVoice** voices;
static float volume;
std::string name;
};
FAudioSourceVoice** SoundTrack::voices = NULL;
float SoundTrack::volume = 0.0f;
@ -657,6 +660,29 @@ void musicclass::init(void)
soundTracks.push_back(SoundTrack( "sounds/trophy.wav" ));
soundTracks.push_back(SoundTrack( "sounds/rescue.wav" ));
//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;
#define FOREACH_TRACK(blob, track_name) blob.AddFileToBinaryBlob("data/" track_name);
@ -1144,6 +1170,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();

View file

@ -2,6 +2,7 @@
#define MUSIC_H
#include "BinaryBlob.h"
#include <string>
#define musicroom(rx, ry) ((rx) + ((ry) * 20))
@ -38,6 +39,7 @@ public:
int currentsong;
void playef(int t);
void playef_name(std::string& t);
void pauseef(void);
void resumeef(void);

View file

@ -355,7 +355,14 @@ void scriptclass::run(void)
}
if (words[0] == "playef")
{
music.playef(ss_toi(words[1]));
if (words[1] != "0" && ss_toi(words[1]) == 0)
{
music.playef_name(raw_words[1]);
}
else
{
music.playef(ss_toi(words[1]));
}
}
if (words[0] == "play")
{