Add conditional song prompt

This commit is contained in:
Jack Andersen 2016-05-31 17:05:13 -10:00
parent 08de4873f4
commit 44204d7b08
1 changed files with 63 additions and 28 deletions

View File

@ -696,46 +696,79 @@ struct AppCallback : boo::IApplicationCallback
#else #else
const char* utf8Path = m_argv[2]; const char* utf8Path = m_argv[2];
#endif #endif
songs = amuse::ContainerRegistry::LoadSongs(utf8Path);
}
else
songs = amuse::ContainerRegistry::LoadSongs(utf8Path); songs = amuse::ContainerRegistry::LoadSongs(utf8Path);
/* Get song selection from user */ if (songs.size())
if (songs.size() > 1) {
bool play = true;
if (m_argc <= 2)
{ {
/* Ask user to specify which song */ bool prompt = true;
printf("Multiple Songs discovered:\n"); while (true)
int idx = 0;
for (const auto& pair : songs)
{ {
printf(" %d %s (Group %d, Setup %d)\n", idx++, if (prompt)
pair.first.c_str(), pair.second.m_groupId, pair.second.m_setupId); {
printf("Play Song? (Y/N): ");
prompt = false;
}
char userSel;
if (scanf("%c", &userSel) <= 0 || userSel == '\n')
continue;
userSel = tolower(userSel);
if (userSel == 'n')
play = false;
else if (userSel != 'y')
{
prompt = true;
continue;
}
break;
} }
}
int userSel = 0; if (play)
printf("Enter Song Number: "); {
if (scanf("%d", &userSel) <= 0) /* Get song selection from user */
if (songs.size() > 1)
{ {
Log.report(logvisor::Error, "unable to parse prompt"); /* Ask user to specify which song */
exit(1); printf("Multiple Songs discovered:\n");
int idx = 0;
for (const auto& pair : songs)
{
printf(" %d %s (Group %d, Setup %d)\n", idx++,
pair.first.c_str(), pair.second.m_groupId, pair.second.m_setupId);
}
int userSel = 0;
printf("Enter Song Number: ");
if (scanf("%d", &userSel) <= 0)
{
Log.report(logvisor::Error, "unable to parse prompt");
exit(1);
}
if (userSel < songs.size())
{
m_arrData = &songs[userSel].second;
m_groupId = m_arrData->m_groupId;
m_setupId = m_arrData->m_setupId;
}
else
{
Log.report(logvisor::Error, "unable to find Song %d", userSel);
exit(1);
}
} }
else if (songs.size() == 1)
if (userSel < songs.size())
{ {
m_arrData = &songs[userSel].second; m_arrData = &songs[0].second;
m_groupId = m_arrData->m_groupId; m_groupId = m_arrData->m_groupId;
m_setupId = m_arrData->m_setupId; m_setupId = m_arrData->m_setupId;
} }
else
{
Log.report(logvisor::Error, "unable to find Song %d", userSel);
exit(1);
}
}
else if (songs.size() == 1)
{
m_arrData = &songs[0].second;
m_groupId = m_arrData->m_groupId;
m_setupId = m_arrData->m_setupId;
} }
} }
@ -859,6 +892,8 @@ struct AppCallback : boo::IApplicationCallback
SFXLoop(*sfxIndex); SFXLoop(*sfxIndex);
else else
SongLoop(*songIndex); SongLoop(*songIndex);
printf("\n\n");
} }
return 0; return 0;