Added functions to ActorUtil for converting the extension to a file type and changed various places that had lists of extensions to use ActorUtil instead of duplicating the list of extensions. Added webm and wmv to list of video types.
This commit is contained in:
+100
-38
@@ -499,55 +499,117 @@ void ActorUtil::SortByZPosition( vector<Actor*> &vActors )
|
||||
}
|
||||
|
||||
static const char *FileTypeNames[] = {
|
||||
"Bitmap",
|
||||
"Bitmap",
|
||||
"Sprite",
|
||||
"Sound",
|
||||
"Movie",
|
||||
"Directory",
|
||||
"Sound",
|
||||
"Movie",
|
||||
"Directory",
|
||||
"Xml",
|
||||
"Model",
|
||||
"Lua",
|
||||
"Model",
|
||||
"Lua",
|
||||
"Ini",
|
||||
};
|
||||
XToString( FileType );
|
||||
LuaXType( FileType );
|
||||
|
||||
// convenience so the for-loop lines can be shorter.
|
||||
typedef map<RString, FileType> etft_cont_t;
|
||||
typedef map<FileType, vector<RString> > fttel_cont_t;
|
||||
etft_cont_t ExtensionToFileType;
|
||||
fttel_cont_t FileTypeToExtensionList;
|
||||
|
||||
void ActorUtil::InitFileTypeLists()
|
||||
{
|
||||
// This function creates things to serve two purposes:
|
||||
// 1. A map from extensions to filetypes, so extensions can be converted.
|
||||
// 2. A reverse map for things that need a list of extensions to look for.
|
||||
// The first section creates the map from extensions to filetypes, then the
|
||||
// second section uses that map to build the reverse map.
|
||||
ExtensionToFileType["lua"]= FT_Lua;
|
||||
|
||||
ExtensionToFileType["xml"]= FT_Xml;
|
||||
|
||||
ExtensionToFileType["ini"]= FT_Ini;
|
||||
|
||||
// Update RageSurfaceUtils when adding new image formats.
|
||||
ExtensionToFileType["bmp"]= FT_Bitmap;
|
||||
ExtensionToFileType["gif"]= FT_Bitmap;
|
||||
ExtensionToFileType["jpeg"]= FT_Bitmap;
|
||||
ExtensionToFileType["jpg"]= FT_Bitmap;
|
||||
ExtensionToFileType["png"]= FT_Bitmap;
|
||||
|
||||
// Update RageSoundReader_FileReader when adding new sound formats.
|
||||
ExtensionToFileType["mp3"]= FT_Sound;
|
||||
ExtensionToFileType["oga"]= FT_Sound;
|
||||
ExtensionToFileType["ogg"]= FT_Sound;
|
||||
ExtensionToFileType["wav"]= FT_Sound;
|
||||
|
||||
// ffmpeg takes care of loading videos, not sure whether this list should
|
||||
// have everything ffmpeg supports.
|
||||
ExtensionToFileType["avi"]= FT_Movie;
|
||||
ExtensionToFileType["f4v"]= FT_Movie;
|
||||
ExtensionToFileType["flv"]= FT_Movie;
|
||||
ExtensionToFileType["mkv"]= FT_Movie;
|
||||
ExtensionToFileType["mp4"]= FT_Movie;
|
||||
ExtensionToFileType["mpeg"]= FT_Movie;
|
||||
ExtensionToFileType["mpg"]= FT_Movie;
|
||||
ExtensionToFileType["mov"]= FT_Movie;
|
||||
ExtensionToFileType["ogv"]= FT_Movie;
|
||||
ExtensionToFileType["webm"]= FT_Movie;
|
||||
ExtensionToFileType["wmv"]= FT_Movie;
|
||||
|
||||
ExtensionToFileType["sprite"]= FT_Sprite;
|
||||
|
||||
ExtensionToFileType["txt"]= FT_Model;
|
||||
|
||||
// When adding new extensions, do not add them below this line. This line
|
||||
// marks the point where the function switches to building the reverse map.
|
||||
for(etft_cont_t::iterator curr_ext= ExtensionToFileType.begin();
|
||||
curr_ext != ExtensionToFileType.end(); ++curr_ext)
|
||||
{
|
||||
FileTypeToExtensionList[curr_ext->second].push_back(curr_ext->first);
|
||||
}
|
||||
}
|
||||
|
||||
vector<RString> const& ActorUtil::GetTypeExtensionList(FileType ft)
|
||||
{
|
||||
return FileTypeToExtensionList[ft];
|
||||
}
|
||||
|
||||
void ActorUtil::AddTypeExtensionsToList(FileType ft, vector<RString>& add_to)
|
||||
{
|
||||
fttel_cont_t::iterator ext_list= FileTypeToExtensionList.find(ft);
|
||||
if(ext_list != FileTypeToExtensionList.end())
|
||||
{
|
||||
add_to.reserve(add_to.size() + ext_list->second.size());
|
||||
for(vector<RString>::iterator curr= ext_list->second.begin();
|
||||
curr != ext_list->second.end(); ++curr)
|
||||
{
|
||||
add_to.push_back(*curr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileType ActorUtil::GetFileType( const RString &sPath )
|
||||
{
|
||||
RString sExt = GetExtension( sPath );
|
||||
sExt.MakeLower();
|
||||
|
||||
if( sExt=="lua" ) return FT_Lua;
|
||||
else if(sExt=="xml") return FT_Xml;
|
||||
else if(
|
||||
sExt=="png" ||
|
||||
sExt=="jpg" ||
|
||||
sExt=="jpeg" ||
|
||||
sExt=="gif" ||
|
||||
sExt=="bmp" ) return FT_Bitmap;
|
||||
else if(
|
||||
sExt=="ogg" ||
|
||||
sExt=="oga" ||
|
||||
sExt=="wav" ||
|
||||
sExt=="mp3" ) return FT_Sound;
|
||||
else if(
|
||||
sExt=="ogv" ||
|
||||
sExt=="avi" ||
|
||||
sExt=="mpeg" ||
|
||||
sExt=="mp4" ||
|
||||
sExt=="mkv" ||
|
||||
sExt=="mov" ||
|
||||
sExt=="flv" ||
|
||||
sExt=="f4v" ||
|
||||
sExt=="mpg" ) return FT_Movie;
|
||||
else if(
|
||||
sExt=="sprite" ) return FT_Sprite;
|
||||
else if(
|
||||
sExt=="txt" ) return FT_Model;
|
||||
else if( sPath.size() > 0 && sPath[sPath.size()-1] == '/' )
|
||||
return FT_Directory;
|
||||
|
||||
etft_cont_t::iterator conversion_entry= ExtensionToFileType.find(sExt);
|
||||
if(conversion_entry != ExtensionToFileType.end())
|
||||
{
|
||||
return conversion_entry->second;
|
||||
}
|
||||
else if(sPath.size() > 0 && sPath[sPath.size()-1] == '/')
|
||||
{
|
||||
return FT_Directory;
|
||||
}
|
||||
/* Do this last, to avoid the IsADirectory in most cases. */
|
||||
else if( IsADirectory(sPath) ) return FT_Directory;
|
||||
else return FileType_Invalid;
|
||||
else if(IsADirectory(sPath))
|
||||
{
|
||||
return FT_Directory;
|
||||
}
|
||||
return FileType_Invalid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user