Don't parse things yourself when there's code to do it ...

This commit is contained in:
Glenn Maynard
2003-07-15 00:52:01 +00:00
parent 0598ee4050
commit 461e1bcf1a
+29 -27
View File
@@ -21,6 +21,7 @@
#include "SongManager.h" #include "SongManager.h"
#include "GameState.h" #include "GameState.h"
#include "IniFile.h" #include "IniFile.h"
#include "MsdFile.h"
#include <fstream> #include <fstream>
using namespace std; using namespace std;
@@ -278,49 +279,50 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
{ {
LOG->Trace( "UnlockSystem::LoadFromDATFile(%s)", sPath.c_str() ); LOG->Trace( "UnlockSystem::LoadFromDATFile(%s)", sPath.c_str() );
ifstream input; MsdFile msd;
if( !msd.ReadFile( sPath ) )
input.open(sPath);
if(input.fail())
{ {
LOG->Warn( "Error opening file '%s' for reading.", sPath.c_str() ); LOG->Warn( "Error opening file '%s' for reading: %s.", sPath.c_str(), msd.GetError().c_str() );
return false; return false;
} }
CString unlock_type, song_title;
float datavalue;
int MaxRouletteSlot = 0; int MaxRouletteSlot = 0;
int i; unsigned i;
CString line; for( i=0; i<msd.GetNumValues(); i++ )
while( getline(input, line) )
{ {
CStringArray parameters; int iNumParams = msd.GetNumParams(i);
CStringArray UnlockTypes; const MsdFile::value_t &sParams = msd.GetValue(i);
CString sValueName = sParams[0];
split(line, ":", parameters); if(iNumParams < 1)
{
if (parameters[0] != "#UNLOCK") LOG->Warn("Got \"%s\" tag with no parameters", sValueName.c_str());
continue; continue;
}
split(parameters[2], ",", UnlockTypes); if( stricmp(sParams[0],"UNLOCK") )
{
LOG->Warn("Unrecognized unlock tag \"%s\", ignored.", sValueName);
continue;
}
SongEntry current; SongEntry current;
current.m_sSongName = sParams[1];
LOG->Trace("Song entry: %s", current.m_sSongName.c_str() );
parameters[1].MakeUpper(); //Avoid case-sensitive problems CStringArray UnlockTypes;
current.m_sSongName = parameters[1]; split(sParams[2], ",", UnlockTypes);
LOG->Trace("Song entry: %s", parameters[1].c_str() ); for( unsigned j=0; j<UnlockTypes.size(); ++j )
for(i=0; i<UnlockTypes.size(); i++)
{ {
CStringArray readparam; CStringArray readparam;
split(UnlockTypes[i], "=", readparam); split(UnlockTypes[j], "=", readparam);
unlock_type = readparam[0]; CString unlock_type = readparam[0];
datavalue = atof(readparam[1]); float datavalue = (float) atof(readparam[1]);
LOG->Trace("UnlockTypes line: %s", UnlockTypes[i].c_str() ); LOG->Trace("UnlockTypes line: %s", UnlockTypes[j].c_str() );
LOG->Trace("Unlock info: %s %f", unlock_type.c_str(), datavalue); LOG->Trace("Unlock info: %s %f", unlock_type.c_str(), datavalue);
if (unlock_type == "AP") if (unlock_type == "AP")
@@ -340,13 +342,13 @@ bool UnlockSystem::LoadFromDATFile( CString sPath )
if (unlock_type == "RO") if (unlock_type == "RO")
{ {
current.m_iRouletteSeed = (int)datavalue; current.m_iRouletteSeed = (int)datavalue;
if (datavalue > MaxRouletteSlot) MaxRouletteSlot = max( MaxRouletteSlot, (int) datavalue );
MaxRouletteSlot = (int)datavalue;
} }
} }
current.updateLocked(); current.updateLocked();
m_SongEntries.push_back(current); m_SongEntries.push_back(current);
} }
InitRouletteSeeds(MaxRouletteSlot); // resize roulette seeds InitRouletteSeeds(MaxRouletteSlot); // resize roulette seeds
// for more efficient use of file // for more efficient use of file