Added tools, cleaned up main
This commit is contained in:
92
src/main.rs
92
src/main.rs
@@ -1,43 +1,35 @@
|
||||
use std::env;
|
||||
|
||||
// mod models {
|
||||
// pub mod board;
|
||||
// pub mod piece;
|
||||
// pub mod networking;
|
||||
// }
|
||||
|
||||
fn print_help() {
|
||||
println!("Ey fam, hmu with dat '--serve' or '--join <address>'")
|
||||
}
|
||||
|
||||
fn start_game() {
|
||||
println!("OK");
|
||||
mod models {
|
||||
pub mod board;
|
||||
pub mod piece;
|
||||
pub mod networking;
|
||||
}
|
||||
use clap::{Arg, App, SubCommand};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if (args.len() == 2) && ((args[1] == "--serve") | (args[1] == "serve")) {
|
||||
let matches = App::new("Khetamine")
|
||||
.version("1.0")
|
||||
.author("oysteikt, felixalb")
|
||||
.about("Play Khet with your friends!")
|
||||
.arg(Arg::with_name("serve")
|
||||
.short("s")
|
||||
.long("serve")
|
||||
.help("Run as game server, your friend connects as client."))
|
||||
.arg(Arg::with_name("connect")
|
||||
.short("c")
|
||||
.help("Connect to a server")
|
||||
.value_name("ADRESS")
|
||||
.takes_value(true)
|
||||
.arg(Arg::with_name("v")
|
||||
.short("v")
|
||||
.multiple(true)
|
||||
.help("Sets the level of verbosity"))
|
||||
.subcommand(SubCommand::with_name("test")
|
||||
.about("Runs various tests")
|
||||
.version("1.3")
|
||||
.author("felixalb"))
|
||||
.get_matches();
|
||||
|
||||
//Start game server
|
||||
println!("Serving!");
|
||||
start_game();
|
||||
|
||||
} else if (args.len() == 3) && ((args[1] == "--join") | (args[1] == "join")) {
|
||||
|
||||
//Join game server
|
||||
println!("Joining!");
|
||||
start_game();
|
||||
|
||||
} else if (args.len() == 2) && (args[1] == "--help") {
|
||||
|
||||
print_help();
|
||||
|
||||
} else {
|
||||
|
||||
println!("What do you mean with {:?}\n", args);
|
||||
print_help();
|
||||
|
||||
}
|
||||
println!("{}", matches);
|
||||
|
||||
// println!("{}", &serialize_move(models::networking::Action::Rotate {
|
||||
// from: (2, 2),
|
||||
@@ -47,18 +39,16 @@ fn main() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// fn serialize_move(action: models::networking::Action) -> str {
|
||||
// let serialized = serde_json::to_string(&action);
|
||||
// match serialized {
|
||||
// Ok(s) => {
|
||||
// println!("OK: {}", s);
|
||||
// return &s;
|
||||
// },
|
||||
// Err(_e) => {
|
||||
// println!("Couldn't serialize...");
|
||||
// return ("");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
fn serialize_move(action: models::networking::Action) -> String {
|
||||
let serialized = serde_json::to_string(&action);
|
||||
match serialized {
|
||||
Ok(s) => {
|
||||
// println!("{}", s);
|
||||
return s;
|
||||
},
|
||||
Err(_e) => {
|
||||
println!("Couldn't serialize...");
|
||||
return String::from("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user