Address Issue#45. Pressing opposite movement keys now properly stops animation. Movement with analog stick now properly sets last moved direction key as well instead of facing last digital input direction. Velocity is now applied and footsteps factor in total velocity before playing. Fixed a bug where the game could be closed by the player during a file save, causing the hash of the file to potentially become corrupted and unplayable. Fix some tiles at the end of 1-1 to match the underlying color of the surrounding forest. Removed erroneous upwards path from base camp on the world map. Release Build 8630.

This commit is contained in:
2024-04-01 16:26:46 -05:00
parent c864e0f155
commit 35c269bd8b
8 changed files with 109 additions and 71 deletions
+32 -15
View File
@@ -82,6 +82,8 @@ const size_t SaveFile::GetOnlineSaveFileCount(){
const void SaveFile::SaveGame(){
game->saveGameDisplayTime=6.f;
game->SetQuitAllowed(false);
std::filesystem::create_directories("save_file_path"_S);
utils::datafile saveFile;
@@ -222,6 +224,7 @@ const void SaveFile::SaveGame(){
}else{
LOG("WARNING! Could not save metadata to server!");
}
game->SetQuitAllowed(true);
};
Server_SaveMetadataFile(RetryResponse);
}else{
@@ -271,38 +274,46 @@ const void SaveFile::SaveGame(){
std::string systemContents=systemFileContents.str();
emscripten_idb_async_store("/assets",("save_file_path"_S+"system.conf").c_str(),systemContents.data(),systemContents.length(),0,[](void*arg){
LOG("Successfully saved system file!");
game->SetQuitAllowed(true);
},[](void*arg){
LOG("Failed to save system file!");
game->SetQuitAllowed(true);
});
systemfile.close();
#else
game->SetQuitAllowed(true);
#endif
}
#define HASH_VERIFICATION_REQUIRED true
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));
if(!loadFile.HasProperty("Hash")){
LOG(std::format("WARNING! Filehash for file {} does not exist!","save_file_path"_S+std::format("save.{:04}",saveFileID)));
return;
}
if(loadFile.HasProperty("Hash")){
std::string expectedFileHash=loadFile["Hash"].GetString();
loadFile["Hash"].SetString("");
utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID));
if(expectedFileHash!=fileHash){
LOG(std::format("WARNING! Filehash for file {} was not identified as proper! Will not load this file!","save_file_path"_S+std::format("save.{:04}",saveFileID)));
if(HASH_VERIFICATION_REQUIRED){
if(!loadFile.HasProperty("Hash")){
LOG(std::format("WARNING! Filehash for file {} does not exist!","save_file_path"_S+std::format("save.{:04}",saveFileID)));
return;
}
if(loadFile.HasProperty("Hash")){
std::string expectedFileHash=loadFile["Hash"].GetString();
loadFile["Hash"].SetString("");
utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID));
loadFile["Hash"].SetString(expectedFileHash); //Now write the hash back into the file since we tampered with it.
utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
if(expectedFileHash!=fileHash){
LOG(std::format("WARNING! Filehash for file {} was not identified as proper! Will not load this file!","save_file_path"_S+std::format("save.{:04}",saveFileID)));
return;
}
loadFile["Hash"].SetString(expectedFileHash); //Now write the hash back into the file since we tampered with it.
utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
}
}
game->ResetGame();
for(auto&[key,data]:loadFile["Items"].GetOrderedKeys()){
@@ -398,6 +409,8 @@ void SaveFile::LoadFile(){
const void SaveFile::LoadGame(){
std::filesystem::create_directories("save_file_path"_S);
game->SetQuitAllowed(false);
#ifdef __EMSCRIPTEN__
if(onlineMode){
@@ -410,6 +423,7 @@ const void SaveFile::LoadGame(){
}else{
LOG("WARNING! Could not load save file!");
}
game->SetQuitAllowed(true);
});
}else{
emscripten_idb_async_load("/assets",("save_file_path"_S+std::format("save.{:04}",saveFileID)).c_str(),0,[](void*arg,void*data,int length){
@@ -422,12 +436,15 @@ const void SaveFile::LoadGame(){
}
file.close();
LoadFile();
game->SetQuitAllowed(true);
},[](void*arg){
LOG("Failed to load Save File "<<saveFileID<<"!");
game->SetQuitAllowed(true);
});
}
#else
LoadFile();
game->SetQuitAllowed(true);
#endif
}