|
|
|
@ -53,15 +53,18 @@ std::string SaveFile::saveFileName=""; |
|
|
|
|
|
|
|
|
|
const size_t SaveFile::GetSaveFileCount(){ |
|
|
|
|
size_t count=0; |
|
|
|
|
if(std::filesystem::exists("save_file_path"_S)){ |
|
|
|
|
for(auto&path:std::filesystem::directory_iterator("save_file_path"_S)){ |
|
|
|
|
if(path.is_regular_file()){ |
|
|
|
|
if(path.is_regular_file()&&path.path()!="metadata.dat"){ |
|
|
|
|
count++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const void SaveFile::SaveGame(){ |
|
|
|
|
std::filesystem::create_directories("save_file_path"_S); |
|
|
|
|
utils::datafile saveFile; |
|
|
|
|
utils::datafile::INITIAL_SETUP_COMPLETE=false; |
|
|
|
|
for(size_t itemCount=0;auto&[cat,items]:Inventory::sortedInv){ |
|
|
|
@ -70,6 +73,11 @@ const void SaveFile::SaveGame(){ |
|
|
|
|
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))); |
|
|
|
|
uint8_t loadoutSlotNumber=255; |
|
|
|
|
for(int i=0;i<game->loadout.size();i++){ |
|
|
|
|
if(item==game->GetLoadoutItem(i)){loadoutSlotNumber=i;break;} |
|
|
|
|
} |
|
|
|
|
saveFile["Items"][std::format("Item[{}]",itemCount)]["LoadoutSlot"].SetInt(loadoutSlotNumber); |
|
|
|
|
for(const auto&[attr,val]:item->RandomStats()){ |
|
|
|
|
saveFile["Items"][std::format("Item[{}]",itemCount)]["Attributes"][std::string(attr.ActualName())].SetReal(val); |
|
|
|
|
} |
|
|
|
@ -94,7 +102,9 @@ const void SaveFile::SaveGame(){ |
|
|
|
|
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); |
|
|
|
|
|
|
|
|
|
utils::datafile metadata; |
|
|
|
|
if(std::filesystem::exists("save_file_path"_S+"metadata.dat")){ |
|
|
|
|
utils::datafile::Read(metadata,"save_file_path"_S+"metadata.dat"); |
|
|
|
|
} |
|
|
|
|
metadata.GetProperty(std::format("save{}",saveFileID)).SetReal(game->GetRuntime(),0U); |
|
|
|
|
metadata.GetProperty(std::format("save{}",saveFileID)).SetInt(game->GetCurrentChapter(),1U); |
|
|
|
|
metadata.GetProperty(std::format("save{}",saveFileID)).SetInt(game->GetPlayer()->Level(),2U); |
|
|
|
@ -106,7 +116,9 @@ const void SaveFile::SaveGame(){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const void SaveFile::LoadGame(){ |
|
|
|
|
std::filesystem::create_directories("save_file_path"_S); |
|
|
|
|
utils::datafile loadFile; |
|
|
|
|
if(std::filesystem::exists("save_file_path"_S+std::format("save.{:04}",saveFileID))){ |
|
|
|
|
utils::datafile::Read(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); |
|
|
|
|
game->ResetGame(); |
|
|
|
|
for(auto&[key,data]:loadFile["Items"].GetOrderedKeys()){ |
|
|
|
@ -117,6 +129,13 @@ const void SaveFile::LoadGame(){ |
|
|
|
|
newItem.lock()->randomizedStats.A(attr)=data.GetReal(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(data.HasProperty("LoadoutSlot")){ |
|
|
|
|
uint8_t loadoutSlot=data["LoadoutSlot"].GetInt(); |
|
|
|
|
if(loadoutSlot!=255){ |
|
|
|
|
game->SetLoadoutItem(loadoutSlot,newItem.lock()->ActualName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
EquipSlot slot=EquipSlot(loadFile.GetProperty(std::format("Items.{}.Equip Slot",key)).GetInt()); |
|
|
|
|
if(slot!=EquipSlot::NONE){ //This should be equipped somewhere!
|
|
|
|
|
Inventory::EquipItem(newItem,slot); |
|
|
|
@ -140,6 +159,9 @@ const void SaveFile::LoadGame(){ |
|
|
|
|
game->GetPlayer()->RecalculateEquipStats(); |
|
|
|
|
|
|
|
|
|
GameState::ChangeState(States::OVERWORLD_MAP,0.5f); |
|
|
|
|
}else{ |
|
|
|
|
std::cout<<std::format("WARNING! File {} does not exist for loading!","save_file_path"_S+std::format("save.{:04}",saveFileID))<<std::endl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const std::string_view SaveFile::GetSaveFileName(){ |
|
|
|
|