NotesLoader is just a namespace. If you want to load a particular directory, there's no need to create a specialized loader, just call NotesLoader::LoadFromDir().

This commit is contained in:
Steve Checkoway
2007-02-14 12:26:36 +00:00
parent c827907980
commit 61ae8c3c1b
9 changed files with 56 additions and 84 deletions
+20 -9
View File
@@ -22,18 +22,29 @@ void NotesLoader::GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, R
sSubTitleOut = ""; sSubTitleOut = "";
}; };
NotesLoader *NotesLoader::MakeLoader( const RString &sDir ) bool NotesLoader::LoadFromDir( const RString &sPath, Song &out, set<RString> &BlacklistedImages )
{ {
vector<RString> list; vector<RString> list;
#define CHECK_LOADER(x) x::GetApplicableFiles( sDir, list ); if( list.size() ) return new x BlacklistedImages.clear();
CHECK_LOADER( SMLoader ); SMLoader::GetApplicableFiles( sPath, list );
CHECK_LOADER( DWILoader ); if( !list.empty() )
CHECK_LOADER( BMSLoader ); {
CHECK_LOADER( KSFLoader ); if( !SMLoader::LoadFromDir(sPath, out) )
#undef CHECK_LOADER return false;
SMLoader::TidyUpData( out, false );
return NULL; return true;
}
DWILoader::GetApplicableFiles( sPath, list );
if( !list.empty() )
return DWILoader::LoadFromDir( sPath, out, BlacklistedImages );
BMSLoader::GetApplicableFiles( sPath, list );
if( !list.empty() )
return BMSLoader::LoadFromDir( sPath, out );
KSFLoader::GetApplicableFiles( sPath, list );
if( !list.empty() )
return KSFLoader::LoadFromDir( sPath, out );
return false;
} }
+4 -13
View File
@@ -7,20 +7,11 @@
class Song; class Song;
class NotesLoader namespace NotesLoader
{ {
protected: void GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, RString &sMainTitleOut, RString &sSubTitleOut );
set<RString> BlacklistedImages; bool LoadFromDir( const RString &sPath, Song &out, set<RString> &BlacklistedImages );
}
public:
virtual ~NotesLoader() { }
const set<RString> &GetBlacklistedImages() const { return BlacklistedImages; }
static void GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, RString &sMainTitleOut, RString &sSubTitleOut );
virtual bool LoadFromDir( const RString &sPath, Song &out ) = 0;
virtual void TidyUpData( Song &song, bool cache ) { }
static NotesLoader *MakeLoader( const RString& sDir );
};
#endif #endif
+2 -2
View File
@@ -11,7 +11,7 @@
#include "Steps.h" #include "Steps.h"
#include "RageUtil_CharConversions.h" #include "RageUtil_CharConversions.h"
#include "NoteTypes.h" #include "NoteTypes.h"
#include "NotesLoader.h"
typedef multimap<RString, RString> NameToData_t; typedef multimap<RString, RString> NameToData_t;
typedef map<int, float> MeasureToTimeSig_t; typedef map<int, float> MeasureToTimeSig_t;
@@ -1071,7 +1071,7 @@ bool BMSLoader::LoadFromDir( const RString &sDir, Song &out )
// Prevents clobbering and catches "MySong (7keys)" / "MySong (Another) (7keys)" // Prevents clobbering and catches "MySong (7keys)" / "MySong (Another) (7keys)"
// Also catches "MySong (7keys)" / "MySong (14keys)" // Also catches "MySong (7keys)" / "MySong (14keys)"
if( commonSubstring != "" ) if( commonSubstring != "" )
GetMainAndSubTitlesFromFullTitle( commonSubstring, out.m_sMainTitle, out.m_sSubTitle ); NotesLoader::GetMainAndSubTitlesFromFullTitle( commonSubstring, out.m_sMainTitle, out.m_sSubTitle );
// Now that we've parsed the keysound data, load the Steps from the rest // Now that we've parsed the keysound data, load the Steps from the rest
// of the .bms files. // of the .bms files.
+3 -7
View File
@@ -3,17 +3,13 @@
#ifndef NOTES_LOADER_BMS_H #ifndef NOTES_LOADER_BMS_H
#define NOTES_LOADER_BMS_H #define NOTES_LOADER_BMS_H
#include "NotesLoader.h"
#include <map>
class Song; class Song;
class BMSLoader: public NotesLoader namespace BMSLoader
{ {
public: void GetApplicableFiles( const RString &sPath, vector<RString> &out );
static void GetApplicableFiles( const RString &sPath, vector<RString> &out );
bool LoadFromDir( const RString &sDir, Song &out ); bool LoadFromDir( const RString &sDir, Song &out );
}; }
#endif #endif
+3 -2
View File
@@ -7,9 +7,10 @@
#include "NoteData.h" #include "NoteData.h"
#include "song.h" #include "song.h"
#include "Steps.h" #include "Steps.h"
#include "GameInput.h"
#include "NotesLoader.h"
#include <map> #include <map>
using namespace std;
static std::map<int,int> g_mapDanceNoteToNoteDataColumn; static std::map<int,int> g_mapDanceNoteToNoteDataColumn;
@@ -363,7 +364,7 @@ void DWILoader::GetApplicableFiles( const RString &sPath, vector<RString> &out )
GetDirListing( sPath + RString("*.dwi"), out ); GetDirListing( sPath + RString("*.dwi"), out );
} }
bool DWILoader::LoadFromDir( const RString &sPath_, Song &out ) bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set<RString> &BlacklistedImages )
{ {
vector<RString> aFileNames; vector<RString> aFileNames;
GetApplicableFiles( sPath_, aFileNames ); GetApplicableFiles( sPath_, aFileNames );
+5 -7
View File
@@ -3,17 +3,15 @@
#ifndef NOTES_LOADER_DWI_H #ifndef NOTES_LOADER_DWI_H
#define NOTES_LOADER_DWI_H #define NOTES_LOADER_DWI_H
#include "GameInput.h" #include <set>
#include "NotesLoader.h"
class Song; class Song;
class DWILoader: public NotesLoader namespace DWILoader
{ {
public: void GetApplicableFiles( const RString &sPath, vector<RString> &out );
static void GetApplicableFiles( const RString &sPath, vector<RString> &out ); bool LoadFromDir( const RString &sPath, Song &out, set<RString> &BlacklistedImages );
bool LoadFromDir( const RString &sPath, Song &out ); }
};
#endif #endif
+3 -6
View File
@@ -3,16 +3,13 @@
#ifndef NOTES_LOADER_KSF_H #ifndef NOTES_LOADER_KSF_H
#define NOTES_LOADER_KSF_H #define NOTES_LOADER_KSF_H
#include "NotesLoader.h"
class Song; class Song;
class KSFLoader: public NotesLoader namespace KSFLoader
{ {
public: void GetApplicableFiles( const RString &sPath, vector<RString> &out );
static void GetApplicableFiles( const RString &sPath, vector<RString> &out );
bool LoadFromDir( const RString &sDir, Song &out ); bool LoadFromDir( const RString &sDir, Song &out );
}; }
#endif #endif
+11 -14
View File
@@ -3,7 +3,6 @@
#ifndef NotesLoaderSM_H #ifndef NotesLoaderSM_H
#define NotesLoaderSM_H #define NotesLoaderSM_H
#include "NotesLoader.h"
#include "GameConstantsAndTypes.h" #include "GameConstantsAndTypes.h"
class MsdFile; class MsdFile;
@@ -11,21 +10,19 @@ class Song;
class Steps; class Steps;
class TimingData; class TimingData;
class SMLoader: public NotesLoader namespace SMLoader
{ {
public: bool LoadFromDir( const RString &sPath, Song &out );
SMLoader() {} void TidyUpData( Song &song, bool bFromCache );
virtual bool LoadFromDir( const RString &sPath, Song &out );
virtual void TidyUpData( Song &song, bool bFromCache );
static bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false ); bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false );
static void GetApplicableFiles( const RString &sPath, vector<RString> &out ); void GetApplicableFiles( const RString &sPath, vector<RString> &out );
static bool LoadTimingFromFile( const RString &fn, TimingData &out ); bool LoadTimingFromFile( const RString &fn, TimingData &out );
static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out ); void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out );
static bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
static bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot );
static bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
}; }
#endif #endif
+4 -23
View File
@@ -22,7 +22,7 @@
#include "Foreach.h" #include "Foreach.h"
#include "BackgroundUtil.h" #include "BackgroundUtil.h"
#include "SpecialFiles.h" #include "SpecialFiles.h"
#include "NotesLoader.h"
#include "NotesLoaderSM.h" #include "NotesLoaderSM.h"
#include "NotesWriterDWI.h" #include "NotesWriterDWI.h"
#include "NotesWriterSM.h" #include "NotesWriterSM.h"
@@ -208,8 +208,7 @@ bool Song::LoadFromSongDir( RString sDir )
{ {
// LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() ); // LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() );
SMLoader::LoadFromSMFile( GetCacheFilePath(), *this, true ); SMLoader::LoadFromSMFile( GetCacheFilePath(), *this, true );
// XXX: This shouldn't really be a non-static member function. SMLoader::TidyUpData( *this, true );
SMLoader().TidyUpData( *this, true );
} }
else else
{ {
@@ -218,24 +217,7 @@ bool Song::LoadFromSongDir( RString sDir )
// Let's load it from a file, then write a cache entry. // Let's load it from a file, then write a cache entry.
// //
NotesLoader *ld = NotesLoader::MakeLoader( sDir ); if( !NotesLoader::LoadFromDir(sDir, *this, BlacklistedImages) )
if( ld )
{
bool success = ld->LoadFromDir( sDir, *this );
BlacklistedImages = ld->GetBlacklistedImages();
if(!success)
{
delete ld;
return false;
}
TidyUpData();
ld->TidyUpData( *this, false );
delete ld;
}
else
{ {
LOG->UserLog( "Song", sDir, "has no SM, DWI, BMS, or KSF files." ); LOG->UserLog( "Song", sDir, "has no SM, DWI, BMS, or KSF files." );
@@ -251,9 +233,8 @@ bool Song::LoadFromSongDir( RString sDir )
} }
// Continue on with a blank Song so that people can make adjustments using the editor. // Continue on with a blank Song so that people can make adjustments using the editor.
TidyUpData();
} }
TidyUpData();
// save a cache file so we don't have to parse it all over again next time // save a cache file so we don't have to parse it all over again next time
SaveToCacheFile(); SaveToCacheFile();
} }