Merge branch 'webxr-refactor' into example_actions
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use quote::quote;
|
||||
use syn::parse::{Parse, ParseStream};
|
||||
use syn::punctuated::Punctuated;
|
||||
use syn::spanned::Spanned;
|
||||
use syn::token::{Comma, Eq};
|
||||
use syn::{parse_macro_input, parse_quote, AttrStyle, DeriveInput, Expr, Type};
|
||||
use syn::parse::{Parse, ParseStream};
|
||||
|
||||
mod kw {
|
||||
syn::custom_keyword!(action_type);
|
||||
@@ -36,7 +36,6 @@ impl Parse for AttributeInput {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[proc_macro_derive(Action, attributes(action))]
|
||||
pub fn derive_action(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
@@ -44,9 +43,17 @@ pub fn derive_action(input: TokenStream) -> TokenStream {
|
||||
let mut attributes = vec![];
|
||||
for attribute in input.attrs {
|
||||
if let AttrStyle::Inner(token) = attribute.style {
|
||||
return TokenStream::from(syn::Error::new(token.span, "This derive macro does not accept inner attributes").to_compile_error());
|
||||
return TokenStream::from(
|
||||
syn::Error::new(
|
||||
token.span,
|
||||
"This derive macro does not accept inner attributes",
|
||||
)
|
||||
.to_compile_error(),
|
||||
);
|
||||
};
|
||||
let parsed_attributes = match attribute.parse_args_with(Punctuated::<AttributeInput, Comma>::parse_terminated) {
|
||||
let parsed_attributes = match attribute
|
||||
.parse_args_with(Punctuated::<AttributeInput, Comma>::parse_terminated)
|
||||
{
|
||||
Ok(inner) => inner,
|
||||
Err(e) => return TokenStream::from(e.to_compile_error()),
|
||||
};
|
||||
@@ -61,27 +68,39 @@ pub fn derive_action(input: TokenStream) -> TokenStream {
|
||||
match attribute {
|
||||
AttributeInput::Kind(ty, span) => {
|
||||
if kind.is_some() {
|
||||
return syn::Error::new(span, "attribute 'action_type' is defined more than once").to_compile_error().into();
|
||||
return syn::Error::new(
|
||||
span,
|
||||
"attribute 'action_type' is defined more than once",
|
||||
)
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
|
||||
kind = Some(ty);
|
||||
},
|
||||
}
|
||||
AttributeInput::Name(expr, span) => {
|
||||
if name.is_some() {
|
||||
return syn::Error::new(span, "attribute 'name' is defined more than once").to_compile_error().into();
|
||||
return syn::Error::new(span, "attribute 'name' is defined more than once")
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
|
||||
name = Some(expr);
|
||||
},
|
||||
}
|
||||
AttributeInput::PrettyName(expr, span) => {
|
||||
if pretty_name.is_some() {
|
||||
return syn::Error::new(span, "attribute 'pretty_name' is defined more than once").to_compile_error().into();
|
||||
return syn::Error::new(
|
||||
span,
|
||||
"attribute 'pretty_name' is defined more than once",
|
||||
)
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
|
||||
pretty_name = Some(expr);
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if kind.is_none() {
|
||||
panic!("action_type isn't specified")
|
||||
@@ -114,4 +133,4 @@ pub fn derive_action(input: TokenStream) -> TokenStream {
|
||||
};
|
||||
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
use bevy::{ecs::component::Component, math::bool, prelude::{Deref, DerefMut}};
|
||||
use bevy::{
|
||||
ecs::component::Component,
|
||||
math::bool,
|
||||
prelude::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Component, Debug)]
|
||||
pub struct LeftHand;
|
||||
|
||||
#[derive(Clone, Copy, Component, Debug)]
|
||||
pub struct RightHand;
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Component, Debug,DerefMut,Deref)]
|
||||
#[derive(Clone, Copy, Component, Debug, DerefMut, Deref)]
|
||||
pub struct HandBoneRadius(pub f32);
|
||||
|
||||
#[repr(u8)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod actions;
|
||||
pub mod camera;
|
||||
pub mod hands;
|
||||
pub mod session;
|
||||
pub mod types;
|
||||
pub mod hands;
|
||||
|
||||
@@ -89,7 +89,9 @@ pub fn handle_session(
|
||||
}
|
||||
|
||||
/// A [`Condition`](bevy::ecs::schedule::Condition) that allows the system to run when the xr status changed to a specific [`XrStatus`].
|
||||
pub fn status_changed_to(status: XrStatus) -> impl FnMut(EventReader<XrStatusChanged>) -> bool + Clone {
|
||||
pub fn status_changed_to(
|
||||
status: XrStatus,
|
||||
) -> impl FnMut(EventReader<XrStatusChanged>) -> bool + Clone {
|
||||
move |mut reader: EventReader<XrStatusChanged>| {
|
||||
reader.read().any(|new_status| new_status.0 == status)
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ use bevy::math::{Quat, Vec3};
|
||||
|
||||
pub struct Pose {
|
||||
pub position: Vec3,
|
||||
pub orientation: Quat
|
||||
}
|
||||
pub orientation: Quat,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user