remove unnedded macro crate and make bevy_xr_utils compile for wasm
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -7,4 +7,3 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy.workspace = true
|
bevy.workspace = true
|
||||||
bevy_xr_macros.path = "macros"
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "bevy_xr_macros"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
proc-macro = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
proc-macro2 = "1.0"
|
|
||||||
quote = "1.0"
|
|
||||||
syn = "2.0"
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
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};
|
|
||||||
|
|
||||||
mod kw {
|
|
||||||
syn::custom_keyword!(action_type);
|
|
||||||
syn::custom_keyword!(name);
|
|
||||||
syn::custom_keyword!(pretty_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum AttributeInput {
|
|
||||||
Kind(Type, Span),
|
|
||||||
Name(Expr, Span),
|
|
||||||
PrettyName(Expr, Span),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for AttributeInput {
|
|
||||||
fn parse(input: ParseStream) -> syn::Result<Self> {
|
|
||||||
if let Ok(field) = input.parse::<kw::action_type>() {
|
|
||||||
input.parse::<Eq>()?;
|
|
||||||
Ok(Self::Kind(input.parse()?, field.span()))
|
|
||||||
} else if let Ok(field) = input.parse::<kw::name>() {
|
|
||||||
input.parse::<Eq>()?;
|
|
||||||
Ok(Self::Name(input.parse()?, field.span()))
|
|
||||||
} else if let Ok(field) = input.parse::<kw::pretty_name>() {
|
|
||||||
input.parse::<Eq>()?;
|
|
||||||
Ok(Self::PrettyName(input.parse()?, field.span()))
|
|
||||||
} else {
|
|
||||||
Err(input.error("expected 'action_type', 'name' or 'pretty_name'"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[proc_macro_derive(Action, attributes(action))]
|
|
||||||
pub fn derive_action(input: TokenStream) -> TokenStream {
|
|
||||||
let input = parse_macro_input!(input as DeriveInput);
|
|
||||||
let item = input.ident;
|
|
||||||
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(),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
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()),
|
|
||||||
};
|
|
||||||
for attr in parsed_attributes {
|
|
||||||
attributes.push(attr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut kind: Option<Type> = None;
|
|
||||||
let mut name: Option<Expr> = None;
|
|
||||||
let mut pretty_name: Option<Expr> = None;
|
|
||||||
for attribute in attributes {
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
pretty_name = Some(expr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if kind.is_none() {
|
|
||||||
panic!("action_type isn't specified")
|
|
||||||
}
|
|
||||||
if name.is_none() {
|
|
||||||
name = Some(parse_quote! {
|
|
||||||
std::stringify!(#item)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if pretty_name.is_none() {
|
|
||||||
pretty_name = name.clone();
|
|
||||||
}
|
|
||||||
let kind = kind.unwrap();
|
|
||||||
let name = name.unwrap();
|
|
||||||
let pretty_name = pretty_name.unwrap();
|
|
||||||
|
|
||||||
let expanded = quote! {
|
|
||||||
impl bevy_xr::actions::Action for #item {
|
|
||||||
type ActionType = #kind;
|
|
||||||
|
|
||||||
fn info() -> bevy_xr::actions::ActionInfo {
|
|
||||||
bevy_xr::actions::ActionInfo {
|
|
||||||
pretty_name: #pretty_name,
|
|
||||||
name: #name,
|
|
||||||
action_type: <Self::ActionType as bevy_xr::actions::ActionTy>::TYPE,
|
|
||||||
type_id: std::any::TypeId::of::<Self>(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TokenStream::from(expanded)
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ use std::{any::TypeId, marker::PhantomData};
|
|||||||
use bevy::app::{App, Plugin};
|
use bevy::app::{App, Plugin};
|
||||||
use bevy::ecs::system::Resource;
|
use bevy::ecs::system::Resource;
|
||||||
use bevy::math::Vec2;
|
use bevy::math::Vec2;
|
||||||
pub use bevy_xr_macros::Action;
|
|
||||||
|
|
||||||
pub struct ActionPlugin<A: Action>(PhantomData<A>);
|
pub struct ActionPlugin<A: Action>(PhantomData<A>);
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,7 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bevy.workspace = true
|
bevy.workspace = true
|
||||||
bevy_mod_xr.path = "../bevy_xr"
|
bevy_mod_xr.path = "../bevy_xr"
|
||||||
openxr = "0.18.0"
|
|
||||||
bevy_mod_openxr.path = "../bevy_openxr"
|
bevy_mod_openxr.path = "../bevy_openxr"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
||||||
|
openxr = "0.18.0"
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
// use bevy::prelude::*;
|
// use bevy::prelude::*;
|
||||||
pub mod hand_gizmos;
|
pub mod hand_gizmos;
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
pub mod xr_utils_actions;
|
pub mod xr_utils_actions;
|
||||||
|
#[cfg(not(target_family = "wasm"))]
|
||||||
pub mod transform_utils;
|
pub mod transform_utils;
|
||||||
|
|||||||
Reference in New Issue
Block a user