mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2025-08-04 16:38:22 +00:00
Add warning for playef
command and lower sound IDs
Ethan mentioned how case sensitivity could be a concern -- this commit lowers the filename to create the sound ID, and also strips spaces. Script arguments are always lowered, and the spaces get removed, so the IDs are modified to match this behavior. If someone types in the command `playef(horses REALLY COOL)`, the argument will get converted to `horsesreallycool`. Likewise, the filename "horses REALLY COOL.wav" will get converted to `horsesreallycool`. To the level creator, they can just enter the same name twice and their sound will play. This commit also adds a warning for the `playef` script command. While most creators do not open the console, some warning somewhere is better than nothing. I do think we should eventually have some sort of system where it's easier to view level warnings, but for now this should be sufficient.
This commit is contained in:
parent
33cce8372c
commit
87788cd615
3 changed files with 48 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -448,13 +448,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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue