chore: remove bevy_mod_xr::actions
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -1,107 +0,0 @@
|
|||||||
use std::{any::TypeId, marker::PhantomData};
|
|
||||||
|
|
||||||
use bevy_app::{App, Plugin};
|
|
||||||
use bevy_ecs::resource::Resource;
|
|
||||||
use bevy_math::Vec2;
|
|
||||||
|
|
||||||
pub struct ActionPlugin<A: Action>(PhantomData<A>);
|
|
||||||
|
|
||||||
impl<A: Action> Default for ActionPlugin<A> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self(Default::default())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A: Action> Plugin for ActionPlugin<A> {
|
|
||||||
fn build(&self, app: &mut App) {
|
|
||||||
app.init_resource::<ActionList>()
|
|
||||||
.init_resource::<ActionState<A>>();
|
|
||||||
app.world_mut().resource_mut::<ActionList>().0.push(A::info());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
|
||||||
pub enum ActionType {
|
|
||||||
Bool,
|
|
||||||
Float,
|
|
||||||
Vector,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ActionTy: Send + Sync + Default + Clone + Copy {
|
|
||||||
const TYPE: ActionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActionTy for bool {
|
|
||||||
const TYPE: ActionType = ActionType::Bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActionTy for f32 {
|
|
||||||
const TYPE: ActionType = ActionType::Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActionTy for Vec2 {
|
|
||||||
const TYPE: ActionType = ActionType::Float;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Action: Send + Sync + 'static {
|
|
||||||
type ActionType: ActionTy;
|
|
||||||
|
|
||||||
fn info() -> ActionInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ActionInfo {
|
|
||||||
pub pretty_name: &'static str,
|
|
||||||
pub name: &'static str,
|
|
||||||
pub action_type: ActionType,
|
|
||||||
pub type_id: TypeId,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Resource, Default)]
|
|
||||||
pub struct ActionList(pub Vec<ActionInfo>);
|
|
||||||
|
|
||||||
#[derive(Resource)]
|
|
||||||
pub struct ActionState<A: Action> {
|
|
||||||
previous_state: A::ActionType,
|
|
||||||
current_state: A::ActionType,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A: Action> Default for ActionState<A> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
previous_state: Default::default(),
|
|
||||||
current_state: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A: Action> ActionState<A> {
|
|
||||||
pub fn current_state(&self) -> A::ActionType {
|
|
||||||
self.current_state
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn previous_state(&self) -> A::ActionType {
|
|
||||||
self.previous_state
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set(&mut self, state: A::ActionType) {
|
|
||||||
self.previous_state = std::mem::replace(&mut self.current_state, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<A: Action<ActionType = bool>> ActionState<A> {
|
|
||||||
pub fn pressed(&self) -> bool {
|
|
||||||
self.current_state
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn just_pressed(&self) -> bool {
|
|
||||||
!self.previous_state && self.current_state
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn just_released(&self) -> bool {
|
|
||||||
self.previous_state && !self.current_state
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn press(&mut self) {
|
|
||||||
self.current_state = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
pub mod actions;
|
|
||||||
pub mod camera;
|
pub mod camera;
|
||||||
#[cfg(feature = "gizmos")]
|
#[cfg(feature = "gizmos")]
|
||||||
pub mod hand_debug_gizmos;
|
pub mod hand_debug_gizmos;
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
use bevy::{math::vec3, prelude::*};
|
use bevy::{math::vec3, prelude::*};
|
||||||
use bevy_mod_openxr::{add_xr_plugins, helper_traits::ToQuat, resources::OxrViews};
|
use bevy_mod_openxr::{add_xr_plugins, helper_traits::ToQuat, resources::OxrViews};
|
||||||
use bevy_mod_xr::session::XrTrackingRoot;
|
use bevy_mod_xr::session::XrTrackingRoot;
|
||||||
use bevy_xr_utils::xr_utils_actions::{
|
use bevy_xr_utils::actions::{
|
||||||
ActiveSet, XRUtilsAction, XRUtilsActionSet, XRUtilsActionState, XRUtilsActionSystems,
|
ActionType, ActiveSet, XRUtilsAction, XRUtilsActionSet, XRUtilsActionState, XRUtilsActionSystems, XRUtilsActionsPlugin, XRUtilsBinding
|
||||||
XRUtilsActionsPlugin, XRUtilsBinding,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -73,7 +72,7 @@ fn create_action_entities(mut commands: Commands) {
|
|||||||
XRUtilsAction {
|
XRUtilsAction {
|
||||||
action_name: "flight_input".into(),
|
action_name: "flight_input".into(),
|
||||||
localized_name: "flight_input_localized".into(),
|
localized_name: "flight_input_localized".into(),
|
||||||
action_type: bevy_mod_xr::actions::ActionType::Vector,
|
action_type: ActionType::Vector,
|
||||||
},
|
},
|
||||||
FlightActionMarker, //lets try a marker component
|
FlightActionMarker, //lets try a marker component
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ fn create_openxr_events(
|
|||||||
let (create_action, bindings) = actions_query.get(child).unwrap();
|
let (create_action, bindings) = actions_query.get(child).unwrap();
|
||||||
//lets create dat action
|
//lets create dat action
|
||||||
match create_action.action_type {
|
match create_action.action_type {
|
||||||
bevy_mod_xr::actions::ActionType::Bool => {
|
ActionType::Bool => {
|
||||||
let action: openxr::Action<bool> = action_set
|
let action: openxr::Action<bool> = action_set
|
||||||
.create_action::<bool>(
|
.create_action::<bool>(
|
||||||
&create_action.action_name,
|
&create_action.action_name,
|
||||||
@@ -176,7 +176,7 @@ fn create_openxr_events(
|
|||||||
binding_writer.write(sugestion);
|
binding_writer.write(sugestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bevy_mod_xr::actions::ActionType::Float => {
|
ActionType::Float => {
|
||||||
let action: openxr::Action<f32> = action_set
|
let action: openxr::Action<f32> = action_set
|
||||||
.create_action::<f32>(
|
.create_action::<f32>(
|
||||||
&create_action.action_name,
|
&create_action.action_name,
|
||||||
@@ -215,7 +215,7 @@ fn create_openxr_events(
|
|||||||
binding_writer.write(sugestion);
|
binding_writer.write(sugestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bevy_mod_xr::actions::ActionType::Vector => {
|
ActionType::Vector => {
|
||||||
let action: openxr::Action<Vector2f> = action_set
|
let action: openxr::Action<Vector2f> = action_set
|
||||||
.create_action::<Vector2f>(
|
.create_action::<Vector2f>(
|
||||||
&create_action.action_name,
|
&create_action.action_name,
|
||||||
@@ -345,6 +345,13 @@ fn sync_and_update_action_states_vector(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||||
|
pub enum ActionType {
|
||||||
|
Bool,
|
||||||
|
Float,
|
||||||
|
Vector,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet)]
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet)]
|
||||||
pub enum XRUtilsActionSystems {
|
pub enum XRUtilsActionSystems {
|
||||||
/// Runs in Startup
|
/// Runs in Startup
|
||||||
@@ -375,7 +382,7 @@ pub struct ActiveSet;
|
|||||||
pub struct XRUtilsAction {
|
pub struct XRUtilsAction {
|
||||||
pub action_name: Cow<'static, str>,
|
pub action_name: Cow<'static, str>,
|
||||||
pub localized_name: Cow<'static, str>,
|
pub localized_name: Cow<'static, str>,
|
||||||
pub action_type: bevy_mod_xr::actions::ActionType,
|
pub action_type: ActionType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@@ -3,7 +3,7 @@ pub mod tracking_utils;
|
|||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
pub mod transform_utils;
|
pub mod transform_utils;
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
pub mod xr_utils_actions;
|
pub mod actions;
|
||||||
pub mod generic_tracker;
|
pub mod generic_tracker;
|
||||||
#[cfg(not(target_family = "wasm"))]
|
#[cfg(not(target_family = "wasm"))]
|
||||||
pub mod mndx_xdev_spaces_trackers;
|
pub mod mndx_xdev_spaces_trackers;
|
||||||
|
|||||||
Reference in New Issue
Block a user