Update sprites for second boss, add config parameters for new behavior.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
Nic0Nic0Nii
2024-01-26 18:21:01 +00:00
co-authored by AMay
parent aa39b1b855
commit 1046557ac0
6 changed files with 88 additions and 41 deletions
+66 -38
View File
@@ -124,35 +124,37 @@ const void SaveFile::SaveGame(){
utils::datafile::INITIAL_SETUP_COMPLETE=true;
#ifdef __EMSCRIPTEN__
std::stringstream fileContents;
std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID));
while(file.good()){
int val=file.get();
if(val!=-1){
fileContents<<char(val);
if(onlineMode){
std::stringstream fileContents;
std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID)+"_online");
while(file.good()){
int val=file.get();
if(val!=-1){
fileContents<<char(val);
}
}
}
std::string contents=fileContents.str();
emscripten_idb_async_store("/assets",("save_file_path"_S+std::format("save.{:04}",saveFileID)).c_str(),contents.data(),contents.length(),0,[](void*arg){
std::cout<<"Successfully saved save file "<<saveFileID<<"!"<<std::endl;
},[](void*arg){
std::cout<<"Failed to save save file "<<saveFileID<<"!"<<std::endl;
});
std::string contents=fileContents.str();
emscripten_idb_async_store("/assets",("save_file_path"_S+std::format("save.{:04}",saveFileID)+"_online").c_str(),contents.data(),contents.length(),0,[](void*arg){
std::cout<<"Successfully saved save file "<<saveFileID<<"!"<<std::endl;
},[](void*arg){
std::cout<<"Failed to save save file "<<saveFileID<<"!"<<std::endl;
});
file.close();
std::function<void(std::string_view response)>RetryResponse;
RetryResponse=[&](std::string_view response){
if(response!="ERR"){
Server_SaveFile([](std::string_view response){
if(response=="ERR"){
std::cout<<"WARNING! Could not save data to server!"<<std::endl;
}
});
}else{
std::cout<<"WARNING! Could not save metadata to server!"<<std::endl;
}
};
Server_SaveMetadataFile(RetryResponse);
file.close();
std::function<void(std::string_view response)>RetryResponse;
RetryResponse=[&](std::string_view response){
if(response!="ERR"){
Server_SaveFile([](std::string_view response){
if(response=="ERR"){
std::cout<<"WARNING! Could not save data to server!"<<std::endl;
}
});
}else{
std::cout<<"WARNING! Could not save metadata to server!"<<std::endl;
}
};
Server_SaveMetadataFile(RetryResponse);
}
#endif
}
@@ -264,6 +266,30 @@ const void SaveFile::UpdateSaveGameData(){
}
}
};
auto LoadOnlineMetadataFile=[](){
auto gameFilesList=Component<ScrollableWindowComponent>(LOAD_GAME,"Game Files List");
gameFilesList->RemoveAllComponents();
if(SaveFile::IsOnline()){
const size_t saveFileCount=GetSaveFileCount();
utils::datafile metadata;
if(!std::filesystem::exists("save_file_path"_S+"metadata.dat")){
utils::datafile::Write(metadata,"save_file_path"_S+"metadata.dat");
}
utils::datafile::Read(metadata,"save_file_path"_S+"metadata.dat");
float offsetY=0;
for(size_t i=0;i<saveFileCount;i++){
if(metadata.HasProperty(std::format("save{}",i))){
gameFilesList->ADD(std::format("Load File Button - Save {}",i),LoadFileButton)(geom2d::rect<float>{{0,offsetY},{gameFilesList->GetSize().x-13,48}},metadata[std::format("save{}",i)],i,[](MenuFuncData data){
std::weak_ptr<LoadFileButton>comp=DYNAMIC_POINTER_CAST<LoadFileButton>(data.component.lock());
saveFileID=comp.lock()->getSaveFileID();
SaveFile::LoadGame();
return true;
},ButtonAttr::NONE)END;
offsetY+=49;
}
}
}
};
LoadMetadataFile();
@@ -337,7 +363,7 @@ const void SaveFile::Server_GetFile(std::function<void(std::string_view)>respCal
}
const void SaveFile::Server_SaveFile(std::function<void(std::string_view)>respCallbackFunc){
std::stringstream fileContents;
std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID));
std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID)+"_online");
while(file.good()){
int val=file.get();
if(val!=-1){
@@ -349,21 +375,19 @@ const void SaveFile::Server_SaveFile(std::function<void(std::string_view)>respCa
}
const void SaveFile::Server_SaveMetadataFile(std::function<void(std::string_view)>respCallbackFunc){
std::stringstream fileContents;
std::ifstream file("save_file_path"_S+"metadata.dat");
std::ifstream file("save_file_path"_S+"metadata.dat"+"_online");
while(file.good()){
int val=file.get();
if(val!=-1){
fileContents<<char(val);
}
}
#ifdef __EMSCRIPTEN__
std::string contents=fileContents.str();
emscripten_idb_async_store("/assets",("save_file_path"_S+"metadata.dat").c_str(),contents.data(),contents.length(),0,[](void*arg){
std::cout<<"Saved metadata successfully!"<<std::endl;
},[](void*arg){
std::cout<<"Failed to save metadata!"<<std::endl;
});
#endif
std::string contents=fileContents.str();
emscripten_idb_async_store("/assets",("save_file_path"_S+"metadata.dat"+"_online").c_str(),contents.data(),contents.length(),0,[](void*arg){
std::cout<<"Saved metadata successfully!"<<std::endl;
},[](void*arg){
std::cout<<"Failed to save metadata!"<<std::endl;
});
game->SendRequest("save_server"_S,CreateServerRequest(SaveFileOperation::SAVE_METADATA_FILE,fileContents.str()));
game->responseCallback=respCallbackFunc;
}
@@ -375,6 +399,10 @@ const void SaveFile::SetUserID(std::string_view userID){
SaveFile::username=userID;
}
bool SaveFile::IsOnline(){
const bool SaveFile::IsOnline(){
return onlineMode;
}
void SaveFile::SetOnlineMode(bool online){
onlineMode=online;
}