@ -1,27 +1,20 @@
# include "quicksavemanager.hpp"
# include "quicksavemanager.hpp"
# include <sstream>
MWState : : QuickSaveManager : : QuickSaveManager ( std : : string & saveName , unsigned int maxSaves )
MWState : : QuickSaveManager : : QuickSaveManager ( std : : string & saveName , unsigned int maxSaves )
{
{
this - > mSaveName = saveName ;
this - > mSaveName = saveName ;
this - > mMaxSaves = maxSaves ;
this - > mMaxSaves = maxSaves ;
this - > mOldestSlotVisited = NULL ;
this - > mOldestSlotVisited = NULL ;
this - > mOldestSlotId = 0 ;
this - > mSlotsVisited = 0 ;
this - > mSlotsVisited = 0 ;
}
}
void MWState : : QuickSaveManager : : visitSave ( const Slot * saveSlot )
void MWState : : QuickSaveManager : : visitSave ( const Slot * saveSlot )
{
{
unsigned int slotId ;
if ( mSaveName = = saveSlot - > mProfile . mDescription )
if ( tryExtractSlotId ( saveSlot - > mProfile . mDescription , slotId ) )
{
{
+ + mSlotsVisited ;
+ + mSlotsVisited ;
if ( isOldestSave ( saveSlot ) )
if ( isOldestSave ( saveSlot ) )
{
mOldestSlotVisited = saveSlot ;
mOldestSlotVisited = saveSlot ;
mOldestSlotId = slotId ;
}
}
}
}
}
@ -32,29 +25,6 @@ bool MWState::QuickSaveManager::isOldestSave(const Slot *compare)
return ( compare - > mTimeStamp < = mOldestSlotVisited - > mTimeStamp ) ;
return ( compare - > mTimeStamp < = mOldestSlotVisited - > mTimeStamp ) ;
}
}
bool MWState : : QuickSaveManager : : tryExtractSlotId ( const std : : string & slotName , unsigned int & extractedId )
{
std : : istringstream formattedExtractor ( slotName ) ;
std : : string nameToTest ;
formattedExtractor > > nameToTest ;
if ( nameToTest = = mSaveName )
{
//Only try to extract the id if maxSaves > 1
//With maxSaves == 1, we don't append the slotId to the name
if ( formattedExtractor > > extractedId )
return ( isSlotIdValid ( extractedId ) ) ;
else if ( mMaxSaves = = 1 )
return formattedExtractor . eof ( ) ;
}
return false ;
}
bool MWState : : QuickSaveManager : : isSlotIdValid ( unsigned int slotId )
{
return ( slotId > 0 & & slotId < = mMaxSaves ) ;
}
bool MWState : : QuickSaveManager : : shouldCreateNewSlot ( )
bool MWState : : QuickSaveManager : : shouldCreateNewSlot ( )
{
{
return ( mSlotsVisited < mMaxSaves ) ;
return ( mSlotsVisited < mMaxSaves ) ;
@ -66,20 +36,3 @@ const MWState::Slot *MWState::QuickSaveManager::getNextQuickSaveSlot()
return NULL ;
return NULL ;
return mOldestSlotVisited ;
return mOldestSlotVisited ;
}
}
std : : string MWState : : QuickSaveManager : : getNextQuickSaveName ( )
{
std : : ostringstream nameFormatter ;
nameFormatter < < mSaveName ;
//Only print the number if there will be more than 1
if ( mMaxSaves > 1 )
nameFormatter < < " " < < calcNextSlotId ( ) ;
return nameFormatter . str ( ) ;
}
int MWState : : QuickSaveManager : : calcNextSlotId ( )
{
if ( shouldCreateNewSlot ( ) )
return ( mSlotsVisited + 1 ) ;
return mOldestSlotId ;
}