|
|
|
@ -53,15 +53,18 @@ 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++; |
|
|
|
|
if(std::filesystem::exists("save_file_path"_S)){ |
|
|
|
|
for(auto&path:std::filesystem::directory_iterator("save_file_path"_S)){ |
|
|
|
|
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; |
|
|
|
|
utils::datafile::Read(metadata,"save_file_path"_S+"metadata.dat"); |
|
|
|
|
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,40 +116,52 @@ const void SaveFile::SaveGame(){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const void SaveFile::LoadGame(){ |
|
|
|
|
std::filesystem::create_directories("save_file_path"_S); |
|
|
|
|
utils::datafile loadFile; |
|
|
|
|
utils::datafile::Read(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); |
|
|
|
|
game->ResetGame(); |
|
|
|
|
for(auto&[key,data]:loadFile["Items"].GetOrderedKeys()){ |
|
|
|
|
std::weak_ptr<Item>newItem=Inventory::AddItem(data["Item Name"].GetString(),data["Amt"].GetInt()); |
|
|
|
|
newItem.lock()->enhancementLevel=data["Enhancement Level"].GetInt(); |
|
|
|
|
if(loadFile.GetProperty(std::format("Items.{}",key)).HasProperty("Attributes")){ |
|
|
|
|
for(auto&[attr,data]:loadFile.GetProperty(std::format("Items.{}.Attributes",key)).GetOrderedKeys()){ |
|
|
|
|
newItem.lock()->randomizedStats.A(attr)=data.GetReal(); |
|
|
|
|
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()){ |
|
|
|
|
std::weak_ptr<Item>newItem=Inventory::AddItem(data["Item Name"].GetString(),data["Amt"].GetInt()); |
|
|
|
|
newItem.lock()->enhancementLevel=data["Enhancement Level"].GetInt(); |
|
|
|
|
if(loadFile.GetProperty(std::format("Items.{}",key)).HasProperty("Attributes")){ |
|
|
|
|
for(auto&[attr,data]:loadFile.GetProperty(std::format("Items.{}.Attributes",key)).GetOrderedKeys()){ |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
game->ChangePlayerClass(classutils::StringToClass(loadFile["Player"]["Class"].GetString())); |
|
|
|
|
game->GetPlayer()->level=loadFile["Player"]["Level"].GetInt(); |
|
|
|
|
game->GetPlayer()->SetMoney(loadFile["Player"]["Money"].GetInt()); |
|
|
|
|
game->GetPlayer()->currentLevelXP=loadFile["Player"]["Current EXP"].GetInt(); |
|
|
|
|
game->GetPlayer()->totalXPEarned=loadFile["Player"]["Total EXP"].GetInt(); |
|
|
|
|
for(auto&[key,data]:loadFile["Player"]["Base Stats"].GetOrderedKeys()){ |
|
|
|
|
game->GetPlayer()->SetBaseStat(key,data.GetReal()); |
|
|
|
|
} |
|
|
|
|
for(const auto&[key,data]:loadFile["Unlocks"].GetOrderedKeys()){ |
|
|
|
|
Unlock::UnlockArea(key); |
|
|
|
|
} |
|
|
|
|
State_OverworldMap::SetStageMarker(loadFile["Overworld Map Location"].GetString()); |
|
|
|
|
game->SetChapter(loadFile["Chapter"].GetInt()); |
|
|
|
|
SaveFile::SetSaveFileName(loadFile["Save Name"].GetString()); |
|
|
|
|
game->SetRuntime(loadFile["Game Time"].GetReal()); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
game->ChangePlayerClass(classutils::StringToClass(loadFile["Player"]["Class"].GetString())); |
|
|
|
|
game->GetPlayer()->level=loadFile["Player"]["Level"].GetInt(); |
|
|
|
|
game->GetPlayer()->SetMoney(loadFile["Player"]["Money"].GetInt()); |
|
|
|
|
game->GetPlayer()->currentLevelXP=loadFile["Player"]["Current EXP"].GetInt(); |
|
|
|
|
game->GetPlayer()->totalXPEarned=loadFile["Player"]["Total EXP"].GetInt(); |
|
|
|
|
for(auto&[key,data]:loadFile["Player"]["Base Stats"].GetOrderedKeys()){ |
|
|
|
|
game->GetPlayer()->SetBaseStat(key,data.GetReal()); |
|
|
|
|
} |
|
|
|
|
for(const auto&[key,data]:loadFile["Unlocks"].GetOrderedKeys()){ |
|
|
|
|
Unlock::UnlockArea(key); |
|
|
|
|
} |
|
|
|
|
State_OverworldMap::SetStageMarker(loadFile["Overworld Map Location"].GetString()); |
|
|
|
|
game->SetChapter(loadFile["Chapter"].GetInt()); |
|
|
|
|
SaveFile::SetSaveFileName(loadFile["Save Name"].GetString()); |
|
|
|
|
game->SetRuntime(loadFile["Game Time"].GetReal()); |
|
|
|
|
game->GetPlayer()->RecalculateEquipStats(); |
|
|
|
|
|
|
|
|
|
GameState::ChangeState(States::OVERWORLD_MAP,0.5f); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const std::string_view SaveFile::GetSaveFileName(){ |
|
|
|
|