|
|
|
|
#pragma region License
|
|
|
|
|
/*
|
|
|
|
|
License (OLC-3)
|
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Copyright 2018 - 2022 OneLoneCoder.com
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
1. Redistributions or derivations of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
|
|
|
|
|
2. Redistributions or derivative works in binary form must reproduce the above
|
|
|
|
|
copyright notice. This list of conditions and the following disclaimer must be
|
|
|
|
|
reproduced in the documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
3. Neither the name of the copyright holder nor the names of its contributors may
|
|
|
|
|
be used to endorse or promote products derived from this software without specific
|
|
|
|
|
prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
|
|
|
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
|
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
Portions of this software are copyright <EFBFBD> 2023 The FreeType
|
|
|
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
|
|
|
All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
#pragma endregion
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "Item.h"
|
|
|
|
|
#include "Crawler.h"
|
|
|
|
|
#include "Unlock.h"
|
|
|
|
|
#include "State_OverworldMap.h"
|
|
|
|
|
#include "SaveFile.h"
|
|
|
|
|
|
|
|
|
|
INCLUDE_game
|
|
|
|
|
|
|
|
|
|
size_t SaveFile::saveFileID=0;
|
|
|
|
|
std::string SaveFile::saveFileName="";
|
|
|
|
|
|
|
|
|
|
const size_t SaveFile::GetSaveFileCount(){
|
|
|
|
|
size_t count=0;
|
|
|
|
|
for(auto&path:std::filesystem::directory_iterator("save_file_path"_S)){
|
|
|
|
|
if(path.is_regular_file()){
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const void SaveFile::SaveGame(){
|
|
|
|
|
utils::datafile saveFile;
|
|
|
|
|
utils::datafile::INITIAL_SETUP_COMPLETE=false;
|
|
|
|
|
for(size_t itemCount=0;auto&[name,item]:Inventory::_inventory){
|
|
|
|
|
saveFile["Items"][std::format("Item[{}]",itemCount)]["Amt"].SetInt(item->Amt());
|
|
|
|
|
saveFile["Items"][std::format("Item[{}]",itemCount)]["Enhancement Level"].SetInt(item->EnhancementLevel());
|
|
|
|
|
saveFile["Items"][std::format("Item[{}]",itemCount)]["Item Name"].SetString(item->ActualName());
|
|
|
|
|
saveFile["Items"][std::format("Item[{}]",itemCount)]["Equip Slot"].SetInt(int(Inventory::GetSlotEquippedIn(item)));
|
|
|
|
|
for(const auto&[attr,val]:item->RandomStats()){
|
|
|
|
|
saveFile["Items"][std::format("Item[{}]",itemCount)]["Attributes"][std::string(attr.ActualName())].SetReal(val);
|
|
|
|
|
}
|
|
|
|
|
itemCount++;
|
|
|
|
|
}
|
|
|
|
|
saveFile["Player"]["Class"].SetString(game->GetPlayer()->GetClassName());
|
|
|
|
|
saveFile["Player"]["Level"].SetInt(game->GetPlayer()->Level());
|
|
|
|
|
saveFile["Player"]["Current EXP"].SetInt(game->GetPlayer()->CurrentXP());
|
|
|
|
|
saveFile["Player"]["Total EXP"].SetInt(game->GetPlayer()->TotalXP());
|
|
|
|
|
for(const auto&[attr,val]:game->GetPlayer()->GetBaseStats()){
|
|
|
|
|
saveFile["Player"]["Base Stats"][std::string(attr.ActualName())].SetReal(val);
|
|
|
|
|
}
|
|
|
|
|
for(const std::string&unlockName:Unlock::unlocks){
|
|
|
|
|
saveFile["Unlocks"][unlockName].SetString("True");
|
|
|
|
|
}
|
|
|
|
|
saveFile["Overworld Map Location"].SetString(State_OverworldMap::GetCurrentConnectionPoint().name);
|
|
|
|
|
saveFile["Chapter"].SetInt(game->GetCurrentChapter());
|
|
|
|
|
saveFile["Save Name"].SetString(std::string(GetSaveFileName()));
|
|
|
|
|
utils::datafile::INITIAL_SETUP_COMPLETE=true;
|
|
|
|
|
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string_view SaveFile::GetSaveFileName(){
|
|
|
|
|
return saveFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const void SaveFile::SetSaveFileName(std::string_view saveFileName){
|
|
|
|
|
SaveFile::saveFileName=saveFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const void SaveFile::SetSaveFileID(size_t saveFileID){
|
|
|
|
|
SaveFile::saveFileID=saveFileID;
|
|
|
|
|
}
|