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
+21 -10
View File
@@ -22,18 +22,29 @@ void NotesLoader::GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, R
sSubTitleOut = "";
};
NotesLoader *NotesLoader::MakeLoader( const RString &sDir )
bool NotesLoader::LoadFromDir( const RString &sPath, Song &out, set<RString> &BlacklistedImages )
{
vector<RString> list;
#define CHECK_LOADER(x) x::GetApplicableFiles( sDir, list ); if( list.size() ) return new x
CHECK_LOADER( SMLoader );
CHECK_LOADER( DWILoader );
CHECK_LOADER( BMSLoader );
CHECK_LOADER( KSFLoader );
#undef CHECK_LOADER
return NULL;
BlacklistedImages.clear();
SMLoader::GetApplicableFiles( sPath, list );
if( !list.empty() )
{
if( !SMLoader::LoadFromDir(sPath, out) )
return false;
SMLoader::TidyUpData( out, false );
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 NotesLoader
namespace NotesLoader
{
protected:
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 );
};
void GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, RString &sMainTitleOut, RString &sSubTitleOut );
bool LoadFromDir( const RString &sPath, Song &out, set<RString> &BlacklistedImages );
}
#endif
+2 -2
View File
@@ -11,7 +11,7 @@
#include "Steps.h"
#include "RageUtil_CharConversions.h"
#include "NoteTypes.h"
#include "NotesLoader.h"
typedef multimap<RString, RString> NameToData_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)"
// Also catches "MySong (7keys)" / "MySong (14keys)"
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
// of the .bms files.
+3 -7
View File
@@ -3,17 +3,13 @@
#ifndef NOTES_LOADER_BMS_H
#define NOTES_LOADER_BMS_H
#include "NotesLoader.h"
#include <map>
class Song;
class BMSLoader: public NotesLoader
namespace BMSLoader
{
public:
static void GetApplicableFiles( const RString &sPath, vector<RString> &out );
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
bool LoadFromDir( const RString &sDir, Song &out );
};
}
#endif
+3 -2
View File
@@ -7,9 +7,10 @@
#include "NoteData.h"
#include "song.h"
#include "Steps.h"
#include "GameInput.h"
#include "NotesLoader.h"
#include <map>
using namespace std;
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 );
}
bool DWILoader::LoadFromDir( const RString &sPath_, Song &out )
bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set<RString> &BlacklistedImages )
{
vector<RString> aFileNames;
GetApplicableFiles( sPath_, aFileNames );
+5 -7
View File
@@ -3,17 +3,15 @@
#ifndef NOTES_LOADER_DWI_H
#define NOTES_LOADER_DWI_H
#include "GameInput.h"
#include "NotesLoader.h"
#include <set>
class Song;
class DWILoader: public NotesLoader
namespace DWILoader
{
public:
static void GetApplicableFiles( const RString &sPath, vector<RString> &out );
bool LoadFromDir( const RString &sPath, Song &out );
};
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
bool LoadFromDir( const RString &sPath, Song &out, set<RString> &BlacklistedImages );
}
#endif
+3 -6
View File
@@ -3,16 +3,13 @@
#ifndef NOTES_LOADER_KSF_H
#define NOTES_LOADER_KSF_H
#include "NotesLoader.h"
class Song;
class KSFLoader: public NotesLoader
namespace KSFLoader
{
public:
static void GetApplicableFiles( const RString &sPath, vector<RString> &out );
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
bool LoadFromDir( const RString &sDir, Song &out );
};
}
#endif
+11 -14
View File
@@ -3,7 +3,6 @@
#ifndef NotesLoaderSM_H
#define NotesLoaderSM_H
#include "NotesLoader.h"
#include "GameConstantsAndTypes.h"
class MsdFile;
@@ -11,21 +10,19 @@ class Song;
class Steps;
class TimingData;
class SMLoader: public NotesLoader
namespace SMLoader
{
public:
SMLoader() {}
virtual bool LoadFromDir( const RString &sPath, Song &out );
virtual void TidyUpData( Song &song, bool bFromCache );
bool LoadFromDir( const RString &sPath, Song &out );
void TidyUpData( Song &song, bool bFromCache );
static bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false );
static void GetApplicableFiles( const RString &sPath, vector<RString> &out );
static bool LoadTimingFromFile( const RString &fn, TimingData &out );
static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out );
static bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
static bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot );
static bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
};
bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false );
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
bool LoadTimingFromFile( const RString &fn, TimingData &out );
void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out );
bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot );
bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
}
#endif
+4 -23
View File
@@ -22,7 +22,7 @@
#include "Foreach.h"
#include "BackgroundUtil.h"
#include "SpecialFiles.h"
#include "NotesLoader.h"
#include "NotesLoaderSM.h"
#include "NotesWriterDWI.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() );
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
{
@@ -218,24 +217,7 @@ bool Song::LoadFromSongDir( RString sDir )
// Let's load it from a file, then write a cache entry.
//
NotesLoader *ld = NotesLoader::MakeLoader( sDir );
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
if( !NotesLoader::LoadFromDir(sDir, *this, BlacklistedImages) )
{
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.
TidyUpData();
}
TidyUpData();
// save a cache file so we don't have to parse it all over again next time
SaveToCacheFile();
}