Skip to content

Commit

Permalink
Merge branch 'feature/RB-142-menu-de-connection' of github.com:X-R-G-…
Browse files Browse the repository at this point in the history
…B/R-Bus into feature/RB-142-menu-de-connection
  • Loading branch information
KitetsuK committed Nov 2, 2023
2 parents 4e89f34 + fbfe9c6 commit 4f393fe
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
10 changes: 6 additions & 4 deletions src/Client/Systems/Menus/CreateLobby/CreateLobbySystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
namespace Systems {
namespace CreateLobby {


void initCreateLobby(std::size_t managerId, std::size_t systemId)
{
if (Scene::SceneManager::getInstance().getCurrentScene() != Scene::Scene::CREATE_LOBBY) {
SystemManagersDirector::getInstance().getSystemManager(managerId).removeSystem(systemId);
return;
}
try {
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>("createLobbyMenu", JsonType::CREATE_LOBBY);
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(Json::getInstance().getDatasFromList(jsonData));
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>(
"createLobbyMenu",
JsonType::CREATE_LOBBY);
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
} catch (const std::exception &err) {
Logger::error(
"Counldn't load menu correctly, verify your json data : " + std::string(err.what()));
Expand All @@ -47,4 +49,4 @@ namespace Systems {
}

} // namespace CreateLobby
} // namespace Systems
} // namespace Systems
36 changes: 18 additions & 18 deletions src/Client/Systems/Menus/Menu/ButtonCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#pragma once

#include <unordered_map>
#include <functional>
#include <unordered_map>
#include "Json.hpp"

namespace Menu {
Expand All @@ -27,15 +27,15 @@ namespace Menu {

NLOHMANN_JSON_SERIALIZE_ENUM(
CallbackType,
{
{DEFAULT_CALLBACK, nullptr},
{INIT_CONNECTION, "initConnection"},
{CONNECT, "connectLobbySelected"},
{CREATE, "onButtonGoToCreateLobbyClicked"},
{GO_BACK, "goBackPage"},
{GO_NEXT, "goNextPage"},
{GO_SELECT_LOBBY, "goToSelectLobby"},
{CREATE_NORMAL, "onButtonCreateLobbyNormalClicked"}
{
{DEFAULT_CALLBACK, nullptr },
{INIT_CONNECTION, "initConnection" },
{CONNECT, "connectLobbySelected" },
{CREATE, "onButtonGoToCreateLobbyClicked" },
{GO_BACK, "goBackPage" },
{GO_NEXT, "goNextPage" },
{GO_SELECT_LOBBY, "goToSelectLobby" },
{CREATE_NORMAL, "onButtonCreateLobbyNormalClicked"}
});

void initConnection();
Expand All @@ -55,14 +55,14 @@ namespace Menu {
void onButtonCreateLobbyNormalClicked();

const std::unordered_map<CallbackType, std::function<void()>> callbacks = {
{CallbackType::DEFAULT_CALLBACK, &defaultCallBack},
{CallbackType::INIT_CONNECTION, &initConnection},
{CallbackType::CONNECT, &connectLobbySelected},
{CallbackType::CREATE, &onButtonGotoCreateLobbyClicked},
{CallbackType::GO_SELECT_LOBBY, &gotToSelectLobby},
{CallbackType::GO_BACK, &goBackPage},
{CallbackType::GO_NEXT, &goNextPage},
{CallbackType::CREATE_NORMAL, &onButtonCreateLobbyNormalClicked}
{CallbackType::DEFAULT_CALLBACK, &defaultCallBack },
{CallbackType::INIT_CONNECTION, &initConnection },
{CallbackType::CONNECT, &connectLobbySelected },
{CallbackType::CREATE, &onButtonGotoCreateLobbyClicked },
{CallbackType::GO_SELECT_LOBBY, &gotToSelectLobby },
{CallbackType::GO_BACK, &goBackPage },
{CallbackType::GO_NEXT, &goNextPage },
{CallbackType::CREATE_NORMAL, &onButtonCreateLobbyNormalClicked}
};

} // namespace Callback
Expand Down
5 changes: 3 additions & 2 deletions src/Client/Systems/Menus/Menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ namespace Menu {
if (elem.is_array()) {
throw std::runtime_error("Error while loading entity : data is array");
}
std::function<void()> callback = Callback::callbacks.at(elem["callback"].get<Callback::CallbackType>());
std::function<void()> callback =
Callback::callbacks.at(elem["callback"].get<Callback::CallbackType>());

switch (Json::getInstance().getDataFromJson<ObjectType>(elem, "type")) {
case ObjectType::BUTTON: return (initButton(elem, callback));
Expand All @@ -225,7 +226,7 @@ namespace Menu {
} catch (std::runtime_error &err) {
Logger::error(
"Counldn't load menu correctly, verify your json data : " + std::string(err.what()));
throw std::runtime_error("Cannot load scene menu correctly.");
throw std::runtime_error("Cannot load scene menu correctly.");
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Client/Systems/Menus/Menu/Menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ namespace Menu {
* @param callback Optional callback function for the menu entity. Defaults to
* Menu::Callback::defaultCallBack.
*/
std::size_t initMenuEntity(
nlohmann::json &elem);
std::size_t initMenuEntity(nlohmann::json &elem);
void initMenuSceneEntity(nlohmann::json sceneMenuData);

private:
Expand Down
6 changes: 4 additions & 2 deletions src/Client/Systems/Menus/Menu/MenuSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ namespace Systems {
return;
}
try {
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>("menu", JsonType::MENU);
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(Json::getInstance().getDatasFromList(jsonData));
nlohmann::json jsonData =
Json::getInstance().getDataByJsonType<nlohmann::json>("menu", JsonType::MENU);
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));

} catch (std::runtime_error &err) {
Logger::info(err.what());
Expand Down
10 changes: 7 additions & 3 deletions src/Client/Systems/Menus/SelectLobby/SelectLobbySystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ namespace Systems::SelectLobbySystems {
return;
}
try {
nlohmann::json jsonData = Json::getInstance().getDataByJsonType<nlohmann::json>("lobbyMenu", JsonType::SELECT_LOBBY);
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(Json::getInstance().getDatasFromList(jsonData));
nlohmann::json jsonData =
Json::getInstance().getDataByJsonType<nlohmann::json>("lobbyMenu", JsonType::SELECT_LOBBY);
::Menu::MenuBuilder::getInstance().initMenuSceneEntity(
Json::getInstance().getDatasFromList(jsonData));
} catch (const std::exception &err) {
Logger::error(
"Counldn't load menu correctly, verify your json data : " + std::string(err.what()));
Expand Down Expand Up @@ -74,7 +76,9 @@ namespace Systems::SelectLobbySystems {

try {
for (std::size_t i = 0; i < 5; i++) {
nlohmann::json lobbyBox = Json::getInstance().getDataByJsonType<nlohmann::json>("inputBoxes", JsonType::SELECT_LOBBY);
nlohmann::json lobbyBox = Json::getInstance().getDataByJsonType<nlohmann::json>(
"inputBoxes",
JsonType::SELECT_LOBBY);

std::size_t id = ::Menu::MenuBuilder::getInstance().initMenuEntity(lobbyBox);
if (arrPosition.exist(id)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Nitwork/NitworkMainServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,13 @@ namespace Nitwork {
int ownerPort)
{
#ifdef _WIN32
std::string winName = "\"" + name + "\"";
std::basic_ostringstream<TCHAR> cmdline;
cmdline << _T(ECS::ResourcesManager::convertPath(
"./r-type_server.exe",
ECS::ResourcesManager::FileType::BINARY)
.c_str())
<< _T(" 1 ") << _T(maxNbPlayer) << _T(" ") << _T(gameType) << _T(" ") << _T(name.c_str())
<< _T(" 1 ") << _T(maxNbPlayer) << _T(" ") << _T(gameType) << _T(" ") << _T(winName.c_str())
<< _T(" ") << _T(ownerIp.c_str()) << _T(" ") << _T(ownerPort);

Logger::fatal("cmdline: " + cmdline.str());
Expand Down

0 comments on commit 4f393fe

Please sign in to comment.