Merge branch 'spark'
This commit is contained in:
commit
5e7c050c68
3 files changed
+205
-7
No files matched your search
+57
-4
@@ -1,6 +1,11 @@
|
||||
#include "MenuManager.h"
|
||||
#include <iostream>
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
namespace ZL {
|
||||
|
||||
extern bool inverseVertical;
|
||||
@@ -55,15 +60,39 @@ namespace ZL {
|
||||
state = GameState::ShipSelectionSingle;
|
||||
uiManager.replaceRoot(shipSelectionRoot);
|
||||
|
||||
uiManager.setButtonCallback("spaceshipButton", [this](const std::string&) {
|
||||
std::string initialNick;
|
||||
#ifdef EMSCRIPTEN
|
||||
char* savedNickC = emscripten_run_script_string("localStorage.getItem('spacegame_nick') || ''");
|
||||
if (savedNickC) {
|
||||
initialNick = savedNickC;
|
||||
free(savedNickC);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto tf = uiManager.findTextField("nicknameInput");
|
||||
if (tf) {
|
||||
if (!initialNick.empty()) tf->text = initialNick;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
uiManager.setTextFieldCallback("nicknameInput", [](const std::string&, const std::string& value) {
|
||||
EM_ASM_({
|
||||
try { localStorage.setItem('spacegame_nick', UTF8ToString($0)); } catch(e) {}
|
||||
}, value.c_str());
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
uiManager.setButtonCallback("spaceshipButton", [this, initialNick](const std::string&) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = initialNick;
|
||||
if (nick.empty()) nick = "Player";
|
||||
enterGameplay();
|
||||
if (onSingleplayerPressed) onSingleplayerPressed(nick, 0);
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("cargoshipButton", [this](const std::string&) {
|
||||
uiManager.setButtonCallback("cargoshipButton", [this, initialNick](const std::string&) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = initialNick;
|
||||
if (nick.empty()) nick = "Player";
|
||||
enterGameplay();
|
||||
if (onSingleplayerPressed) onSingleplayerPressed(nick, 1);
|
||||
@@ -81,8 +110,31 @@ namespace ZL {
|
||||
state = GameState::ShipSelectionMulti;
|
||||
uiManager.replaceRoot(shipSelectionRoot);
|
||||
|
||||
uiManager.setButtonCallback("spaceshipButton", [this](const std::string&) {
|
||||
std::string initialNick;
|
||||
#ifdef EMSCRIPTEN
|
||||
char* savedNickC = emscripten_run_script_string("localStorage.getItem('spacegame_nick') || ''");
|
||||
if (savedNickC) {
|
||||
initialNick = savedNickC;
|
||||
free(savedNickC);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto tf = uiManager.findTextField("nicknameInput");
|
||||
if (tf) {
|
||||
if (!initialNick.empty()) tf->text = initialNick;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
uiManager.setTextFieldCallback("nicknameInput", [](const std::string&, const std::string& value) {
|
||||
EM_ASM_({
|
||||
try { localStorage.setItem('spacegame_nick', UTF8ToString($0)); } catch(e) {}
|
||||
}, value.c_str());
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
uiManager.setButtonCallback("spaceshipButton", [this, initialNick](const std::string&) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = initialNick;
|
||||
if (nick.empty()) nick = "Player";
|
||||
pendingMultiNick = nick;
|
||||
pendingMultiShipType = 0;
|
||||
@@ -90,8 +142,9 @@ namespace ZL {
|
||||
if (onMultiplayerPressed) onMultiplayerPressed(nick, 0);
|
||||
});
|
||||
|
||||
uiManager.setButtonCallback("cargoshipButton", [this](const std::string&) {
|
||||
uiManager.setButtonCallback("cargoshipButton", [this, initialNick](const std::string&) {
|
||||
std::string nick = uiManager.getTextFieldValue("nicknameInput");
|
||||
if (nick.empty()) nick = initialNick;
|
||||
if (nick.empty()) nick = "Player";
|
||||
pendingMultiNick = nick;
|
||||
pendingMultiShipType = 1;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ZL {
|
||||
// Формируем URL. Обратите внимание, что в Web часто лучше использовать ws://localhost
|
||||
//std::string url = "ws://" + host + ":" + std::to_string(port);
|
||||
std::string url = "wss://api.spacegame.fishrungames.com";
|
||||
|
||||
//std::string url = "ws://localhost:8081";
|
||||
EmscriptenWebSocketCreateAttributes attr = {
|
||||
url.c_str(),
|
||||
nullptr,
|
||||
|
||||
Reference in new issue
Block a user