diff --git a/src/FileManager.cpp b/src/FileManager.cpp index 3aac6fc..36eedb4 100644 --- a/src/FileManager.cpp +++ b/src/FileManager.cpp @@ -26,8 +26,10 @@ #include "Functions.h" #include #include +#ifndef __EMSCRIPTEN__ #include #include +#endif using namespace std; @@ -48,7 +50,9 @@ using namespace std; #endif //Included for the downloadFile method. +#ifndef __EMSCRIPTEN__ #include +#endif //Under Windows there's just one userpath. #ifdef WIN32 @@ -546,6 +550,12 @@ bool downloadFile(const string &path, const string &destination) { return status; } +#ifdef __EMSCRIPTEN__ +// Browser build: no network access (no add-ons). +bool downloadFile(const string &path, FILE* destination) { + return false; +} +#else bool downloadFile(const string &path, FILE* destination) { CURL* curl=curl_easy_init(); @@ -585,11 +595,18 @@ bool downloadFile(const string &path, FILE* destination) { return (res==0); } +#endif + size_t writeData(void *ptr, size_t size, size_t nmemb, void *stream){ return fwrite(ptr, size, nmemb, (FILE *)stream); } +#ifdef __EMSCRIPTEN__ +bool extractFile(const string &fileName, const string &destination) { + return false; +} +#else bool extractFile(const string &fileName, const string &destination) { //Create the archive we're going to extract. archive* file; @@ -642,6 +659,7 @@ bool extractFile(const string &fileName, const string &destination) { archive_read_free(file); return true; } +#endif bool dirExists(const char* dir){ #if defined(WIN32) @@ -795,6 +813,7 @@ bool renameDirectory(const char* oldPath,const char* newPath){ } +#ifndef __EMSCRIPTEN__ void copyData(archive* file, archive* dest) { int status; const void* buff; @@ -822,6 +841,7 @@ void copyData(archive* file, archive* dest) { } } } +#endif bool copyFile(const char* source,const char* dest){ //Open the source file. diff --git a/src/Functions.cpp b/src/Functions.cpp index 9e171a1..d2e2b59 100644 --- a/src/Functions.cpp +++ b/src/Functions.cpp @@ -869,6 +869,18 @@ void flipScreen(SDL_Renderer& renderer){ SDL_RenderPresent(&renderer); } +#ifdef __EMSCRIPTEN__ +#include +// Browser build: the game only writes settings and statistics on exit; the page calls this when +// the tab is hidden or closed. +extern "C" EMSCRIPTEN_KEEPALIVE void fredygames_save(){ + if(settings){ + saveSettings(); + statsMgr.saveFile(getUserPath(USER_CONFIG)+"statistics"); + } +} +#endif + void clean(){ //Save statistics statsMgr.saveFile(getUserPath(USER_CONFIG)+"statistics"); diff --git a/src/Main.cpp b/src/Main.cpp index 6c8db3a..df63dbf 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -25,6 +25,9 @@ #include "StatisticsManager.h" #include "Timer.h" #include +#ifdef __EMSCRIPTEN__ +#include +#endif #include #include #include @@ -234,6 +237,11 @@ int main(int argc, char** argv) { if(t>0){ SDL_Delay(t); } +#ifdef __EMSCRIPTEN__ + else{ + emscripten_sleep(0); + } +#endif } //The game has ended, save the settings just to be sure. diff --git a/src/Settings.cpp b/src/Settings.cpp index bdc988d..df79317 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -37,7 +37,11 @@ Settings::Settings(const string& fileName): fileName(fileName){ settings["height"]="600"; settings["resizable"]="1"; settings["theme"]="%DATA%/themes/Cloudscape"; +#ifdef __EMSCRIPTEN__ + settings["internet"]="0"; +#else settings["internet"]="1"; +#endif settings["lastlevelpack"]="tutorial"; settings["internet-proxy"]=""; settings["lang"]=""; diff --git a/src/TitleMenu.cpp b/src/TitleMenu.cpp index 4ef5404..b9a7b1d 100644 --- a/src/TitleMenu.cpp +++ b/src/TitleMenu.cpp @@ -126,6 +126,11 @@ void Menu::handleEvents(ImageManager& imageManager, SDL_Renderer& renderer){ setNextState(STATE_LEVEL_EDIT_SELECT); break; case 4: +#ifdef __EMSCRIPTEN__ + // Browser build: add-ons are downloaded from the internet, which this version never does. + msgBox(imageManager,renderer,_("Addons are not available in this version of the game."),MsgBoxOKOnly,_("Addons")); + break; +#endif //Check if internet is enabled. if(!getSettings()->getBoolValue("internet")){ msgBox(imageManager,renderer,_("Enable internet in order to install addons."),MsgBoxOKOnly,_("Internet disabled"));