implement map selection in cli
This commit is contained in:
parent
d95eedcc83
commit
2fec5e4509
3 changed files with 21 additions and 6 deletions
|
@ -22,6 +22,9 @@ struct PlayMatch {
|
|||
#[clap(value_parser)]
|
||||
opponent_name: String,
|
||||
|
||||
#[clap(value_parser, long = "map")]
|
||||
map_name: Option<String>,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
long,
|
||||
|
@ -69,9 +72,13 @@ async fn main() {
|
|||
|
||||
let channel = Channel::builder(uri).connect().await.unwrap();
|
||||
|
||||
let created_match = create_match(channel.clone(), play_match.opponent_name)
|
||||
.await
|
||||
.unwrap();
|
||||
let created_match = create_match(
|
||||
channel.clone(),
|
||||
play_match.opponent_name,
|
||||
play_match.map_name,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
run_player(bot_config, created_match.player_key, channel).await;
|
||||
println!(
|
||||
"Match completed. Watch the replay at {}",
|
||||
|
@ -83,10 +90,14 @@ async fn main() {
|
|||
async fn create_match(
|
||||
channel: Channel,
|
||||
opponent_name: String,
|
||||
map_name: Option<String>,
|
||||
) -> Result<pb::CreateMatchResponse, Status> {
|
||||
let mut client = ClientApiServiceClient::new(channel);
|
||||
let res = client
|
||||
.create_match(Request::new(pb::CreateMatchRequest { opponent_name }))
|
||||
.create_match(Request::new(pb::CreateMatchRequest {
|
||||
opponent_name,
|
||||
map_name: map_name.unwrap_or_default(),
|
||||
}))
|
||||
.await;
|
||||
res.map(|response| response.into_inner())
|
||||
}
|
||||
|
|
|
@ -111,8 +111,11 @@ impl pb::client_api_service_server::ClientApiService for ClientApiServer {
|
|||
db::bots::find_bot_with_version_by_name(&match_request.opponent_name, &conn)
|
||||
.map_err(|_| Status::not_found("opponent not found"))?;
|
||||
|
||||
// TODO: allow map as parameter here
|
||||
let map = db::maps::find_map_by_name(&"hex", &conn)
|
||||
let map_name = match match_request.map_name.as_str() {
|
||||
"" => "hex",
|
||||
name => name,
|
||||
};
|
||||
let map = db::maps::find_map_by_name(map_name, &conn)
|
||||
.map_err(|_| Status::not_found("map not found"))?;
|
||||
|
||||
let player_key = gen_alphanumeric(32);
|
||||
|
|
|
@ -10,6 +10,7 @@ service ClientApiService {
|
|||
|
||||
message CreateMatchRequest {
|
||||
string opponent_name = 1;
|
||||
string map_name = 2;
|
||||
}
|
||||
|
||||
message CreateMatchResponse {
|
||||
|
|
Loading…
Reference in a new issue