refactor: trying to do something right!
This commit is contained in:
+9
@@ -400,6 +400,7 @@ name = "bevy_controls"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy_app",
|
"bevy_app",
|
||||||
|
"bevy_controls_macros",
|
||||||
"bevy_derive",
|
"bevy_derive",
|
||||||
"bevy_ecs",
|
"bevy_ecs",
|
||||||
"bevy_input",
|
"bevy_input",
|
||||||
@@ -418,6 +419,14 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bevy_controls_macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bevy_core"
|
name = "bevy_core"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
//!
|
//!
|
||||||
//! It displays
|
//! It displays
|
||||||
//!
|
//!
|
||||||
//! Yeah I know, now it's a bit ugly
|
//! Yeah I know, that's kind of weird that it displays
|
||||||
|
//! But it does.........
|
||||||
|
|
||||||
use bevy::{ecs::schedule::States, prelude::*};
|
use bevy::{ecs::schedule::States, prelude::*};
|
||||||
use bevy_controls::{
|
use bevy_controls::{
|
||||||
|
|||||||
@@ -114,3 +114,41 @@ pub fn game_state_supertraits(_attrs: TokenStream, input: TokenStream) -> TokenS
|
|||||||
|
|
||||||
TokenStream::from(out)
|
TokenStream::from(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[proc_macro_attribute]
|
||||||
|
pub fn action_supertraits(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||||
|
let input = parse_macro_input!(input as ItemTrait);
|
||||||
|
|
||||||
|
let mut bounds = Vec::new();
|
||||||
|
if cfg!(feature = "serialize") {
|
||||||
|
bounds.push(quote! { serde::Serialize });
|
||||||
|
bounds.push(quote! { serde::de::DeserializeOwned });
|
||||||
|
};
|
||||||
|
if cfg!(feature = "reflect") {
|
||||||
|
bounds.push(quote! { bevy_reflect::Reflect });
|
||||||
|
bounds.push(quote! { bevy_reflect::TypePath });
|
||||||
|
bounds.push(quote! { bevy_reflect::FromReflect });
|
||||||
|
};
|
||||||
|
if cfg!(feature = "inspector-egui") {
|
||||||
|
bounds.push(quote! { bevy_inspector_egui::inspector_options::InspectorOptionsType });
|
||||||
|
};
|
||||||
|
|
||||||
|
let ItemTrait {
|
||||||
|
ident,
|
||||||
|
vis,
|
||||||
|
items,
|
||||||
|
supertraits: bounds_old,
|
||||||
|
..
|
||||||
|
} = input;
|
||||||
|
|
||||||
|
let bounds_old = bounds_old.iter().collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let out = quote! {
|
||||||
|
#vis trait #ident: #(#bounds_old)+* + #(#bounds)+* { #(#items)* }
|
||||||
|
};
|
||||||
|
|
||||||
|
// dbg!(&out);
|
||||||
|
// dbg!(out.to_string());
|
||||||
|
|
||||||
|
TokenStream::from(out)
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,34 +56,19 @@ pub trait InspectorEguiImpl: InspectorOptionsType {}
|
|||||||
not(feature = "reflect"),
|
not(feature = "reflect"),
|
||||||
not(feature = "inspector-egui")
|
not(feature = "inspector-egui")
|
||||||
))]
|
))]
|
||||||
pub trait Action: ActionInner {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
#[game_state_supertraits]
|
||||||
feature = "serialize",
|
pub trait Action: 'static
|
||||||
not(feature = "reflect"),
|
+ std::marker::Sync
|
||||||
not(feature = "inspector-egui")
|
+ std::marker::Send
|
||||||
))]
|
+ PartialEq
|
||||||
pub trait Action: ActionInner + SerializeImpl {}
|
+ Eq
|
||||||
|
+ Hash
|
||||||
#[cfg(all(
|
+ IntoEnumIterator
|
||||||
not(feature = "serialize"),
|
+ Clone
|
||||||
feature = "reflect",
|
+ Copy
|
||||||
not(feature = "inspector-egui")
|
+ std::fmt::Debug
|
||||||
))]
|
{}
|
||||||
pub trait Action: ActionInner + ReflectImpl {}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
feature = "serialize",
|
|
||||||
feature = "reflect",
|
|
||||||
not(feature = "inspector-egui")
|
|
||||||
))]
|
|
||||||
pub trait Action: ActionInner + SerializeImpl + ReflectImpl {}
|
|
||||||
|
|
||||||
#[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))]
|
|
||||||
pub trait Action: ActionInner + ReflectImpl + InspectorEguiImpl {}
|
|
||||||
|
|
||||||
#[cfg(all(feature = "serialize", feature = "inspector-egui"))]
|
|
||||||
pub trait Action: ActionInner + SerializeImpl + ReflectImpl + InspectorEguiImpl {}
|
|
||||||
|
|
||||||
// ===== GameState =====
|
// ===== GameState =====
|
||||||
// SAFETY: inspector-egui includes reflect
|
// SAFETY: inspector-egui includes reflect
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ pub fn action(input: TokenStream) -> TokenStream {
|
|||||||
let name = &ast.ident;
|
let name = &ast.ident;
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
impl bevy_controls::contract::Action for #name {}
|
impl bevy_controls::contract::Action for #name {}
|
||||||
impl bevy_controls::contract::ActionInner for #name {}
|
|
||||||
};
|
};
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
@@ -23,7 +22,6 @@ pub fn game_state(input: TokenStream) -> TokenStream {
|
|||||||
let name = &ast.ident;
|
let name = &ast.ident;
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
impl bevy_controls::contract::GameState for #name {}
|
impl bevy_controls::contract::GameState for #name {}
|
||||||
impl bevy_controls::contract::GameStateInner for #name {}
|
|
||||||
};
|
};
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user