diff options
author | Patric Stout <truebrain@openttd.org> | 2020-12-05 21:57:47 +0100 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2020-12-15 15:46:39 +0100 |
commit | d15dc9f40f5a20bff452547a2dcb15231f9f969d (patch) | |
tree | 7b8d88635c048d906cbb6358007fb26055e24410 /src/network/network_gui.cpp | |
parent | 2da07f76154d841bcfe9aaff4833144550186deb (diff) | |
download | openttd-d15dc9f40f5a20bff452547a2dcb15231f9f969d.tar.xz |
Add: support for emscripten (play-OpenTTD-in-the-browser)
Emscripten compiles to WASM, which can be loaded via
HTML / JavaScript. This allows you to play OpenTTD inside a
browser.
Co-authored-by: milek7 <me@milek7.pl>
Diffstat (limited to 'src/network/network_gui.cpp')
-rw-r--r-- | src/network/network_gui.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index c430c47e5..47bf8fb69 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -39,6 +39,9 @@ #include "../safeguards.h" +#ifdef __EMSCRIPTEN__ +# include <emscripten.h> +#endif static void ShowNetworkStartServerWindow(); static void ShowNetworkLobbyWindow(NetworkGameList *ngl); @@ -475,6 +478,14 @@ public: this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR; this->SetFocusedWidget(WID_NG_FILTER); + /* As the master-server doesn't support "websocket" servers yet, we + * let "os/emscripten/pre.js" hardcode a list of servers people can + * join. This means the serverlist is curated for now, but it is the + * best we can offer. */ +#ifdef __EMSCRIPTEN__ + EM_ASM(if (window["openttd_server_list"]) openttd_server_list()); +#endif + this->last_joined = NetworkGameListAddItem(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); this->server = this->last_joined; if (this->last_joined != nullptr) NetworkUDPQueryServer(this->last_joined->address); @@ -615,6 +626,12 @@ public: this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr); this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || !sel->online || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible); +#ifdef __EMSCRIPTEN__ + this->SetWidgetDisabledState(WID_NG_FIND, true); + this->SetWidgetDisabledState(WID_NG_ADD, true); + this->SetWidgetDisabledState(WID_NG_START, true); +#endif + this->DrawWidgets(); } |