mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat: add player name configuration and rename config file
- Add --player command-line argument and 'player' field in Arguments struct - Rename ip.toml to server.toml and corresponding internal variable to 'server' - Fix block.cpp source path in CMakeLists.txt
This commit is contained in:
17
src/app.cpp
17
src/app.cpp
@@ -74,7 +74,7 @@ void App::init(int argc, char** argv) {
|
||||
|
||||
m_client->start(m_argument.ip, m_argument.port);
|
||||
// init will send packet
|
||||
m_client_world.init("test", m_client);
|
||||
m_client_world.init(m_argument.player, m_client);
|
||||
|
||||
Logger::info("World Init Success");
|
||||
|
||||
@@ -114,6 +114,11 @@ void App::handle_argument(int argc, char** argv) {
|
||||
[&](ArgParser& p) {
|
||||
auto arg = p.require_next("--ip");
|
||||
m_argument.ip = arg;
|
||||
}},
|
||||
{"--player",
|
||||
[&](ArgParser& p) {
|
||||
auto arg = p.require_next("--player");
|
||||
m_argument.player = arg;
|
||||
}}
|
||||
|
||||
};
|
||||
@@ -130,17 +135,17 @@ void App::handle_argument(int argc, char** argv) {
|
||||
}
|
||||
|
||||
void App::handle_toml() {
|
||||
toml::table ip;
|
||||
toml::table server;
|
||||
try {
|
||||
ip = toml::parse_file("ip.toml");
|
||||
server = toml::parse_file("server.toml");
|
||||
} catch (const toml::parse_error& e) {
|
||||
Logger::warn("Ip toml parse error {}", e.what());
|
||||
return;
|
||||
}
|
||||
|
||||
m_argument.ip = *TOML::safe_get_value(ip, "ip", "127.0.01");
|
||||
m_argument.port = *TOML::safe_get_value(ip, "port", 25530);
|
||||
m_argument.is_client = *TOML::safe_get_value(ip, "client", false);
|
||||
m_argument.ip = *TOML::safe_get_value(server, "ip", "127.0.01");
|
||||
m_argument.port = *TOML::safe_get_value(server, "port", 25530);
|
||||
m_argument.is_client = *TOML::safe_get_value(server, "client", false);
|
||||
}
|
||||
|
||||
void App::key_callback(GLFWwindow* window, int key, int scancode, int action,
|
||||
|
||||
@@ -582,6 +582,7 @@ void DevPanel::show_player_tab_item() {
|
||||
return;
|
||||
}
|
||||
if (ImGui::BeginTabItem("player")) {
|
||||
ImGui::Text("Player %s", m_player->get_name().c_str());
|
||||
if (ImGui::Combo("GameMode", &m_player_profile.game_mode, GAME_MODES,
|
||||
IM_ARRAYSIZE(GAME_MODES))) {
|
||||
if (m_player_profile.game_mode == 0) {
|
||||
|
||||
Reference in New Issue
Block a user