From 21d98a4a1d5705146cec97098ed3fea164f7add0 Mon Sep 17 00:00:00 2001 From: tuxmain Date: Thu, 25 Aug 2022 15:52:28 +0200 Subject: [PATCH] cli: skip to level --- src/game.rs | 5 ++++- src/main.rs | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/game.rs b/src/game.rs index c335c75..eba3d44 100644 --- a/src/game.rs +++ b/src/game.rs @@ -21,6 +21,8 @@ pub enum AudioMsg { Switch, } +pub struct FirstLevel(pub LevelId); + #[derive(Clone, Copy, Eq, Hash, PartialEq)] pub struct LevelId(pub u32); @@ -99,12 +101,13 @@ pub struct CollisionCount(usize); // Systems fn setup( + first_level: Res, mut current_level: ResMut, mut level_startup_event: EventWriter, mut camera_query: Query<&mut Transform, With>, ) { if current_level.0.is_none() { - current_level.0 = Some(LevelId(0)); + current_level.0 = Some(first_level.0); } crate::levels::setup_level(&mut level_startup_event, &mut camera_query); diff --git a/src/main.rs b/src/main.rs index 08b60fa..6cb80d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,10 +26,20 @@ fn main() { #[cfg(not(target_arch = "wasm32"))] std::thread::spawn(move || audio::setup(audio_event_receiver)); + #[cfg(not(target_arch = "wasm32"))] + let first_level = game::LevelId( + std::env::args() + .nth(1) + .map_or(0, |s| s.parse().unwrap_or(0)), + ); + #[cfg(target_arch = "wasm32")] + let first_level = game::LevelId(0); + App::new() .insert_resource(Msaa { samples: 4 }) .insert_resource(audio_event_sender) .add_state(AppState::Menu) + .insert_resource(game::FirstLevel(first_level)) .insert_resource(ClearColor(Color::BLACK)) .add_plugins(DefaultPlugins) .add_plugin(RapierPhysicsPlugin::::pixels_per_meter(64.0))