4#include <unordered_map>
7#define APP_EXTENSION ".exe"
9#define APP_EXTENSION ""
18 "\t--help, -h Show this help message\n"
19 "\t--version, -v Show version information\n"
20 "\t--config, -c Specify path to config file\n";
29 std::ifstream file(path);
32 throw std::runtime_error(
"Cannot open config file: " + path);
38 if (j.contains(
"window"))
40 const auto &w = j[
"window"];
41 if (w.contains(
"width"))
43 cfg.
width = w[
"width"];
45 if (w.contains(
"height"))
49 if (w.contains(
"frame_limit"))
53 if (w.contains(
"fullscreen"))
57 const auto &p = j[
"plugins"];
58 if (p.contains(
"audio"))
62 if (p.contains(
"network"))
66 if (p.contains(
"renderer"))
70 if (p.contains(
"game_solo"))
74 if (p.contains(
"game_multi"))
78 const auto &c = j[
"client"];
79 if (c.contains(
"host"))
83 if (c.contains(
"port"))
87 if (c.contains(
"player_name"))
102 using ArgHandler = std::function<void(
const char *arg)>;
103 std::unordered_map<std::string_view, ArgHandler> handlers;
105 for (
const auto *
const opt : {
"-h",
"--help"})
107 handlers[opt] = [&config](
const char *)
113 for (
const auto *
const opt : {
"-v",
"--version"})
115 handlers[opt] = [&config](
const char *)
122 for (
const auto *
const opt : {
"-c",
"--config"})
124 handlers[opt] = [&config](
const char *arg)
128 throw std::runtime_error(
"Missing config file argument");
132 std::cout <<
"\tWidth: " << config.width <<
'\n'
133 <<
"\tHeight: " << config.height <<
'\n'
134 <<
"\tFrameLimit: " << config.frameLimit <<
"\n"
135 <<
"\tFullscreen: " << (config.fullscreen ?
"true" :
"false") <<
'\n';
139 const std::string_view key = argv[1];
140 const char *argValue = (argc > 2) ? argv[2] :
nullptr;
142 if (
const auto it = handlers.find(key); it != handlers.end())
144 it->second(argValue);
148 throw std::runtime_error(
"Unknown argument: " + std::string(key));
This file contains the Logger class.
static ArgsConfig ParseArgs(int argc, const char *const argv[])
static EnvConfig ParseEnv(const char *const env[])
static void log(const std::string &message, const LogLevel &logLevel)
This file contains the ArgsHandler class declaration.
static constexpr std::string_view VERSION_MESSAGE
static constexpr std::string_view HELP_MESSAGE
std::string game_multi_lib_path
static ArgsConfig fromFile(const std::string &path)
std::string audio_lib_path
std::string network_lib_path
std::string game_solo_lib_path
std::string renderer_lib_path