Fix the sound bonanza so they actually play

sfx player and blip player now both account for extension-less sound paths and also correctly handle paths that do provide the extension.
This commit is contained in:
Crystalwarrior 2019-11-04 17:13:52 +03:00
parent d402921257
commit 9939637dda
4 changed files with 13 additions and 15 deletions

View File

@ -9,7 +9,7 @@ AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
void AOBlipPlayer::set_blips(QString p_sfx)
{
QString f_path = ao_app->get_sounds_path(p_sfx);
QString f_path = ao_app->get_sfx_suffix(ao_app->get_sounds_path(p_sfx));
for (int n_stream = 0 ; n_stream < 5 ; ++n_stream)
{

View File

@ -40,12 +40,12 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout, int channel
QString misc_path = "";
QString char_path = "";
QString sound_path = ao_app->get_sounds_path(p_sfx);
QString sound_path = ao_app->get_sfx_suffix(ao_app->get_sounds_path(p_sfx));
if (shout != "")
misc_path = ao_app->get_base_path() + "misc/" + shout + "/" + p_sfx;
misc_path = ao_app->get_sfx_suffix(ao_app->get_base_path() + "misc/" + shout + "/" + p_sfx);
if (p_char != "")
char_path = ao_app->get_character_path(p_char, p_sfx);
char_path = ao_app->get_sfx_suffix(ao_app->get_character_path(p_char, p_sfx));
QString f_path;
@ -56,9 +56,6 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout, int channel
else
f_path = sound_path;
if (!file_exists(f_path))
f_path = ao_app->get_sfx_suffix(f_path); //If we're not given a sound file with .wav/.ogg/.opus already there, let's do this thing
if (f_path.endsWith(".opus"))
m_stream_list[channel] = BASS_OPUS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE);
else

View File

@ -1818,7 +1818,6 @@ void Courtroom::handle_chatmessage_2()
int other_offset = m_chatmessage[OTHER_OFFSET].toInt();
ui_vp_sideplayer_char->move(ui_viewport->width() * other_offset / 100, 0);
qDebug() << "other offset" << other_offset;
QStringList args = m_chatmessage[OTHER_CHARID].split("^");
if (args.size() > 1) //This ugly workaround is so we don't make an extra packet just for this purpose. Rewrite pairing when?
@ -1914,7 +1913,6 @@ void Courtroom::do_screenshake()
int rng = qrand();//QRandomGenerator::global()->generate();
int rand_x = max_x - (int(rng) % (max_x*2));
int rand_y = max_y - (int(rng+100) % (max_y*2));
qDebug() << rand_x << rand_y;
screenshake_animation->setKeyValueAt(fraction, QPoint(pos_default.x() + rand_x, pos_default.y() + rand_y));
}
screenshake_animation->setEndValue(pos_default);
@ -1947,12 +1945,12 @@ void Courtroom::do_effect(QString fx_name, QString fx_sound, QString p_char)
ui_vp_effect->set_play_once(false); // The effects themselves dictate whether or not they're looping. Static effects will linger.
ui_vp_effect->play(effect); // It will set_play_once to true if the filepath provided is not designed to loop more than once
if (fx_sound != "")
sfx_player->play(ao_app->get_sfx_suffix(fx_sound));
sfx_player->play(fx_sound);
}
void Courtroom::play_char_sfx(QString sfx_name)
{
sfx_player->play(ao_app->get_sfx_suffix(sfx_name));
sfx_player->play(sfx_name);
if(ao_app->get_looping_sfx())
sfx_player->set_looping(ao_app->get_sfx_looping(current_char, QString::number(current_emote))!="0");
}
@ -2690,7 +2688,7 @@ void Courtroom::play_sfx()
if (sfx_name == "1")
return;
sfx_player->play(ao_app->get_sfx_suffix(sfx_name));
sfx_player->play(sfx_name);
if(ao_app->get_looping_sfx())
sfx_player->set_looping(ao_app->get_sfx_looping(current_char, sfx_name)!="0");
}

View File

@ -527,7 +527,8 @@ QString AOApplication::get_sfx(QString p_identifier)
QString AOApplication::get_sfx_suffix(QString sound_to_check)
{
sound_to_check = get_sounds_path(sound_to_check);
if (sound_to_check.contains(".")) //We have what we could call a file extension
return sound_to_check;
if (file_exists(sound_to_check + ".opus"))
return sound_to_check + ".opus";
if (file_exists(sound_to_check + ".ogg"))
@ -541,6 +542,8 @@ QString AOApplication::get_sfx_suffix(QString sound_to_check)
QString AOApplication::get_image_suffix(QString path_to_check)
{
if (path_to_check.contains(".")) //We have what we could call a file extension
return path_to_check;
if (file_exists(path_to_check + ".webp"))
return path_to_check + ".webp";
if (file_exists(path_to_check + ".apng"))
@ -629,9 +632,9 @@ QString AOApplication::get_gender(QString p_char)
if (f_result == "")
return "sfx-blipmale";
if (!file_exists(get_sfx_suffix(get_sfx(f_result))))
if (!file_exists(get_sfx_suffix(get_sounds_path(f_result))))
{
if (file_exists(get_sfx_suffix(get_sfx("blips/" + f_result))))
if (file_exists(get_sfx_suffix(get_sounds_path("blips/" + f_result))))
return "blips/" + f_result; //Return the cool kids variant
return "sfx-blip" + f_result; //Return legacy variant