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:
2026-06-27 15:13:25 +08:00
parent 3d4490a46b
commit 20402d1fda
4 changed files with 14 additions and 7 deletions

View File

@@ -136,7 +136,7 @@ add_executable(${PROJECT_NAME}
src/gameplay/builders/snowy_plain_builder.cpp
src/gameplay/river_worm.cpp
src/gameplay/river_path.cpp
src/block.cpp
src/gameplay/block.cpp
src/gameplay/vertex_data.cpp
src/gameplay/builders/ocean_builder.cpp
src/gameplay/network_server.cpp

View File

@@ -16,6 +16,7 @@ public:
bool is_client = false;
int port = 25530;
std::string ip{"127.0.0.1"};
std::string player{"Unknown"};
};
App();

View File

@@ -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,

View File

@@ -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) {