mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 00:09:50 +00:00
Make the creation of save file directories even more explicit
This commit is contained in:
parent
b7b7c0612d
commit
a0cc9de088
6 changed files with 41 additions and 33 deletions
|
@ -78,8 +78,8 @@ namespace MWBase
|
||||||
/** Used for quickload **/
|
/** Used for quickload **/
|
||||||
virtual void quickLoad()=0;
|
virtual void quickLoad()=0;
|
||||||
|
|
||||||
virtual MWState::Character *getCurrentCharacter (bool create = true) = 0;
|
virtual MWState::Character *getCurrentCharacter () = 0;
|
||||||
///< \param create Create a new character, if there is no current character.
|
///< @note May return null.
|
||||||
|
|
||||||
virtual CharacterIterator characterBegin() = 0;
|
virtual CharacterIterator characterBegin() = 0;
|
||||||
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
||||||
|
|
|
@ -132,7 +132,7 @@ namespace MWGui
|
||||||
if (mgr->characterBegin() == mgr->characterEnd())
|
if (mgr->characterBegin() == mgr->characterEnd())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mCurrentCharacter = mgr->getCurrentCharacter (false);
|
mCurrentCharacter = mgr->getCurrentCharacter();
|
||||||
|
|
||||||
std::string directory =
|
std::string directory =
|
||||||
Misc::StringUtils::lowerCase (Settings::Manager::getString ("character", "Saves"));
|
Misc::StringUtils::lowerCase (Settings::Manager::getString ("character", "Saves"));
|
||||||
|
@ -202,7 +202,7 @@ namespace MWGui
|
||||||
|
|
||||||
if (!load)
|
if (!load)
|
||||||
{
|
{
|
||||||
mCurrentCharacter = MWBase::Environment::get().getStateManager()->getCurrentCharacter (false);
|
mCurrentCharacter = MWBase::Environment::get().getStateManager()->getCurrentCharacter();
|
||||||
}
|
}
|
||||||
|
|
||||||
center();
|
center();
|
||||||
|
|
|
@ -32,11 +32,8 @@ MWState::CharacterManager::CharacterManager (const boost::filesystem::path& save
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MWState::Character *MWState::CharacterManager::getCurrentCharacter (bool create, const std::string& name)
|
MWState::Character *MWState::CharacterManager::getCurrentCharacter ()
|
||||||
{
|
{
|
||||||
if (!mCurrent && create)
|
|
||||||
createCharacter(name);
|
|
||||||
|
|
||||||
return mCurrent;
|
return mCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +53,7 @@ void MWState::CharacterManager::deleteSlot(const MWState::Character *character,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWState::CharacterManager::createCharacter(const std::string& name)
|
MWState::Character* MWState::CharacterManager::createCharacter(const std::string& name)
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
|
|
||||||
|
@ -82,8 +79,7 @@ void MWState::CharacterManager::createCharacter(const std::string& name)
|
||||||
}
|
}
|
||||||
|
|
||||||
mCharacters.push_back (Character (path, mGame));
|
mCharacters.push_back (Character (path, mGame));
|
||||||
|
return &mCharacters.back();
|
||||||
mCurrent = &mCharacters.back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<MWState::Character>::iterator MWState::CharacterManager::findCharacter(const MWState::Character* character)
|
std::list<MWState::Character>::iterator MWState::CharacterManager::findCharacter(const MWState::Character* character)
|
||||||
|
|
|
@ -31,13 +31,12 @@ namespace MWState
|
||||||
|
|
||||||
CharacterManager (const boost::filesystem::path& saves, const std::string& game);
|
CharacterManager (const boost::filesystem::path& saves, const std::string& game);
|
||||||
|
|
||||||
Character *getCurrentCharacter (bool create, const std::string& name);
|
Character *getCurrentCharacter ();
|
||||||
///< \param create Create a new character, if there is no current character.
|
///< @note May return null
|
||||||
/// \param name The character name to use in case a new character is created.
|
|
||||||
|
|
||||||
void deleteSlot(const MWState::Character *character, const MWState::Slot *slot);
|
void deleteSlot(const MWState::Character *character, const MWState::Slot *slot);
|
||||||
|
|
||||||
void createCharacter(const std::string& name);
|
Character* createCharacter(const std::string& name);
|
||||||
///< Create new character within saved game management
|
///< Create new character within saved game management
|
||||||
/// \param name Name for the character (does not need to be unique)
|
/// \param name Name for the character (does not need to be unique)
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ void MWState::StateManager::askLoadRecent()
|
||||||
|
|
||||||
if( !mAskLoadRecent )
|
if( !mAskLoadRecent )
|
||||||
{
|
{
|
||||||
const MWState::Character* character = getCurrentCharacter(false);
|
const MWState::Character* character = getCurrentCharacter();
|
||||||
if(!character || character->begin() == character->end())//no saves
|
if(!character || character->begin() == character->end())//no saves
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
|
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
|
||||||
|
@ -173,6 +173,16 @@ void MWState::StateManager::endGame()
|
||||||
|
|
||||||
void MWState::StateManager::saveGame (const std::string& description, const Slot *slot)
|
void MWState::StateManager::saveGame (const std::string& description, const Slot *slot)
|
||||||
{
|
{
|
||||||
|
MWState::Character* character = getCurrentCharacter();
|
||||||
|
if (!character)
|
||||||
|
{
|
||||||
|
MWWorld::ConstPtr player = MWMechanics::getPlayer();
|
||||||
|
std::string name = player.get<ESM::NPC>()->mBase->mName;
|
||||||
|
|
||||||
|
character = mCharacterManager.createCharacter(name);
|
||||||
|
mCharacterManager.setCurrentCharacter(character);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ESM::SavedGame profile;
|
ESM::SavedGame profile;
|
||||||
|
@ -204,9 +214,9 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
|
||||||
writeScreenshot(profile.mScreenshot);
|
writeScreenshot(profile.mScreenshot);
|
||||||
|
|
||||||
if (!slot)
|
if (!slot)
|
||||||
slot = getCurrentCharacter(true)->createSlot (profile);
|
slot = character->createSlot (profile);
|
||||||
else
|
else
|
||||||
slot = getCurrentCharacter(true)->updateSlot (slot, profile);
|
slot = character->updateSlot (slot, profile);
|
||||||
|
|
||||||
// Write to a memory stream first. If there is an exception during the save process, we don't want to trash the
|
// Write to a memory stream first. If there is an exception during the save process, we don't want to trash the
|
||||||
// existing save file we are overwriting.
|
// existing save file we are overwriting.
|
||||||
|
@ -290,7 +300,10 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot
|
||||||
|
|
||||||
// If no file was written, clean up the slot
|
// If no file was written, clean up the slot
|
||||||
if (slot && !boost::filesystem::exists(slot->mPath))
|
if (slot && !boost::filesystem::exists(slot->mPath))
|
||||||
getCurrentCharacter(true)->deleteSlot(slot);
|
{
|
||||||
|
character->deleteSlot(slot);
|
||||||
|
character->cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,13 +319,16 @@ void MWState::StateManager::quickSave (std::string name)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Slot* slot = NULL;
|
const Slot* slot = NULL;
|
||||||
Character* mCurrentCharacter = getCurrentCharacter(true); //Get current character
|
Character* currentCharacter = getCurrentCharacter(); //Get current character
|
||||||
|
|
||||||
//Find quicksave slot
|
//Find quicksave slot
|
||||||
for (Character::SlotIterator it = mCurrentCharacter->begin(); it != mCurrentCharacter->end(); ++it)
|
if (currentCharacter)
|
||||||
{
|
{
|
||||||
if (it->mProfile.mDescription == name)
|
for (Character::SlotIterator it = currentCharacter->begin(); it != currentCharacter->end(); ++it)
|
||||||
slot = &*it;
|
{
|
||||||
|
if (it->mProfile.mDescription == name)
|
||||||
|
slot = &*it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveGame(name, slot);
|
saveGame(name, slot);
|
||||||
|
@ -334,7 +350,7 @@ void MWState::StateManager::loadGame(const std::string& filepath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MWState::Character* character = getCurrentCharacter(false);
|
MWState::Character* character = getCurrentCharacter();
|
||||||
loadGame(character, filepath);
|
loadGame(character, filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +522,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str
|
||||||
|
|
||||||
void MWState::StateManager::quickLoad()
|
void MWState::StateManager::quickLoad()
|
||||||
{
|
{
|
||||||
if (Character* currentCharacter = getCurrentCharacter (false))
|
if (Character* currentCharacter = getCurrentCharacter ())
|
||||||
{
|
{
|
||||||
if (currentCharacter->begin() == currentCharacter->end())
|
if (currentCharacter->begin() == currentCharacter->end())
|
||||||
return;
|
return;
|
||||||
|
@ -519,12 +535,9 @@ void MWState::StateManager::deleteGame(const MWState::Character *character, cons
|
||||||
mCharacterManager.deleteSlot(character, slot);
|
mCharacterManager.deleteSlot(character, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
MWState::Character *MWState::StateManager::getCurrentCharacter (bool create)
|
MWState::Character *MWState::StateManager::getCurrentCharacter ()
|
||||||
{
|
{
|
||||||
MWWorld::ConstPtr player = MWMechanics::getPlayer();
|
return mCharacterManager.getCurrentCharacter();
|
||||||
std::string name = player.get<ESM::NPC>()->mBase->mName;
|
|
||||||
|
|
||||||
return mCharacterManager.getCurrentCharacter (create, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MWState::StateManager::CharacterIterator MWState::StateManager::characterBegin()
|
MWState::StateManager::CharacterIterator MWState::StateManager::characterBegin()
|
||||||
|
@ -545,7 +558,7 @@ void MWState::StateManager::update (float duration)
|
||||||
if (mAskLoadRecent)
|
if (mAskLoadRecent)
|
||||||
{
|
{
|
||||||
int iButton = MWBase::Environment::get().getWindowManager()->readPressedButton();
|
int iButton = MWBase::Environment::get().getWindowManager()->readPressedButton();
|
||||||
MWState::Character *curCharacter = getCurrentCharacter(false);
|
MWState::Character *curCharacter = getCurrentCharacter();
|
||||||
if(iButton==0 && curCharacter)
|
if(iButton==0 && curCharacter)
|
||||||
{
|
{
|
||||||
mAskLoadRecent = false;
|
mAskLoadRecent = false;
|
||||||
|
|
|
@ -73,8 +73,8 @@ namespace MWState
|
||||||
virtual void loadGame (const Character *character, const std::string &filepath);
|
virtual void loadGame (const Character *character, const std::string &filepath);
|
||||||
///< Load a saved game file belonging to the given character.
|
///< Load a saved game file belonging to the given character.
|
||||||
|
|
||||||
virtual Character *getCurrentCharacter (bool create);
|
virtual Character *getCurrentCharacter ();
|
||||||
///< \param create Create a new character, if there is no current character.
|
///< @note May return null.
|
||||||
|
|
||||||
virtual CharacterIterator characterBegin();
|
virtual CharacterIterator characterBegin();
|
||||||
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
///< Any call to SaveGame and getCurrentCharacter can invalidate the returned
|
||||||
|
|
Loading…
Reference in a new issue