|
|
|
@ -180,64 +180,65 @@ const void SaveFile::SaveGame(){ |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const void SaveFile::LoadGame(){ |
|
|
|
|
std::filesystem::create_directories("save_file_path"_S); |
|
|
|
|
auto LoadFile=[&](){ |
|
|
|
|
utils::datafile loadFile; |
|
|
|
|
void SaveFile::LoadFile(){ |
|
|
|
|
utils::datafile loadFile; |
|
|
|
|
|
|
|
|
|
std::string loadFilename="save_file_path"_S+std::format("save.{:04}",saveFileID); |
|
|
|
|
|
|
|
|
|
if(std::filesystem::exists(loadFilename)){ |
|
|
|
|
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()); |
|
|
|
|
} |
|
|
|
|
std::string loadFilename="save_file_path"_S+std::format("save.{:04}",saveFileID); |
|
|
|
|
|
|
|
|
|
if(std::filesystem::exists(loadFilename)){ |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
if(data.HasProperty("LoadoutSlot")){ |
|
|
|
|
uint8_t loadoutSlot=data["LoadoutSlot"].GetInt(); |
|
|
|
|
if(loadoutSlot!=255){ |
|
|
|
|
game->SetLoadoutItem(loadoutSlot,newItem.lock()->ActualName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
for(const auto&[key,data]:loadFile["Unlocks"].GetOrderedKeys()){ |
|
|
|
|
Unlock::UnlockArea(key); |
|
|
|
|
if(data.GetValueCount()>1&&data.GetBool(1U)){ |
|
|
|
|
auto opt_cp=State_OverworldMap::ConnectionPointFromString(key); |
|
|
|
|
if(!opt_cp)ERR(std::format("WARNING! Could not find connection point {}! THIS SHOULD NOT BE HAPPENING! Potential invalid unlock name.",key)) |
|
|
|
|
else opt_cp.value()->SetVisited(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
if(data.GetValueCount()>1&&data.GetBool(1U)){ |
|
|
|
|
auto opt_cp=State_OverworldMap::ConnectionPointFromString(key); |
|
|
|
|
if(!opt_cp)ERR(std::format("WARNING! Could not find connection point {}! THIS SHOULD NOT BE HAPPENING! Potential invalid unlock name.",key)) |
|
|
|
|
else opt_cp.value()->SetVisited(); |
|
|
|
|
} |
|
|
|
|
State_OverworldMap::SetStageMarker(loadFile["Overworld Map Location"].GetString()); |
|
|
|
|
State_OverworldMap::UpdateCurrentConnectionPoint(const_cast<ConnectionPoint&>(State_OverworldMap::GetCurrentConnectionPoint())); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
State_OverworldMap::SetStageMarker(loadFile["Overworld Map Location"].GetString()); |
|
|
|
|
State_OverworldMap::UpdateCurrentConnectionPoint(const_cast<ConnectionPoint&>(State_OverworldMap::GetCurrentConnectionPoint())); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const void SaveFile::LoadGame(){ |
|
|
|
|
std::filesystem::create_directories("save_file_path"_S); |
|
|
|
|
|
|
|
|
|
#ifdef __EMSCRIPTEN__ |
|
|
|
|
if(onlineMode){ |
|
|
|
@ -261,7 +262,7 @@ const void SaveFile::LoadGame(){ |
|
|
|
|
file<<rawMetadata[i]; |
|
|
|
|
} |
|
|
|
|
file.close(); |
|
|
|
|
LoadGame(); |
|
|
|
|
LoadFile(); |
|
|
|
|
},[](void*arg){ |
|
|
|
|
std::cout<<"Failed to load Save File "<<saveFileID<<"!"<<std::endl; |
|
|
|
|
}); |
|
|
|
|