diff --git a/src/exploration.rs b/src/exploration.rs index 4844347..f30776f 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -383,6 +383,9 @@ pub struct ExplorationPlugin { pub map_data: PhantomData, } +#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] +pub struct Exploration; + impl Plugin for ExplorationPlugin where ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Into, @@ -398,38 +401,30 @@ where .register_type::() .register_type::() .add_plugin(InputManagerPlugin::::default()) - .add_system( - exploration_changed_announcement:: - .pipe(error_handler) - .in_base_set(CoreSet::PostUpdate), - ); - if config.states.is_empty() { - app.add_systems(( - exploration_focus::, - exploration_type_focus::.pipe(error_handler), - exploration_type_change::.pipe(error_handler), - navigate_to_explored::, - )) - .add_system( - exploration_type_changed_announcement:: - .pipe(error_handler) - .in_base_set(CoreSet::PostUpdate), - ); - } else { + .add_systems( + ( + exploration_type_change::.pipe(error_handler), + exploration_type_changed_announcement::.pipe(error_handler), + ) + .chain() + .in_set(Exploration), + ) + .add_systems( + ( + exploration_focus::, + exploration_type_focus::.pipe(error_handler), + exploration_changed_announcement:: + .pipe(error_handler), + ) + .chain() + .in_set(Exploration), + ) + .add_system(navigate_to_explored::.in_set(Exploration)); + if !config.states.is_empty() { let states = config.states; for state in states { - app.add_systems( - ( - exploration_focus::, - exploration_type_focus::.pipe(error_handler), - exploration_type_change::.pipe(error_handler), - navigate_to_explored::, - exploration_type_changed_announcement:: - .pipe(error_handler), - ) - .in_set(OnUpdate(state.clone())), - ) - .add_system(cleanup.in_schedule(OnExit(state))); + app.configure_set(Exploration.in_set(OnUpdate(state.clone()))) + .add_system(cleanup.in_schedule(OnExit(state))); } } } diff --git a/src/navigation.rs b/src/navigation.rs index 10f349e..8ae3395 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -82,6 +82,58 @@ impl Default for Speed { } } +fn snap( + mut tts: ResMut, + mut snap_timers: ResMut, + mut query: Query< + ( + Entity, + &ActionState, + &mut Transform, + &CardinalDirection, + ), + With, + >, +) -> Result<(), Box> { + for (entity, actions, mut transform, direction) in &mut query { + if snap_timers.contains_key(&entity) { + continue; + } else if actions.just_pressed(NavigationAction::SnapLeft) { + snap_timers.insert(entity, SnapTimer::default()); + transform.rotation = Quat::from_rotation_z(match direction { + CardinalDirection::North => PI, + CardinalDirection::East => PI / 2., + CardinalDirection::South => 0., + CardinalDirection::West => -PI / 2., + }); + } else if actions.just_pressed(NavigationAction::SnapRight) { + snap_timers.insert(entity, SnapTimer::default()); + transform.rotation = Quat::from_rotation_z(match direction { + CardinalDirection::North => 0., + CardinalDirection::East => -PI / 2., + CardinalDirection::South => PI, + CardinalDirection::West => PI / 2., + }); + } else if actions.just_pressed(NavigationAction::SnapReverse) { + snap_timers.insert(entity, SnapTimer::default()); + transform.rotate(Quat::from_rotation_z(PI)); + } else if actions.just_pressed(NavigationAction::SnapCardinal) { + let yaw: Angle = direction.into(); + let yaw = yaw.radians(); + transform.rotation = Quat::from_rotation_z(yaw); + tts.speak(direction.to_string(), true)?; + } + } + Ok(()) +} + +fn tick_snap_timers(time: Res