add notesloader base class
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef NOTES_LOADER_H
|
#ifndef NOTES_LOADER_H
|
||||||
#define NOTES_LOADER_H
|
#define NOTES_LOADER_H
|
||||||
|
|
||||||
|
#include "song.h"
|
||||||
|
|
||||||
typedef int DanceNote;
|
typedef int DanceNote;
|
||||||
enum {
|
enum {
|
||||||
DANCE_NOTE_NONE = 0,
|
DANCE_NOTE_NONE = 0,
|
||||||
@@ -18,4 +20,13 @@ enum {
|
|||||||
DANCE_NOTE_PAD2_RIGHT
|
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
|
#endif
|
||||||
@@ -272,12 +272,17 @@ bool BMSLoader::LoadFromBMSFile( const CString &sPath, Notes &out, Notes &out2 )
|
|||||||
return true;
|
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 );
|
LOG->Trace( "Song::LoadFromBMSDir(%s)", sDir );
|
||||||
|
|
||||||
CStringArray arrayBMSFileNames;
|
CStringArray arrayBMSFileNames;
|
||||||
GetDirListing( sDir + CString("*.bms"), arrayBMSFileNames );
|
GetApplicableFiles( sDir, arrayBMSFileNames );
|
||||||
|
|
||||||
if( arrayBMSFileNames.GetSize() == 0 )
|
if( arrayBMSFileNames.GetSize() == 0 )
|
||||||
throw RageException( "Couldn't find any BMS files in '%s'", sDir );
|
throw RageException( "Couldn't find any BMS files in '%s'", sDir );
|
||||||
|
|||||||
@@ -5,12 +5,13 @@
|
|||||||
#include "Notes.h"
|
#include "Notes.h"
|
||||||
#include "NotesLoader.h"
|
#include "NotesLoader.h"
|
||||||
|
|
||||||
class BMSLoader {
|
class BMSLoader: public NotesLoader {
|
||||||
bool LoadFromBMSFile( const CString &sPath, Notes &out1, Notes &out2 );
|
bool LoadFromBMSFile( const CString &sPath, Notes &out1, Notes &out2 );
|
||||||
void mapBMSTrackToDanceNote( int iBMSTrack, int &iDanceColOut, char &cNoteCharOut );
|
void mapBMSTrackToDanceNote( int iBMSTrack, int &iDanceColOut, char &cNoteCharOut );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool LoadFromBMSDir( CString sDir, Song &out );
|
void GetApplicableFiles( CString sPath, CStringArray &out );
|
||||||
|
bool LoadFromDir( CString sDir, Song &out );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -382,3 +382,24 @@ bool DWILoader::LoadFromDWIFile( CString sPath, Song &out )
|
|||||||
|
|
||||||
return true;
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,12 @@
|
|||||||
#include "Song.h"
|
#include "Song.h"
|
||||||
#include "Notes.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 ¬e1Out, DanceNote ¬e2Out );
|
void DWIcharToNote( char c, GameController i, DanceNote ¬e1Out, DanceNote ¬e2Out );
|
||||||
|
|
||||||
bool LoadFromDWITokens(
|
bool LoadFromDWITokens(
|
||||||
@@ -17,8 +22,12 @@ class DWILoader {
|
|||||||
CString sStepData2,
|
CString sStepData2,
|
||||||
Notes &out, Notes &out2);
|
Notes &out, Notes &out2);
|
||||||
|
|
||||||
public:
|
|
||||||
bool LoadFromDWIFile( CString sPath, Song &out );
|
bool LoadFromDWIFile( CString sPath, Song &out );
|
||||||
|
|
||||||
|
public:
|
||||||
|
void GetApplicableFiles( CString sPath, CStringArray &out );
|
||||||
|
bool Loadable( CString sPath );
|
||||||
|
bool LoadFromDir( CString sPath, Song &out );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -143,8 +143,12 @@ bool KSFLoader::LoadFromKSFFile( const CString &sPath, Notes &out )
|
|||||||
return true;
|
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 );
|
LOG->Trace( "Song::LoadFromKSFDir(%s)", sDir );
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
|
|
||||||
#include "Song.h"
|
#include "Song.h"
|
||||||
#include "Notes.h"
|
#include "Notes.h"
|
||||||
|
#include "NotesLoader.h"
|
||||||
|
|
||||||
class KSFLoader {
|
class KSFLoader: public NotesLoader {
|
||||||
bool LoadFromKSFFile( const CString &sPath, Notes &out );
|
bool LoadFromKSFFile( const CString &sPath, Notes &out );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool LoadFromKSFDir( CString sDir, Song &out );
|
void GetApplicableFiles( CString sPath, CStringArray &out );
|
||||||
|
bool LoadFromDir( CString sDir, Song &out );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ void SMLoader::LoadFromSMTokens(
|
|||||||
out.TidyUpData();
|
out.TidyUpData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SMLoader::GetApplicableFiles( CString sPath, CStringArray &out )
|
||||||
|
{
|
||||||
|
GetDirListing( sPath + CString("*.sm"), out );
|
||||||
|
}
|
||||||
|
|
||||||
bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
|
bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
|
||||||
{
|
{
|
||||||
@@ -208,3 +212,20 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
|
|||||||
|
|
||||||
return true;
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
|
|
||||||
#include "Song.h"
|
#include "Song.h"
|
||||||
#include "Notes.h"
|
#include "Notes.h"
|
||||||
|
#include "NotesLoader.h"
|
||||||
|
|
||||||
class SMLoader {
|
class SMLoader: public NotesLoader {
|
||||||
void LoadFromSMTokens(
|
void LoadFromSMTokens(
|
||||||
CString sNotesType,
|
CString sNotesType,
|
||||||
CString sDescription,
|
CString sDescription,
|
||||||
@@ -17,6 +18,8 @@ class SMLoader {
|
|||||||
public:
|
public:
|
||||||
bool LoadFromSMFile( CString sPath, Song &out );
|
bool LoadFromSMFile( CString sPath, Song &out );
|
||||||
|
|
||||||
|
void GetApplicableFiles( CString sPath, CStringArray &out );
|
||||||
|
bool LoadFromDir( CString sPath, Song &out );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+34
-42
@@ -292,60 +292,52 @@ const CString &Song::GetSongFilePath() const
|
|||||||
return m_sSongFileName;
|
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 )
|
bool Song::LoadWithoutCache( CString sDir )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// There was no entry in the cache for this song.
|
// There was no entry in the cache for this song.
|
||||||
// Let's load it from a file, then write a cache entry.
|
// 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;
|
NotesLoader *ld = MakeLoader( sDir );
|
||||||
GetDirListing( sDir + CString("*.ksf"), arrayKSFFileNames );
|
if(!ld)
|
||||||
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
|
|
||||||
{
|
{
|
||||||
LOG->Warn( "Couldn't find any SM, DWI, BMS, or KSF files in '%s'. This is not a valid song directory.", sDir );
|
LOG->Warn( "Couldn't find any SM, DWI, BMS, or KSF files in '%s'. This is not a valid song directory.", sDir );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool success = ld->LoadFromDir( sDir, *this );
|
||||||
|
delete ld;
|
||||||
|
|
||||||
|
if(!success)
|
||||||
|
return false;
|
||||||
|
|
||||||
AddAutoGenNotes();
|
AddAutoGenNotes();
|
||||||
|
|
||||||
TidyUpData();
|
TidyUpData();
|
||||||
|
|||||||
@@ -318,6 +318,10 @@ SOURCE=.\Notes.h
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\NotesLoader.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\NotesLoader.h
|
SOURCE=.\NotesLoader.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|||||||
@@ -445,6 +445,9 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
|||||||
<File
|
<File
|
||||||
RelativePath="Notes.h">
|
RelativePath="Notes.h">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="NotesLoader.cpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="NotesLoader.h">
|
RelativePath="NotesLoader.h">
|
||||||
</File>
|
</File>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
struct Notes;
|
struct Notes;
|
||||||
class StyleDef;
|
class StyleDef;
|
||||||
|
class NotesLoader;
|
||||||
|
|
||||||
extern const int FILE_CACHE_VERSION;
|
extern const int FILE_CACHE_VERSION;
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ public:
|
|||||||
~Song();
|
~Song();
|
||||||
|
|
||||||
bool LoadWithoutCache( CString sDir );
|
bool LoadWithoutCache( CString sDir );
|
||||||
|
NotesLoader *MakeLoader( CString sDir ) const;
|
||||||
|
|
||||||
bool LoadFromSongDir( CString sDir );
|
bool LoadFromSongDir( CString sDir );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user