diff --git a/base/caveexpress/config.lua b/base/caveexpress/config.lua index 6ea582d..0a15b1a 100644 --- a/base/caveexpress/config.lua +++ b/base/caveexpress/config.lua @@ -28,9 +28,15 @@ if isAndroid() then defaultgreen = 5 defaultblue = 6 elseif isHTML5() then + -- fredygames: sound through SDL_mixer, a fixed 1024x768 canvas that the page scales, and only the + -- "big" texture atlases (the build ships no "small" ones) defaultfrontend = "opengl3" - defaultsoundengine = "dummy" + defaultsoundengine = "sdl" defaultnetwork = false + defaultwidth = 1024 + defaultheight = 768 + defaultfullscreen = false + defaulttexturesize = "big" else defaultflyingspeedx = 2.5 defaultgamecontroller = true diff --git a/src/caveexpress/client/ui/windows/UIMainWindow.cpp b/src/caveexpress/client/ui/windows/UIMainWindow.cpp index d32b98d..5ecb285 100644 --- a/src/caveexpress/client/ui/windows/UIMainWindow.cpp +++ b/src/caveexpress/client/ui/windows/UIMainWindow.cpp @@ -70,9 +70,12 @@ UIMainWindow::UIMainWindow (IFrontend *frontend, ServiceProvider& serviceProvide panel->add(editor); } +#ifndef __EMSCRIPTEN__ + // fredygames: the web build never leaves the page, so it has no homepage link UINodeMainButton *homepage = new UINodeMainButton(_frontend, tr("Homepage")); homepage->addListener(UINodeListenerPtr(new OpenURLListener(_frontend, "http://caveproductions.org/"))); panel->add(homepage); +#endif UINodeMainButton *help = new UINodeMainButton(_frontend, tr("Help")); help->addListener(UINodeListenerPtr(new OpenWindowListener(UI_WINDOW_HELP))); @@ -86,13 +89,12 @@ UIMainWindow::UIMainWindow (IFrontend *frontend, ServiceProvider& serviceProvide #endif #endif +#ifndef __EMSCRIPTEN__ + // fredygames: in the browser "Quit" used to navigate to the homepage; the page is closed instead UINodeMainButton *quit = new UINodeMainButton(_frontend, tr("Quit")); -#ifdef __EMSCRIPTEN__ - quit->addListener(UINodeListenerPtr(new OpenURLListener(_frontend, "http://caveproductions.org/", false))); -#else quit->addListener(UINodeListenerPtr(new QuitListener())); -#endif panel->add(quit); +#endif add(panel); diff --git a/src/modules/common/ConfigManager.cpp b/src/modules/common/ConfigManager.cpp index 953f442..8eea06e 100644 --- a/src/modules/common/ConfigManager.cpp +++ b/src/modules/common/ConfigManager.cpp @@ -333,6 +333,11 @@ int ConfigManager::mapKey (const std::string& name) return keycode; } +void ConfigManager::save () +{ + _persister->save(_configVars); +} + void ConfigManager::shutdown () { Log::info(LOG_COMMON, "shutdown config manager"); diff --git a/src/modules/common/ConfigManager.h b/src/modules/common/ConfigManager.h index 05fc6b5..c1b33c4 100644 --- a/src/modules/common/ConfigManager.h +++ b/src/modules/common/ConfigManager.h @@ -116,6 +116,8 @@ public: void init (IBindingSpaceListener *bindingSpaceListener, int argc, char **argv); void shutdown (); + // fredygames: writes the config vars to the persister without shutting down + void save (); bool renderToTexture() const; int getClientSideParticleMaxAmount () const; diff --git a/src/modules/common/ports/HTML5.cpp b/src/modules/common/ports/HTML5.cpp index 1a8f7ed..fabbb1a 100644 --- a/src/modules/common/ports/HTML5.cpp +++ b/src/modules/common/ports/HTML5.cpp @@ -1,4 +1,6 @@ #include "HTML5.h" +#include "common/ConfigManager.h" +#include extern "C" { // find these in contrib/installer/html5/library.js @@ -52,6 +54,14 @@ void HTML5::backtrace (const char *errorMessage) int HTML5::openURL (const std::string& url, bool newWindow) const { - _jsOpenURL(url.c_str(), newWindow); - return 0; + // fredygames: the web build never opens other pages + Log::info(LOG_COMMON, "not opening %s", url.c_str()); + return -1; +} + +// fredygames: called by the page when the tab is hidden or closed; the game itself only writes the +// settings when it shuts down (the campaign progress is written after each map) +extern "C" EMSCRIPTEN_KEEPALIVE void fredygames_save () +{ + Config.save(); } diff --git a/src/modules/common/ports/HTML5.h b/src/modules/common/ports/HTML5.h index 1b0c0a1..e1605a3 100644 --- a/src/modules/common/ports/HTML5.h +++ b/src/modules/common/ports/HTML5.h @@ -15,4 +15,6 @@ public: int openURL (const std::string& url, bool newWindow) const override; void backtrace (const char *errorMessage) override; bool supportsUserContent () const override { return false; } + // fredygames: the page has its own fullscreen button + bool isFullscreenSupported () override { return false; } }; diff --git a/src/modules/ui/windows/listener/TextureModeListener.h b/src/modules/ui/windows/listener/TextureModeListener.h index 235821a..7c140a0 100644 --- a/src/modules/ui/windows/listener/TextureModeListener.h +++ b/src/modules/ui/windows/listener/TextureModeListener.h @@ -19,6 +19,11 @@ public: void onClick () override { +#ifdef __EMSCRIPTEN__ + // fredygames: the web build only ships the "big" texture atlases + if (_textureSize != "big") + return; +#endif if (_serviceProvider.getTextureDefinition().getTextureSize() == _textureSize) return; const TextureDefinition& td = _serviceProvider.getTextureDefinition();