From 461e1bcf1a031ec865240fc57fcf62b20a73763e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 15 Jul 2003 00:52:01 +0000 Subject: [PATCH] Don't parse things yourself when there's code to do it ... --- stepmania/src/UnlockSystem.cpp | 58 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/stepmania/src/UnlockSystem.cpp b/stepmania/src/UnlockSystem.cpp index 7fb69daee3..4bb7c36a0c 100644 --- a/stepmania/src/UnlockSystem.cpp +++ b/stepmania/src/UnlockSystem.cpp @@ -21,6 +21,7 @@ #include "SongManager.h" #include "GameState.h" #include "IniFile.h" +#include "MsdFile.h" #include using namespace std; @@ -278,49 +279,50 @@ bool UnlockSystem::LoadFromDATFile( CString sPath ) { LOG->Trace( "UnlockSystem::LoadFromDATFile(%s)", sPath.c_str() ); - ifstream input; - - input.open(sPath); - if(input.fail()) + MsdFile msd; + if( !msd.ReadFile( sPath ) ) { - 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; } - CString unlock_type, song_title; - float datavalue; int MaxRouletteSlot = 0; - int i; + unsigned i; - CString line; - while( getline(input, line) ) + for( i=0; iWarn("Got \"%s\" tag with no parameters", sValueName.c_str()); continue; - - split(parameters[2], ",", UnlockTypes); + } + + if( stricmp(sParams[0],"UNLOCK") ) + { + LOG->Warn("Unrecognized unlock tag \"%s\", ignored.", sValueName); + continue; + } SongEntry current; + current.m_sSongName = sParams[1]; + LOG->Trace("Song entry: %s", current.m_sSongName.c_str() ); - parameters[1].MakeUpper(); //Avoid case-sensitive problems - current.m_sSongName = parameters[1]; - - LOG->Trace("Song entry: %s", parameters[1].c_str() ); + CStringArray UnlockTypes; + split(sParams[2], ",", UnlockTypes); - for(i=0; iTrace("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); if (unlock_type == "AP") @@ -340,13 +342,13 @@ bool UnlockSystem::LoadFromDATFile( CString sPath ) if (unlock_type == "RO") { current.m_iRouletteSeed = (int)datavalue; - if (datavalue > MaxRouletteSlot) - MaxRouletteSlot = (int)datavalue; + MaxRouletteSlot = max( MaxRouletteSlot, (int) datavalue ); } } current.updateLocked(); m_SongEntries.push_back(current); } + InitRouletteSeeds(MaxRouletteSlot); // resize roulette seeds // for more efficient use of file