You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
//! 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("editor")
|
|
.help("Instead of running the main game screen, run the map editor instead")
|
|
.long("editor"),
|
|
)
|
|
.arg(
|
|
Arg::with_name("assets")
|
|
.takes_value(true)
|
|
.default_value("./assets/raw")
|
|
.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;
|
|
}
|
|
|
|
settings.editor = matches.is_present("editor");
|
|
}
|
|
|