2018-01-12 20:02:43 -05:00
|
|
|
#include "quicksavemanager.hpp"
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
MWState::QuickSaveManager::QuickSaveManager(std::string& saveName, unsigned int maxSaves)
|
|
|
|
: mSaveName(saveName)
|
|
|
|
, mMaxSaves(maxSaves)
|
|
|
|
, mSlotsVisited(0)
|
|
|
|
, mOldestSlotVisited(nullptr)
|
2018-01-12 20:02:43 -05:00
|
|
|
{
|
2018-01-12 20:02:43 -05:00
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void MWState::QuickSaveManager::visitSave(const Slot* saveSlot)
|
2018-01-12 20:02:43 -05:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (mSaveName == saveSlot->mProfile.mDescription)
|
2018-01-12 20:02:43 -05:00
|
|
|
{
|
|
|
|
++mSlotsVisited;
|
2022-09-22 21:26:05 +03:00
|
|
|
if (isOldestSave(saveSlot))
|
2018-01-12 20:02:43 -05:00
|
|
|
mOldestSlotVisited = saveSlot;
|
2018-01-12 20:02:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool MWState::QuickSaveManager::isOldestSave(const Slot* compare) const
|
2018-01-12 20:02:43 -05:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (mOldestSlotVisited == nullptr)
|
2018-01-12 20:02:43 -05:00
|
|
|
return true;
|
2018-01-12 20:02:43 -05:00
|
|
|
return (compare->mTimeStamp <= mOldestSlotVisited->mTimeStamp);
|
2018-01-12 20:02:43 -05:00
|
|
|
}
|
|
|
|
|
2021-03-29 19:44:23 +02:00
|
|
|
bool MWState::QuickSaveManager::shouldCreateNewSlot() const
|
2018-01-12 20:02:43 -05:00
|
|
|
{
|
|
|
|
return (mSlotsVisited < mMaxSaves);
|
2018-01-12 20:02:43 -05:00
|
|
|
}
|
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
const MWState::Slot* MWState::QuickSaveManager::getNextQuickSaveSlot()
|
2018-01-12 20:02:43 -05:00
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
if (shouldCreateNewSlot())
|
2018-10-09 10:21:12 +04:00
|
|
|
return nullptr;
|
2018-01-12 20:02:43 -05:00
|
|
|
return mOldestSlotVisited;
|
2018-01-12 20:02:43 -05:00
|
|
|
}
|