Files
itgmania212121/stepmania/src/NotesLoaderSM.cpp
T

289 lines
8.5 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-09-06 23:24:40 +00:00
#include "NotesLoaderSM.h"
#include "GameManager.h"
#include "RageException.h"
#include "MsdFile.h"
#include "RageLog.h"
2002-09-07 11:43:36 +00:00
#include "RageUtil.h"
2002-09-06 23:24:40 +00:00
void SMLoader::LoadFromSMTokens(
CString sNotesType,
CString sDescription,
2002-09-29 05:06:18 +00:00
CString sDifficulty,
2002-09-06 23:24:40 +00:00
CString sMeter,
CString sRadarValues,
CString sNoteData,
Notes &out
)
{
2002-10-31 08:05:13 +00:00
TrimLeft(sNotesType);
TrimRight(sNotesType);
TrimLeft(sDescription);
TrimRight(sDescription);
TrimLeft(sDifficulty);
TrimRight(sDifficulty);
2002-09-06 23:24:40 +00:00
// LOG->Trace( "Notes::LoadFromSMTokens()" );
out.m_NotesType = GameManager::StringToNotesType(sNotesType);
2003-01-02 22:10:51 +00:00
out.SetDescription(sDescription);
out.SetDifficulty(StringToDifficulty( sDifficulty ));
2003-01-21 23:07:22 +00:00
// HACK: We used to store SMANIAC as DIFFICULTY_HARD with special description.
// Now, it has it's own DIFFICULTY_CHALLENGE
if( sDescription.CompareNoCase("smaniac") == 0 )
out.SetDifficulty( DIFFICULTY_CHALLENGE );
// HACK: We used to store CHALLENGE as DIFFICULTY_HARD with special description.
// Now, it has it's own DIFFICULTY_CHALLENGE
if( sDescription.CompareNoCase("challenge") == 0 )
out.SetDifficulty( DIFFICULTY_CHALLENGE );
2003-01-02 22:10:51 +00:00
out.SetMeter(atoi(sMeter));
2002-09-06 23:24:40 +00:00
CStringArray saValues;
split( sRadarValues, ",", saValues, true );
2003-01-30 07:18:33 +00:00
if( saValues.size() == NUM_RADAR_CATEGORIES )
for( int r=0; r<NUM_RADAR_CATEGORIES; r++ )
2003-01-02 22:10:51 +00:00
out.SetRadarValue(r, (float)atof(saValues[r]));
2002-09-06 23:24:40 +00:00
2002-12-14 21:41:34 +00:00
out.SetSMNoteData(sNoteData);
2002-09-06 23:24:40 +00:00
out.TidyUpData();
}
2002-09-11 05:15:46 +00:00
void SMLoader::GetApplicableFiles( CString sPath, CStringArray &out )
{
GetDirListing( sPath + CString("*.sm"), out );
}
2002-09-06 23:24:40 +00:00
bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
{
LOG->Trace( "Song::LoadFromSMDir(%s)", sPath.GetString() );
2002-09-06 23:24:40 +00:00
2002-10-24 20:15:24 +00:00
out.m_BPMSegments.clear();
out.m_StopSegments.clear();
2002-09-06 23:24:40 +00:00
MsdFile msd;
bool bResult = msd.ReadFile( sPath );
if( !bResult )
2002-12-21 18:36:10 +00:00
RageException::Throw( "Error opening file '%s'.", sPath.GetString() );
2002-09-06 23:24:40 +00:00
2003-01-14 22:10:04 +00:00
for( unsigned i=0; i<msd.GetNumValues(); i++ )
2002-09-06 23:24:40 +00:00
{
2003-01-14 22:44:30 +00:00
int iNumParams = msd.GetNumParams(i);
const MsdFile::value_t &sParams = msd.GetValue(i);
2002-09-06 23:24:40 +00:00
CString sValueName = sParams[0];
// handle the data
if( 0==stricmp(sValueName,"TITLE") )
GetMainAndSubTitlesFromFullTitle( sParams[1], out.m_sMainTitle, out.m_sSubTitle );
2002-09-06 23:24:40 +00:00
else if( 0==stricmp(sValueName,"SUBTITLE") )
out.m_sSubTitle = sParams[1];
else if( 0==stricmp(sValueName,"ARTIST") )
out.m_sArtist = sParams[1];
else if( 0==stricmp(sValueName,"TITLETRANSLIT") )
out.m_sMainTitleTranslit = sParams[1];
else if( 0==stricmp(sValueName,"SUBTITLETRANSLIT") )
out.m_sSubTitleTranslit = sParams[1];
else if( 0==stricmp(sValueName,"ARTISTTRANSLIT") )
out.m_sArtistTranslit = sParams[1];
2002-09-06 23:24:40 +00:00
else if( 0==stricmp(sValueName,"CREDIT") )
out.m_sCredit = sParams[1];
else if( 0==stricmp(sValueName,"BANNER") )
out.m_sBannerFile = sParams[1];
else if( 0==stricmp(sValueName,"BACKGROUND") )
out.m_sBackgroundFile = sParams[1];
else if( 0==stricmp(sValueName,"CDTITLE") )
out.m_sCDTitleFile = sParams[1];
else if( 0==stricmp(sValueName,"MUSIC") )
out.m_sMusicFile = sParams[1];
else if( 0==stricmp(sValueName,"MUSICBYTES") )
out.m_iMusicBytes = atoi( sParams[1] );
else if( 0==stricmp(sValueName,"MUSICLENGTH") )
out.m_fMusicLengthSeconds = (float)atof( sParams[1] );
/* We calculate these. Some SMs in circulation have bogus values for
* these, so make sure we always calculate it ourself. */
2002-09-06 23:24:40 +00:00
else if( 0==stricmp(sValueName,"FIRSTBEAT") )
{
if(!FromCache)
{
LOG->Trace("Ignored #FIRSTBEAT (cache only)");
continue;
}
2002-09-06 23:24:40 +00:00
out.m_fFirstBeat = (float)atof( sParams[1] );
}
2002-09-06 23:24:40 +00:00
else if( 0==stricmp(sValueName,"LASTBEAT") )
{
if(!FromCache)
{
LOG->Trace("Ignored #LASTBEAT (cache only)");
continue;
}
2002-09-06 23:24:40 +00:00
out.m_fLastBeat = (float)atof( sParams[1] );
}
2002-09-06 23:24:40 +00:00
else if( 0==stricmp(sValueName,"SAMPLESTART") )
out.m_fMusicSampleStartSeconds = TimeToSeconds( sParams[1] );
else if( 0==stricmp(sValueName,"SAMPLELENGTH") )
out.m_fMusicSampleLengthSeconds = TimeToSeconds( sParams[1] );
else if( 0==stricmp(sValueName,"OFFSET") )
out.m_fBeat0OffsetInSeconds = (float)atof( sParams[1] );
else if( 0==stricmp(sValueName,"SELECTABLE") )
{
if(!stricmp(sParams[1],"YES"))
out.m_SelectionDisplay = out.SHOW_ALWAYS;
else if(!stricmp(sParams[1],"NO"))
out.m_SelectionDisplay = out.SHOW_NEVER;
else if(!stricmp(sParams[1],"ROULETTE"))
out.m_SelectionDisplay = out.SHOW_ROULETTE;
else
LOG->Warn( "The song file '%s' has an unknown #SELECTABLE value, '%s'; ignored.", sPath.GetString(), sParams[1].GetString());
2002-09-06 23:24:40 +00:00
}
else if( 0==stricmp(sValueName,"STOPS") || 0==stricmp(sValueName,"FREEZES") )
{
CStringArray arrayFreezeExpressions;
split( sParams[1], ",", arrayFreezeExpressions );
for( unsigned f=0; f<arrayFreezeExpressions.size(); f++ )
2002-09-06 23:24:40 +00:00
{
CStringArray arrayFreezeValues;
split( arrayFreezeExpressions[f], "=", arrayFreezeValues );
2003-03-04 06:23:12 +00:00
/* XXX: Once we have a way to display warnings that the user actually
* cares about (unlike most warnings), this should be one of them. */
if(arrayFreezeValues.size() != 2)
{
LOG->Warn("Invalid #%s value \"%s\" (must have exactly one '='), ignored",
sValueName.GetString(), arrayFreezeExpressions[f].GetString());
continue;
}
2002-09-06 23:24:40 +00:00
float fFreezeBeat = (float)atof( arrayFreezeValues[0] );
float fFreezeSeconds = (float)atof( arrayFreezeValues[1] );
StopSegment new_seg;
new_seg.m_fStartBeat = fFreezeBeat;
new_seg.m_fStopSeconds = fFreezeSeconds;
2003-01-24 02:18:28 +00:00
// LOG->Trace( "Adding a freeze segment: beat: %f, seconds = %f", new_seg.m_fStartBeat, new_seg.m_fStopSeconds );
2002-09-06 23:24:40 +00:00
out.AddStopSegment( new_seg );
}
}
else if( 0==stricmp(sValueName,"BPMS") )
{
CStringArray arrayBPMChangeExpressions;
split( sParams[1], ",", arrayBPMChangeExpressions );
for( unsigned b=0; b<arrayBPMChangeExpressions.size(); b++ )
2002-09-06 23:24:40 +00:00
{
CStringArray arrayBPMChangeValues;
split( arrayBPMChangeExpressions[b], "=", arrayBPMChangeValues );
2003-03-04 06:23:12 +00:00
/* XXX: Once we have a way to display warnings that the user actually
* cares about (unlike most warnings), this should be one of them. */
if(arrayBPMChangeValues.size() != 2)
{
LOG->Warn("Invalid #%s value \"%s\" (must have exactly one '='), ignored",
sValueName.GetString(), arrayBPMChangeExpressions[b].GetString());
continue;
}
2002-09-06 23:24:40 +00:00
float fBeat = (float)atof( arrayBPMChangeValues[0] );
float fNewBPM = (float)atof( arrayBPMChangeValues[1] );
BPMSegment new_seg;
new_seg.m_fStartBeat = fBeat;
new_seg.m_fBPM = fNewBPM;
out.AddBPMSegment( new_seg );
}
}
else if( 0==stricmp(sValueName,"BGCHANGES") || 0==stricmp(sValueName,"ANIMATIONS") )
2002-09-06 23:24:40 +00:00
{
CStringArray aBGChangeExpressions;
split( sParams[1], ",", aBGChangeExpressions );
for( unsigned b=0; b<aBGChangeExpressions.size(); b++ )
2002-09-06 23:24:40 +00:00
{
CStringArray aBGChangeValues;
split( aBGChangeExpressions[b], "=", aBGChangeValues );
2003-03-04 06:23:12 +00:00
/* XXX: Once we have a way to display warnings that the user actually
* cares about (unlike most warnings), this should be one of them. */
if(aBGChangeValues.size() != 2)
{
LOG->Warn("Invalid #%s value \"%s\" (must have exactly one '='), ignored",
sValueName.GetString(), aBGChangeExpressions[b].GetString());
continue;
}
2002-09-06 23:24:40 +00:00
float fBeat = (float)atof( aBGChangeValues[0] );
CString sBGName = aBGChangeValues[1];
sBGName.MakeLower();
out.AddBackgroundChange( BackgroundChange(fBeat, sBGName) );
}
}
else if( 0==stricmp(sValueName,"NOTES") )
{
Notes* pNewNotes = new Notes;
ASSERT( pNewNotes );
2002-10-31 04:23:39 +00:00
out.m_apNotes.push_back( pNewNotes );
2002-09-06 23:24:40 +00:00
if( iNumParams != 7 )
2002-10-06 16:56:58 +00:00
{
LOG->Trace( "The song file '%s' is has %d fields in a #NOTES tag, but should have %d.", sPath.GetString(), iNumParams, 7 );
2002-12-14 21:41:34 +00:00
continue;
2002-10-06 16:56:58 +00:00
}
2002-09-06 23:24:40 +00:00
2002-12-14 21:41:34 +00:00
LoadFromSMTokens(
sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6],
*pNewNotes);
}
2002-09-06 23:24:40 +00:00
else
LOG->Trace( "Unexpected value named '%s'", sValueName.GetString() );
2002-09-06 23:24:40 +00:00
}
out.m_sBannerFile.Replace("\\", "/");
out.m_sBackgroundFile.Replace("\\", "/");
out.m_sCDTitleFile.Replace("\\", "/");
out.m_sMusicFile.Replace("\\", "/");
2002-09-06 23:24:40 +00:00
return true;
}
2002-09-11 05:15:46 +00:00
bool SMLoader::LoadFromDir( CString sPath, Song &out )
{
CStringArray aFileNames;
GetApplicableFiles( sPath, aFileNames );
if( aFileNames.size() > 1 )
2002-12-21 18:36:10 +00:00
RageException::Throw( "There is more than one SM file in '%s'. There should be only one!", sPath.GetString() );
2002-09-11 05:15:46 +00:00
/* We should have exactly one; if we had none, we shouldn't have been
* called to begin with. */
ASSERT( aFileNames.size() == 1 );
2002-09-11 05:15:46 +00:00
return LoadFromSMFile( sPath + aFileNames[0], out );
}