From 1f194a9dea346cec6799bb689eff6e3a7ba08b98 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 13 Jan 2024 10:36:44 +0000 Subject: [PATCH] Add basic argument processing --- Cargo.lock | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 45 +++++++++++++++++++--- 3 files changed, 148 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eba8e74..769f547 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,6 +181,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "approx" version = "0.5.1" @@ -1413,6 +1461,46 @@ dependencies = [ "libloading 0.8.1", ] +[[package]] +name = "clap" +version = "4.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58e54881c004cec7895b0068a0a954cd5d62da01aef83fa35b1e594497bf5445" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59cb82d7f531603d2fd1f507441cdd35184fa81beff7bd489570de7f773460bb" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.46", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + [[package]] name = "clipboard-win" version = "4.5.0" @@ -1440,6 +1528,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "com-rs" version = "0.2.1" @@ -3487,6 +3581,12 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "svg_fmt" version = "0.4.1" @@ -3548,6 +3648,7 @@ dependencies = [ "bevy", "bevy_ecs_tilemap", "bevy_editor_pls", + "clap", "image", "itertools", "slicetools", @@ -3823,6 +3924,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.6.1" diff --git a/Cargo.toml b/Cargo.toml index b371943..5b22cce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ tiled = "0.11.2" thiserror = "1.0.52" itertools = "0.12.0" slicetools = "0.3.0" +clap = { version = "4.4.16", features = ["derive"] } [features] editor = ["dep:bevy_editor_pls"] diff --git a/src/main.rs b/src/main.rs index 39eade7..ecd85f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use bevy::{ window, }; use bevy_ecs_tilemap::prelude::*; +use clap::Parser; use itertools::Itertools; use slicetools::*; use std::f32::consts::PI; @@ -17,15 +18,33 @@ mod helpers; mod util; use util::IteratorToArrayExt; +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Enable windowed mode (for debugging try: -wdd) + #[arg(short, long)] + window: bool, + + /// Turn debugging visualizations on + #[arg(short, long, action = clap::ArgAction::Count)] + debug: u8, +} + fn main() { + let args = Args::parse(); + App::new() .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { - title: "TRD2024 - Orcombe Point edition".to_string(), - resolution: (1920.0, 1080.0).into(), + title: "TDR2024 - Orcombe Point edition".to_string(), + resolution: (1280.0, 720.0).into(), present_mode: window::PresentMode::AutoVsync, - mode: window::WindowMode::BorderlessFullscreen, + mode: if args.window { + window::WindowMode::default() + } else { + window::WindowMode::BorderlessFullscreen + }, cursor: window::Cursor { visible: false, ..default() @@ -42,6 +61,7 @@ fn main() { .register_type::() .register_type::() .insert_resource(ClearColor(Color::rgb(0.053, 0.782, 0.276))) + .insert_resource(DebugLevel(args.debug)) .add_systems( Startup, (load_maps, spawn_camera, spawn_player, spawn_ai_players), @@ -64,6 +84,19 @@ fn main() { .run(); } +#[derive(Resource)] +struct DebugLevel(u8); + +impl DebugLevel { + fn low(&self) -> bool { + self.0 >= 1 + } + + fn high(&self) -> bool { + self.0 >= 2 + } +} + #[derive(Component, Debug)] struct Player; @@ -386,6 +419,7 @@ impl CollisionBox { fn collision_detection( mut query: Query<(&mut Transform, &Handle, &mut Velocity)>, texture_atlases: Res>, + debug: Res, mut gizmos: Gizmos, ) { let mut colliders = query.iter_mut().collect::>(); @@ -402,7 +436,7 @@ fn collision_detection( let mut abox = CollisionBox::from_transform(&a.0, &atx.size); let mut bbox = CollisionBox::from_transform(&b.0, &btx.size); - if false { + if debug.low() { abox.draw(&mut gizmos); bbox.draw(&mut gizmos); } @@ -456,6 +490,7 @@ fn handle_ai_players( )>, time: Res