implement announcer alternates, for compatibility
This commit is contained in:
@@ -20,6 +20,19 @@ AnnouncerManager* ANNOUNCER = NULL; // global object accessable from anywhere in
|
||||
const CString EMPTY_ANNOUNCER_NAME = "Empty";
|
||||
const CString ANNOUNCERS_DIR = "Announcers/";
|
||||
|
||||
/* XXX: move to RageUtil when I feel like spending 20 minutes recompiling */
|
||||
/* Return true if "dir" is empty or does not exist. */
|
||||
static bool DirectoryIsEmpty( CString dir )
|
||||
{
|
||||
if(dir == "")
|
||||
return true;
|
||||
if(!DoesFileExist(dir))
|
||||
return true;
|
||||
|
||||
CStringArray asFileNames;
|
||||
GetDirListing( dir, asFileNames );
|
||||
return asFileNames.empty();
|
||||
}
|
||||
|
||||
AnnouncerManager::AnnouncerManager()
|
||||
{
|
||||
@@ -67,32 +80,77 @@ void AnnouncerManager::SwitchAnnouncer( CString sNewAnnouncerName )
|
||||
m_sCurAnnouncerName = sNewAnnouncerName;
|
||||
}
|
||||
|
||||
/* Aliases for announcer paths. This is for compatibility, so we don't force
|
||||
* announcer changes along with everything else. We could use it to support
|
||||
* DWI announcers transparently, too. */
|
||||
static const char *aliases[][2] = {
|
||||
/* ScreenSelectDifficulty compatibility: */
|
||||
{ "ScreenSelectDifficulty comment arcade-beginner", "select difficulty comment beginner" },
|
||||
{ "ScreenSelectDifficulty comment arcade-easy", "select difficulty comment easy" },
|
||||
{ "ScreenSelectDifficulty comment arcade-medium", "select difficulty comment medium" },
|
||||
{ "ScreenSelectDifficulty comment arcade-hard", "select difficulty comment hard" },
|
||||
{ "ScreenSelectDifficulty comment oni", "select difficulty comment oni" },
|
||||
{ "ScreenSelectDifficulty comment nonstop", "select difficulty comment nonstop" },
|
||||
{ "ScreenSelectDifficulty comment endless", "select difficulty comment endless" },
|
||||
{ "ScreenSelectDifficulty intro", "select difficulty intro" },
|
||||
|
||||
/* ScreenSelectStyle compatibility: */
|
||||
{ "ScreenSelectStyle intro", "select style intro" },
|
||||
{ "ScreenSelectStyle comment single", "select style comment single" },
|
||||
{ "ScreenSelectStyle comment double", "select style comment double" },
|
||||
{ "ScreenSelectStyle comment solo", "select style comment solo" },
|
||||
{ "ScreenSelectStyle comment versus", "select style comment versus" },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/* Find an announcer directory with sounds in it. First search sFolderName,
|
||||
* then all aliases above. Ignore directories that are empty, since we might
|
||||
* have "select difficulty intro" with sounds and an empty "ScreenSelectDifficulty
|
||||
* intro". */
|
||||
CString AnnouncerManager::GetPathTo( CString sAnnouncerName, CString sFolderName )
|
||||
{
|
||||
if(sAnnouncerName == "")
|
||||
return ""; /* announcer disabled */
|
||||
|
||||
const CString AnnouncerPath = GetAnnouncerDirFromName(sAnnouncerName);
|
||||
|
||||
if( !DirectoryIsEmpty(AnnouncerPath+sFolderName+"/") )
|
||||
return AnnouncerPath+sFolderName+"/";
|
||||
|
||||
/* Search for the announcer folder in the list of aliases. */
|
||||
int i;
|
||||
for(i = 0; aliases[i][0] != NULL; ++i)
|
||||
{
|
||||
if(sFolderName.CompareNoCase(aliases[i][0]))
|
||||
continue; /* no match */
|
||||
|
||||
if( !DirectoryIsEmpty(AnnouncerPath+aliases[i][1]+"/") )
|
||||
return AnnouncerPath+aliases[i][1]+"/";
|
||||
}
|
||||
|
||||
/* No announcer directory matched. In debug, create the directory by
|
||||
* its preferred name. */
|
||||
#ifdef DEBUG
|
||||
LOG->Trace( "The announcer in \"%s\" is missing the folder '%s'.",
|
||||
AnnouncerPath.GetString(), sFolderName.GetString() );
|
||||
// MessageBeep( MB_OK );
|
||||
CreateDirectories( AnnouncerPath+sFolderName );
|
||||
#endif
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
CString AnnouncerManager::GetPathTo( CString sFolderName )
|
||||
{
|
||||
CString sPathToFolderCurrent = GetAnnouncerDirFromName(m_sCurAnnouncerName) + sFolderName;
|
||||
CString sPathToFolderEmpty = GetAnnouncerDirFromName(EMPTY_ANNOUNCER_NAME) + sFolderName;
|
||||
CString sPath = GetPathTo(m_sCurAnnouncerName, sFolderName);
|
||||
if(sPath != "")
|
||||
return sPath;
|
||||
|
||||
#ifdef DEBUG
|
||||
if( m_sCurAnnouncerName!="" && !DoesFileExist(sPathToFolderCurrent) )
|
||||
{
|
||||
LOG->Trace( "The current announcer is missing the folder '%s'.", sFolderName.GetString() );
|
||||
// MessageBeep( MB_OK );
|
||||
CreateDirectories( sPathToFolderCurrent );
|
||||
}
|
||||
if( !DoesFileExist(sPathToFolderEmpty) )
|
||||
{
|
||||
LOG->Trace( "The empty announcer is missing the folder '%s'.", sFolderName.GetString() );
|
||||
// MessageBeep( MB_OK );
|
||||
CreateDirectories( sPathToFolderEmpty );
|
||||
}
|
||||
#endif
|
||||
|
||||
return sPathToFolderCurrent;
|
||||
return GetPathTo(EMPTY_ANNOUNCER_NAME, sFolderName);
|
||||
}
|
||||
|
||||
bool AnnouncerManager::HasSoundsFor( CString sFolderName )
|
||||
{
|
||||
CStringArray asFileNames;
|
||||
GetDirListing( GetPathTo(sFolderName), asFileNames );
|
||||
return !asFileNames.empty();
|
||||
return !DirectoryIsEmpty( GetPathTo(sFolderName) );
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
|
||||
protected:
|
||||
static CString GetAnnouncerDirFromName( CString sAnnouncerName );
|
||||
CString GetPathTo( CString AnnouncerPath, CString sFolderName );
|
||||
|
||||
CString m_sCurAnnouncerName;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user