add command line options for help, and for setting window mode
This commit is contained in:
parent
e7600d1060
commit
729e6be59d
60
src/main.rs
60
src/main.rs
|
@ -32,11 +32,32 @@ use bevy::prelude::*;
|
||||||
use bevy::pbr::ExtendedMaterial;
|
use bevy::pbr::ExtendedMaterial;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
const HELP: &str = "./outfly [options]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--version, -v show this program's version number and exit
|
||||||
|
--help, -h show this help message and exit
|
||||||
|
--gl use GL rendering instead of Vulkan
|
||||||
|
--fs-legacy use 'legacy' (non-borderless) fullscreen mode
|
||||||
|
--fs-sized use 'sized' (non-borderless) fullscreen mode
|
||||||
|
--windowed start in non-fullscreen mode
|
||||||
|
|
||||||
|
Note: borderless fullscreen is the default, but it crashes on some systems.";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let mut opt = CommandLineOptions {
|
||||||
|
window_mode_fullscreen: WindowMode::BorderlessFullscreen,
|
||||||
|
window_mode_initial: WindowMode::BorderlessFullscreen,
|
||||||
|
};
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
for arg in &args[1..] {
|
for arg in &args[1..] {
|
||||||
if arg == "--version" || arg == "-v" {
|
if arg == "--help" || arg == "-h" {
|
||||||
|
println!("{}", HELP);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if arg == "--version" || arg == "-v" {
|
||||||
let version = option_env!("CARGO_PKG_VERSION").unwrap();
|
let version = option_env!("CARGO_PKG_VERSION").unwrap();
|
||||||
let name = option_env!("CARGO_PKG_NAME").unwrap();
|
let name = option_env!("CARGO_PKG_NAME").unwrap();
|
||||||
let homepage = option_env!("CARGO_PKG_HOMEPAGE").unwrap();
|
let homepage = option_env!("CARGO_PKG_HOMEPAGE").unwrap();
|
||||||
|
@ -48,13 +69,38 @@ fn main() {
|
||||||
else if arg == "--gl" {
|
else if arg == "--gl" {
|
||||||
env::set_var("WGPU_BACKEND", "gl");
|
env::set_var("WGPU_BACKEND", "gl");
|
||||||
}
|
}
|
||||||
|
else if arg == "--windowed" {
|
||||||
|
opt.window_mode_initial = WindowMode::Windowed;
|
||||||
|
}
|
||||||
|
else if arg == "--fs-legacy" {
|
||||||
|
let mode = WindowMode::Fullscreen;
|
||||||
|
if opt.window_mode_initial == opt.window_mode_fullscreen {
|
||||||
|
opt.window_mode_initial = mode;
|
||||||
|
}
|
||||||
|
opt.window_mode_fullscreen = mode;
|
||||||
|
}
|
||||||
|
else if arg == "--fs-sized" {
|
||||||
|
let mode = WindowMode::SizedFullscreen;
|
||||||
|
if opt.window_mode_initial == opt.window_mode_fullscreen {
|
||||||
|
opt.window_mode_initial = mode;
|
||||||
|
}
|
||||||
|
opt.window_mode_fullscreen = mode;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println!("{}", HELP);
|
||||||
|
println!("\nERROR: no such option: `{}`", arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
|
app.insert_resource(opt);
|
||||||
|
|
||||||
#[cfg(feature = "embed_assets")]
|
#[cfg(feature = "embed_assets")]
|
||||||
app.add_plugins(bevy_embedded_assets::EmbeddedAssetPlugin {
|
app.add_plugins(bevy_embedded_assets::EmbeddedAssetPlugin {
|
||||||
mode: bevy_embedded_assets::PluginMode::ReplaceDefault
|
mode: bevy_embedded_assets::PluginMode::ReplaceDefault
|
||||||
});
|
});
|
||||||
|
|
||||||
app.add_plugins(OutFlyPlugin).run();
|
app.add_plugins(OutFlyPlugin).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +130,20 @@ impl Plugin for OutFlyPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Resource, Default)]
|
||||||
|
pub struct CommandLineOptions {
|
||||||
|
window_mode_fullscreen: WindowMode,
|
||||||
|
window_mode_initial: WindowMode,
|
||||||
|
}
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
||||||
|
opt: Res<CommandLineOptions>,
|
||||||
) {
|
) {
|
||||||
for mut window in &mut windows {
|
for mut window in &mut windows {
|
||||||
window.cursor.grab_mode = CursorGrabMode::Locked;
|
window.cursor.grab_mode = CursorGrabMode::Locked;
|
||||||
window.cursor.visible = false;
|
window.cursor.visible = false;
|
||||||
window.mode = WindowMode::BorderlessFullscreen;
|
window.mode = opt.window_mode_initial;
|
||||||
window.title = "OutFly".to_string();
|
window.title = "OutFly".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +151,7 @@ fn setup(
|
||||||
fn handle_input(
|
fn handle_input(
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
settings: Res<var::Settings>,
|
settings: Res<var::Settings>,
|
||||||
|
opt: Res<CommandLineOptions>,
|
||||||
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>,
|
||||||
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
||||||
) {
|
) {
|
||||||
|
@ -107,7 +161,7 @@ fn handle_input(
|
||||||
if keyboard_input.just_pressed(settings.key_fullscreen) {
|
if keyboard_input.just_pressed(settings.key_fullscreen) {
|
||||||
for mut window in &mut windows {
|
for mut window in &mut windows {
|
||||||
window.mode = if window.mode == WindowMode::Windowed {
|
window.mode = if window.mode == WindowMode::Windowed {
|
||||||
WindowMode::BorderlessFullscreen
|
opt.window_mode_fullscreen
|
||||||
} else {
|
} else {
|
||||||
WindowMode::Windowed
|
WindowMode::Windowed
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue