aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-client/src/cli.rs
blob: b13697adb29ac16a1eea44c89255afde76fa385e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
    }
}