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:
@@ -136,7 +136,7 @@ add_executable(${PROJECT_NAME}
|
|||||||
src/gameplay/builders/snowy_plain_builder.cpp
|
src/gameplay/builders/snowy_plain_builder.cpp
|
||||||
src/gameplay/river_worm.cpp
|
src/gameplay/river_worm.cpp
|
||||||
src/gameplay/river_path.cpp
|
src/gameplay/river_path.cpp
|
||||||
src/block.cpp
|
src/gameplay/block.cpp
|
||||||
src/gameplay/vertex_data.cpp
|
src/gameplay/vertex_data.cpp
|
||||||
src/gameplay/builders/ocean_builder.cpp
|
src/gameplay/builders/ocean_builder.cpp
|
||||||
src/gameplay/network_server.cpp
|
src/gameplay/network_server.cpp
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
bool is_client = false;
|
bool is_client = false;
|
||||||
int port = 25530;
|
int port = 25530;
|
||||||
std::string ip{"127.0.0.1"};
|
std::string ip{"127.0.0.1"};
|
||||||
|
std::string player{"Unknown"};
|
||||||
};
|
};
|
||||||
|
|
||||||
App();
|
App();
|
||||||
|
|||||||
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);
|
m_client->start(m_argument.ip, m_argument.port);
|
||||||
// init will send packet
|
// 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");
|
Logger::info("World Init Success");
|
||||||
|
|
||||||
@@ -114,6 +114,11 @@ void App::handle_argument(int argc, char** argv) {
|
|||||||
[&](ArgParser& p) {
|
[&](ArgParser& p) {
|
||||||
auto arg = p.require_next("--ip");
|
auto arg = p.require_next("--ip");
|
||||||
m_argument.ip = arg;
|
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() {
|
void App::handle_toml() {
|
||||||
toml::table ip;
|
toml::table server;
|
||||||
try {
|
try {
|
||||||
ip = toml::parse_file("ip.toml");
|
server = toml::parse_file("server.toml");
|
||||||
} catch (const toml::parse_error& e) {
|
} catch (const toml::parse_error& e) {
|
||||||
Logger::warn("Ip toml parse error {}", e.what());
|
Logger::warn("Ip toml parse error {}", e.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_argument.ip = *TOML::safe_get_value(ip, "ip", "127.0.01");
|
m_argument.ip = *TOML::safe_get_value(server, "ip", "127.0.01");
|
||||||
m_argument.port = *TOML::safe_get_value(ip, "port", 25530);
|
m_argument.port = *TOML::safe_get_value(server, "port", 25530);
|
||||||
m_argument.is_client = *TOML::safe_get_value(ip, "client", false);
|
m_argument.is_client = *TOML::safe_get_value(server, "client", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::key_callback(GLFWwindow* window, int key, int scancode, int action,
|
void App::key_callback(GLFWwindow* window, int key, int scancode, int action,
|
||||||
|
|||||||
@@ -582,6 +582,7 @@ void DevPanel::show_player_tab_item() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ImGui::BeginTabItem("player")) {
|
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,
|
if (ImGui::Combo("GameMode", &m_player_profile.game_mode, GAME_MODES,
|
||||||
IM_ARRAYSIZE(GAME_MODES))) {
|
IM_ARRAYSIZE(GAME_MODES))) {
|
||||||
if (m_player_profile.game_mode == 0) {
|
if (m_player_profile.game_mode == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user