#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
#![deny(missing_docs)]
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*;
use bevy_picking_core::PickSet;
pub mod mouse;
pub mod touch;
pub mod prelude {
pub use crate::{InputPlugin, InputPluginSettings};
}
pub struct InputPlugin;
impl Plugin for InputPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<InputPluginSettings>()
.add_systems(Startup, mouse::spawn_mouse_pointer)
.add_systems(
First,
(
touch::touch_pick_events.run_if(InputPluginSettings::is_touch_enabled),
mouse::mouse_pick_events.run_if(InputPluginSettings::is_mouse_enabled),
apply_deferred,
)
.chain()
.in_set(PickSet::Input),
)
.add_systems(
Last,
touch::deactivate_touch_pointers.run_if(InputPluginSettings::is_touch_enabled),
)
.register_type::<InputPluginSettings>();
}
}
#[derive(Resource, Debug, Reflect)]
#[reflect(Resource, Default)]
pub struct InputPluginSettings {
pub is_touch_enabled: bool,
pub is_mouse_enabled: bool,
}
impl Default for InputPluginSettings {
fn default() -> Self {
Self {
is_touch_enabled: true,
is_mouse_enabled: true,
}
}
}
impl InputPluginSettings {
fn is_touch_enabled(state: Res<Self>) -> bool {
state.is_touch_enabled
}
fn is_mouse_enabled(state: Res<Self>) -> bool {
state.is_mouse_enabled
}
}