Follow openmw style guide

pull/390/head
Daniel Vukelich 7 years ago
parent 97924d97c7
commit f09fd6795c

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

@ -1,18 +1,18 @@
#ifndef GAME_STATE_QUICKSAVEMANAGER_H #ifndef GAME_STATE_QUICKSAVEMANAGER_H
#define GAME_STATE_QUICKSAVEMANAGER_H #define GAME_STATE_QUICKSAVEMANAGER_H
#include <string>
#include "character.hpp" #include "character.hpp"
#include "../mwbase/statemanager.hpp" #include "../mwbase/statemanager.hpp"
#include <string>
namespace MWState{ namespace MWState{
class QuickSaveManager{ class QuickSaveManager{
std::string saveName; std::string mSaveName;
int maxSaves; int mMaxSaves;
int slotsVisited; int mSlotsVisited;
int oldestSlotId; int mOldestSlotId;
const Slot *oldestSlotVisited; const Slot *mOldestSlotVisited;
private: private:
bool tryExtractSlotId(const std::string &slotName, int &extractedIdll); bool tryExtractSlotId(const std::string &slotName, int &extractedIdll);
bool isSlotIdValid(int slotId); bool isSlotIdValid(int slotId);

Loading…
Cancel
Save