diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 5fd69fea..f1f47784 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -2565,7 +2565,7 @@ void Crawler::ResetGame(){ } void Crawler::OnRequestCompleted(const std::string_view receivedData)const{ - std::cout<<"Received in engine: "<monstersToBeSpawned; time_t gameStarted; + std::functionresponseCallback; void ValidateGameStatus(); #ifndef __EMSCRIPTEN__ diff --git a/Crawler/MainMenuWindow.cpp b/Crawler/MainMenuWindow.cpp index f37883a9..49864327 100644 --- a/Crawler/MainMenuWindow.cpp +++ b/Crawler/MainMenuWindow.cpp @@ -58,7 +58,19 @@ void Menu::InitializeMainMenuWindow(){ })END; mainMenuWindow->ADD("Load Game Button",MenuComponent)({{12,36},{72,24}},"Load Game",[](MenuFuncData data){ SaveFile::UpdateSaveGameData(); - Menu::OpenMenu(LOAD_GAME); + #ifdef __EMSCRIPTEN__ + SaveFile::Server_GetLoadInfo([](std::string_view response){ + if(response!="ERR"){ + std::ofstream file("save_file_path"_S+"metadata.dat"); + file<ADD("Quit Game Button",MenuComponent)({{12,68},{72,24}},"Quit Game",[](MenuFuncData data){ diff --git a/Crawler/MenuLabel.h b/Crawler/MenuLabel.h index 90715730..b1eb58b7 100644 --- a/Crawler/MenuLabel.h +++ b/Crawler/MenuLabel.h @@ -78,8 +78,8 @@ protected: vf2d adjustedScale={scale,scale}; vf2d labelTextSize= proportional? - vf2d(game->GetWrappedTextSizeProp(label,rect.size.x-8,adjustedScale)): - vf2d(game->GetWrappedTextSize(label,rect.size.x-8,adjustedScale)); + vf2d(game->GetWrappedTextSizeProp(label,rect.size.x-2,adjustedScale)): + vf2d(game->GetWrappedTextSize(label,rect.size.x-2,adjustedScale)); if(fitToLabel){ labelTextSize= @@ -93,7 +93,7 @@ protected: } } - vf2d drawPos=vf2d{-4.f,0.f}+rect.middle()-vf2d{labelTextSize}/2; //Assume centered. + vf2d drawPos=vf2d{-1,0}+rect.middle()-vf2d{labelTextSize}/2; //Assume centered. if(!centered){ drawPos=vf2d{rect.pos.x+2,rect.middle().y-labelTextSize.y/2}; //We should at least vertically align here. } diff --git a/Crawler/SaveFile.cpp b/Crawler/SaveFile.cpp index f1fd6c07..e641f64d 100644 --- a/Crawler/SaveFile.cpp +++ b/Crawler/SaveFile.cpp @@ -116,13 +116,13 @@ const void SaveFile::SaveGame(){ utils::datafile::INITIAL_SETUP_COMPLETE=true; #ifdef __EMSCRIPTEN__ - Server_SaveFile(); + Server_SaveFile([](std::string_view response){}); #endif } const void SaveFile::LoadGame(){ #ifdef __EMSCRIPTEN__ - Server_GetFile(); + Server_GetFile([](std::string_view response){}); #else std::filesystem::create_directories("save_file_path"_S); utils::datafile loadFile; @@ -224,23 +224,39 @@ const std::string SaveFile::CreateServerRequest(const SaveFileOperation::Operati operationName=std::format("SAVE_FILE"); //Data should contain the entire contents of our save file. }break; + case SaveFileOperation::SAVE_METADATA_FILE:{ + operationName=std::format("SAVE_METADATA_FILE"); + //Data should contain the entire contents of our metadata save file. + }break; } dataString+="&operation="+operationName; dataString+="&checksum="+std::to_string(CalculateChecksum(operationName,data)); dataString+="&data="+std::string(data); return "save_server"_S+dataString; } -const void SaveFile::Server_GetLoadInfo(){ +const void SaveFile::Server_GetLoadInfo(std::functionrespCallbackFunc){ game->SendRequest(CreateServerRequest(SaveFileOperation::GET_LOAD_FILES,"0"),""); + game->responseCallback=respCallbackFunc; } -const void SaveFile::Server_GetFile(){ +const void SaveFile::Server_GetFile(std::functionrespCallbackFunc){ game->SendRequest(CreateServerRequest(SaveFileOperation::GET_FILE,std::to_string(saveFileID)),""); + game->responseCallback=respCallbackFunc; } -const void SaveFile::Server_SaveFile(){ +const void SaveFile::Server_SaveFile(std::functionrespCallbackFunc){ std::stringstream fileContents; std::ifstream file("save_file_path"_S+std::format("save.{:04}",saveFileID)); while(file.good()){ fileContents<SendRequest(CreateServerRequest(SaveFileOperation::SAVE_FILE,std::to_string(saveFileID)+"|"+fileContents.str()),""); + game->responseCallback=respCallbackFunc; +} +const void SaveFile::Server_SaveMetadataFile(std::functionrespCallbackFunc){ + std::stringstream fileContents; + std::ifstream file("save_file_path"_S+"metadata.dat"); + while(file.good()){ + fileContents<SendRequest(CreateServerRequest(SaveFileOperation::SAVE_METADATA_FILE,fileContents.str()),""); + game->responseCallback=respCallbackFunc; } \ No newline at end of file diff --git a/Crawler/SaveFile.h b/Crawler/SaveFile.h index bf547b02..47eb880a 100644 --- a/Crawler/SaveFile.h +++ b/Crawler/SaveFile.h @@ -43,6 +43,7 @@ namespace SaveFileOperation{ enum Operation{ GET_LOAD_FILES, GET_FILE, + SAVE_METADATA_FILE, SAVE_FILE, }; }; @@ -61,7 +62,8 @@ public: //Called whenever the save game data is updated. static const void UpdateSaveGameData(); static const std::string CreateServerRequest(const SaveFileOperation::Operation operation,std::string_view data); - static const void Server_GetLoadInfo(); - static const void Server_GetFile(); - static const void Server_SaveFile(); + static const void Server_GetLoadInfo(std::functionrespCallbackFunc); + static const void Server_GetFile(std::functionrespCallbackFunc); + static const void Server_SaveFile(std::functionrespCallbackFunc); + static const void Server_SaveMetadataFile(std::functionrespCallbackFunc); }; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index cafac076..b85e0cb4 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 5285 +#define VERSION_BUILD 5287 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/saves/metadata.dat b/Crawler/assets/saves/metadata.dat index 6f66f2c1..bdfae720 100644 --- a/Crawler/assets/saves/metadata.dat +++ b/Crawler/assets/saves/metadata.dat @@ -1,2 +1,2 @@ -save0 = 534.977882, 1, 2, Ranger, Sig +save0 = 641.829219, 1, 2, Ranger, Sig save1 = 107.824620, 1, 1, Wizard, WIZ diff --git a/Crawler/emscripten_build.ps1 b/Crawler/emscripten_build.ps1 index 299cb300..8678e4cc 100644 --- a/Crawler/emscripten_build.ps1 +++ b/Crawler/emscripten_build.ps1 @@ -1,12 +1,6 @@ +$ErrorActionPreference = "Stop" cd .. ./emscripten_build.ps1 -if( -not $? ) -{ - $msg = $Error[0].Exception.Message - "$msg" - exit -} -else -{ +if ($LASTEXITCODE -eq 0) { ./emscripten_run.ps1 } \ No newline at end of file diff --git a/Crawler/olcPixelGameEngine.h b/Crawler/olcPixelGameEngine.h index df64b5b2..d10b1f70 100644 --- a/Crawler/olcPixelGameEngine.h +++ b/Crawler/olcPixelGameEngine.h @@ -7217,7 +7217,13 @@ namespace olc virtual olc::rcode SendRequest(std::string_view url,std::string_view data)override{ EM_ASM({ requestResp=""; - fetch(UTF8ToString($0)).then((resp)=>resp.text()).then((data)=>{requestResp=data}); + fetch(UTF8ToString($0)).then((resp)=>{ + if(resp.ok){ + resp.text(); + } + throw new Error(resp.text()); + }).then((data)=>{requestResp=data;}) + .catch((err)=>{requestResp="ERR";}); },std::string(url).c_str()); return olc::rcode::OK; }