add notesloader base class

This commit is contained in:
Glenn Maynard
2002-09-11 05:15:46 +00:00
parent 2237a894d2
commit db53dc9923
14 changed files with 141 additions and 52 deletions
+11
View File
@@ -0,0 +1,11 @@
#include "stdafx.h"
#include "NotesLoader.h"
#include "NoteTypes.h"
#include "GameManager.h"
bool NotesLoader::Loadable( CString sPath )
{
CStringArray list;
GetApplicableFiles( sPath, list );
return list.GetSize() != 0;
}
+11
View File
@@ -1,6 +1,8 @@
#ifndef NOTES_LOADER_H
#define NOTES_LOADER_H
#include "song.h"
typedef int DanceNote;
enum {
DANCE_NOTE_NONE = 0,
@@ -18,4 +20,13 @@ enum {
DANCE_NOTE_PAD2_RIGHT
};
class NotesLoader {
protected:
virtual void GetApplicableFiles( CString sPath, CStringArray &out )=0;
public:
virtual bool LoadFromDir( CString sPath, Song &out ) = 0;
bool Loadable( CString sPath );
};
#endif
+7 -2
View File
@@ -272,12 +272,17 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Notes &out, Notes &out2 )
return true;
}
bool BMSLoader::LoadFromBMSDir( CString sDir, Song &out )
void BMSLoader::GetApplicableFiles( CString sPath, CStringArray &out )
{
GetDirListing( sPath + CString("*.bms"), out );
}
bool BMSLoader::LoadFromDir( CString sDir, Song &out )
{
LOG->Trace( "Song::LoadFromBMSDir(%s)", sDir );
CStringArray arrayBMSFileNames;
GetDirListing( sDir + CString("*.bms"), arrayBMSFileNames );
GetApplicableFiles( sDir, arrayBMSFileNames );
if( arrayBMSFileNames.GetSize() == 0 )
throw RageException( "Couldn't find any BMS files in '%s'", sDir );
+3 -2
View File
@@ -5,12 +5,13 @@
#include "Notes.h"
#include "NotesLoader.h"
class BMSLoader {
class BMSLoader: public NotesLoader {
bool LoadFromBMSFile( const CString &sPath, Notes &out1, Notes &out2 );
void mapBMSTrackToDanceNote( int iBMSTrack, int &iDanceColOut, char &cNoteCharOut );
public:
bool LoadFromBMSDir( CString sDir, Song &out );
void GetApplicableFiles( CString sPath, CStringArray &out );
bool LoadFromDir( CString sDir, Song &out );
};
#endif
+21
View File
@@ -382,3 +382,24 @@ bool DWILoader::LoadFromDWIFile( CString sPath, Song &out )
return true;
}
void DWILoader::GetApplicableFiles( CString sPath, CStringArray &out )
{
GetDirListing( sPath + CString("*.dwi"), out );
}
bool DWILoader::LoadFromDir( CString sPath, Song &out )
{
CStringArray aFileNames;
GetApplicableFiles( sPath, aFileNames );
if( aFileNames.GetSize() > 1 )
throw RageException( "There is more than one DWI file in '%s'. There should be only one!", sPath );
/* We should have exactly one; if we had none, we shouldn't have been
* called to begin with. */
ASSERT( aFileNames.GetSize() == 1 );
return LoadFromDWIFile( sPath + aFileNames[0], out );
}
+11 -2
View File
@@ -9,7 +9,12 @@
#include "Song.h"
#include "Notes.h"
class DWILoader {
/* Return NA if no files in the directory can be loaded by
* this loader, OK on success, ERROR if an applicable file was found
* but there was a fatal error loading. (ERROR not used yet--we
* always throw.)
*/
class DWILoader: public NotesLoader {
void DWIcharToNote( char c, GameController i, DanceNote &note1Out, DanceNote &note2Out );
bool LoadFromDWITokens(
@@ -17,8 +22,12 @@ class DWILoader {
CString sStepData2,
Notes &out, Notes &out2);
public:
bool LoadFromDWIFile( CString sPath, Song &out );
public:
void GetApplicableFiles( CString sPath, CStringArray &out );
bool Loadable( CString sPath );
bool LoadFromDir( CString sPath, Song &out );
};
#endif
+5 -1
View File
@@ -143,8 +143,12 @@ bool KSFLoader::LoadFromKSFFile( const CString &sPath, Notes &out )
return true;
}
void KSFLoader::GetApplicableFiles( CString sPath, CStringArray &out )
{
GetDirListing( sPath + CString("*.ksf"), out );
}
bool KSFLoader::LoadFromKSFDir( CString sDir, Song &out )
bool KSFLoader::LoadFromDir( CString sDir, Song &out )
{
LOG->Trace( "Song::LoadFromKSFDir(%s)", sDir );
+4 -2
View File
@@ -3,12 +3,14 @@
#include "Song.h"
#include "Notes.h"
#include "NotesLoader.h"
class KSFLoader {
class KSFLoader: public NotesLoader {
bool LoadFromKSFFile( const CString &sPath, Notes &out );
public:
bool LoadFromKSFDir( CString sDir, Song &out );
void GetApplicableFiles( CString sPath, CStringArray &out );
bool LoadFromDir( CString sDir, Song &out );
};
+21
View File
@@ -42,6 +42,10 @@ void SMLoader::LoadFromSMTokens(
out.TidyUpData();
}
void SMLoader::GetApplicableFiles( CString sPath, CStringArray &out )
{
GetDirListing( sPath + CString("*.sm"), out );
}
bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
{
@@ -208,3 +212,20 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
return true;
}
bool SMLoader::LoadFromDir( CString sPath, Song &out )
{
CStringArray aFileNames;
GetApplicableFiles( sPath, aFileNames );
if( aFileNames.GetSize() > 1 )
throw RageException( "There is more than one SM file in '%s'. There should be only one!", sPath );
/* We should have exactly one; if we had none, we shouldn't have been
* called to begin with. */
ASSERT( aFileNames.GetSize() == 1 );
return LoadFromSMFile( sPath + aFileNames[0], out );
}
+4 -1
View File
@@ -3,8 +3,9 @@
#include "Song.h"
#include "Notes.h"
#include "NotesLoader.h"
class SMLoader {
class SMLoader: public NotesLoader {
void LoadFromSMTokens(
CString sNotesType,
CString sDescription,
@@ -17,6 +18,8 @@ class SMLoader {
public:
bool LoadFromSMFile( CString sPath, Song &out );
void GetApplicableFiles( CString sPath, CStringArray &out );
bool LoadFromDir( CString sPath, Song &out );
};
#endif
+34 -42
View File
@@ -292,60 +292,52 @@ const CString &Song::GetSongFilePath() const
return m_sSongFileName;
}
NotesLoader *Song::MakeLoader( CString sDir ) const
{
NotesLoader *ret;
/* Actually, none of these have any persistant data, so we
* could optimize this, but since they don't have any data,
* there's no real point ... */
ret = new SMLoader;
if(ret->Loadable( sDir )) return ret;
delete ret;
ret = new DWILoader;
if(ret->Loadable( sDir )) return ret;
delete ret;
ret = new BMSLoader;
if(ret->Loadable( sDir )) return ret;
delete ret;
ret = new KSFLoader;
if(ret->Loadable( sDir )) return ret;
delete ret;
return NULL;
}
bool Song::LoadWithoutCache( CString sDir )
{
//
// There was no entry in the cache for this song.
// Let's load it from a file, then write a cache entry.
//
CStringArray arrayBMSFileNames;
GetDirListing( sDir + CString("*.bms"), arrayBMSFileNames );
int iNumBMSFiles = arrayBMSFileNames.GetSize();
CStringArray arrayKSFFileNames;
GetDirListing( sDir + CString("*.ksf"), arrayKSFFileNames );
int iNumKSFFiles = arrayKSFFileNames.GetSize();
CStringArray arrayDWIFileNames;
GetDirListing( sDir + CString("*.dwi"), arrayDWIFileNames );
int iNumDWIFiles = arrayDWIFileNames.GetSize();
CStringArray arraySMFileNames;
GetDirListing( sDir + CString("*.sm"), arraySMFileNames );
int iNumSMFiles = arraySMFileNames.GetSize();
if( iNumSMFiles > 1 )
throw RageException( "There is more than one SM file in '%s'. There should be only one!", sDir );
if( iNumDWIFiles > 1 )
throw RageException( "There is more than one DWI file in '%s'. There should be only one!", sDir );
if( iNumSMFiles == 1 )
{
SMLoader ld;
ld.LoadFromSMFile( sDir + arraySMFileNames[0], *this );
}
else if( iNumDWIFiles == 1 )
{
DWILoader ld;
ld.LoadFromDWIFile( sDir + arrayDWIFileNames[0], *this );
}
else if( iNumBMSFiles > 0 )
{
BMSLoader ld;
ld.LoadFromBMSDir( sDir, *this );
}
else if( iNumKSFFiles > 0 )
{
KSFLoader ld;
ld.LoadFromKSFDir( sDir, *this );
}
else
NotesLoader *ld = MakeLoader( sDir );
if(!ld)
{
LOG->Warn( "Couldn't find any SM, DWI, BMS, or KSF files in '%s'. This is not a valid song directory.", sDir );
return false;
}
bool success = ld->LoadFromDir( sDir, *this );
delete ld;
if(!success)
return false;
AddAutoGenNotes();
TidyUpData();
+4
View File
@@ -318,6 +318,10 @@ SOURCE=.\Notes.h
# End Source File
# Begin Source File
SOURCE=.\NotesLoader.cpp
# End Source File
# Begin Source File
SOURCE=.\NotesLoader.h
# End Source File
# Begin Source File
+3
View File
@@ -445,6 +445,9 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
<File
RelativePath="Notes.h">
</File>
<File
RelativePath="NotesLoader.cpp">
</File>
<File
RelativePath="NotesLoader.h">
</File>
+2
View File
@@ -15,6 +15,7 @@
struct Notes;
class StyleDef;
class NotesLoader;
extern const int FILE_CACHE_VERSION;
@@ -56,6 +57,7 @@ public:
~Song();
bool LoadWithoutCache( CString sDir );
NotesLoader *MakeLoader( CString sDir ) const;
bool LoadFromSongDir( CString sDir );