Skip to content

Commit

Permalink
[ClientApplication|ServerApplication] New parameter '-w/--working-dir…
Browse files Browse the repository at this point in the history
…' to set the working directory of the programs.
  • Loading branch information
Unarelith committed Mar 13, 2020
1 parent 085ef78 commit ceafa8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion client/source/core/ClientApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*
* =====================================================================================
*/
#include "filesystem.hpp"

#include <gk/core/input/GamePad.hpp>
#include <gk/core/Mouse.hpp>
#include <gk/gl/GLCheck.hpp>
Expand All @@ -37,7 +39,7 @@

#include "TitleScreenState.hpp"

using namespace std::literals::string_literals;
namespace fs = ghc::filesystem;

ClientApplication::ClientApplication(int argc, char **argv) : gk::CoreApplication(argc, argv) {
}
Expand All @@ -47,9 +49,13 @@ void ClientApplication::init() {
m_argumentParser.addArgument("port", {"-p", "--port", true});
m_argumentParser.addArgument("singleplayer", {"-s", "--singleplayer", false});
m_argumentParser.addArgument("multiplayer", {"-m", "--multiplayer", false});
m_argumentParser.addArgument("working_dir", {"-w", "--working-dir", true});

gk::CoreApplication::init();

if (m_argumentParser.getArgument("working_dir").isFound)
fs::current_path(m_argumentParser.getArgument("working_dir").parameter);

if (m_argumentParser.getArgument("host").isFound)
m_host = m_argumentParser.getArgument("host").parameter;
if (m_argumentParser.getArgument("port").isFound)
Expand Down
9 changes: 7 additions & 2 deletions server/source/core/ServerApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ namespace fs = ghc::filesystem;

ServerApplication::ServerApplication(int argc, char **argv) : m_argumentParser(argc, argv) {
std::srand(std::time(nullptr));
}

void ServerApplication::init() {
m_argumentParser.addArgument("port", {"-p", "--port", true});
m_argumentParser.addArgument("working_dir", {"-w", "--working-dir", true});

m_argumentParser.parse();
}

void ServerApplication::init() {
if (m_argumentParser.getArgument("working_dir").isFound)
fs::current_path(m_argumentParser.getArgument("working_dir").parameter);

if (m_argumentParser.getArgument("port").isFound)
m_port = std::stoi(m_argumentParser.getArgument("port").parameter);

Expand Down

0 comments on commit ceafa8c

Please sign in to comment.