cli: skip to level

This commit is contained in:
Pascal Engélibert 2022-08-25 15:52:28 +02:00
parent 445f3850ca
commit 21d98a4a1d
Signed by: tuxmain
GPG key ID: 3504BC6D362F7DCA
2 changed files with 14 additions and 1 deletions

View file

@ -21,6 +21,8 @@ pub enum AudioMsg {
Switch, Switch,
} }
pub struct FirstLevel(pub LevelId);
#[derive(Clone, Copy, Eq, Hash, PartialEq)] #[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct LevelId(pub u32); pub struct LevelId(pub u32);
@ -99,12 +101,13 @@ pub struct CollisionCount(usize);
// Systems // Systems
fn setup( fn setup(
first_level: Res<FirstLevel>,
mut current_level: ResMut<CurrentLevel>, mut current_level: ResMut<CurrentLevel>,
mut level_startup_event: EventWriter<LevelStartupEvent>, mut level_startup_event: EventWriter<LevelStartupEvent>,
mut camera_query: Query<&mut Transform, With<Camera>>, mut camera_query: Query<&mut Transform, With<Camera>>,
) { ) {
if current_level.0.is_none() { 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); crate::levels::setup_level(&mut level_startup_event, &mut camera_query);

View file

@ -26,10 +26,20 @@ fn main() {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
std::thread::spawn(move || audio::setup(audio_event_receiver)); 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() App::new()
.insert_resource(Msaa { samples: 4 }) .insert_resource(Msaa { samples: 4 })
.insert_resource(audio_event_sender) .insert_resource(audio_event_sender)
.add_state(AppState::Menu) .add_state(AppState::Menu)
.insert_resource(game::FirstLevel(first_level))
.insert_resource(ClearColor(Color::BLACK)) .insert_resource(ClearColor(Color::BLACK))
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(64.0)) .add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(64.0))