diff options
Diffstat (limited to 'games/rstnode/rst-client/src/cli.rs')
-rw-r--r-- | games/rstnode/rst-client/src/cli.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/games/rstnode/rst-client/src/cli.rs b/games/rstnode/rst-client/src/cli.rs index b8a93b237a7b..b13697adb29a 100644 --- a/games/rstnode/rst-client/src/cli.rs +++ b/games/rstnode/rst-client/src/cli.rs @@ -1 +1,57 @@ //! Handle user CLI inputs + +use crate::{ + constants::{NAME, VERSION}, + settings::WindowMode, + GameSettings, +}; +use clap::{App, Arg}; +use std::path::PathBuf; + +/// Run CLI parser and parse options into GameSettings structure +pub fn parse(settings: &mut GameSettings) { + let app = App::new(NAME) + .version(VERSION) + .author("Bread Machine (Katharina Fey <kookie@spacekookie.de)") + .about("Main game client - consider running the game via the launcher instead") + .arg( + Arg::with_name("assets") + .required(true) + .takes_value(true) + .help("Specify the path to load assets from"), + ) + .arg( + Arg::with_name("width") + .short("w") + .takes_value(true) + .help("Set the desired game window width"), + ) + .arg( + Arg::with_name("height") + .short("h") + .takes_value(true) + .help("Set the desired game window height"), + ) + .arg( + Arg::with_name("fullscreen") + .short("f") + .help("Specify if the game should run full screen"), + ); + + let matches = app.get_matches(); + if let Some(assets) = matches.value_of("assets") { + settings.assets = Some(PathBuf::new().join(assets)); + } + + if let Some(width) = matches.value_of("width") { + settings.window.width = str::parse(width).unwrap(); + } + + if let Some(height) = matches.value_of("height") { + settings.window.height = str::parse(height).unwrap(); + } + + if matches.is_present("fullscreen") { + settings.window.window_mode = WindowMode::Fullscreen; + } +} |