refactor: Fixed a bug in NoteLineCount... not seriously...
This commit is contained in:
@@ -7,14 +7,12 @@
|
||||
|
||||
use bevy::{ecs::schedule::States, prelude::*};
|
||||
use bevy_controls::{
|
||||
contract::{
|
||||
InputsContainer, InputsContainerInner,
|
||||
},
|
||||
contract::InputsContainer,
|
||||
plugin::ControlsPlugin,
|
||||
resource::{Binding, ButtonCombination, Controls, InputType, InputValue, Keyboard, PlayerInputs},
|
||||
};
|
||||
use strum_macros::EnumIter;
|
||||
use bevy_controls_derive::{Action, GameState};
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, EnumIter, Clone, Copy, Debug, Action)]
|
||||
enum MyAction {
|
||||
@@ -37,9 +35,7 @@ struct MyInputsContainer {
|
||||
player_inputs: PlayerInputs<MyAction>,
|
||||
}
|
||||
|
||||
impl InputsContainer<MyAction> for MyInputsContainer {}
|
||||
|
||||
impl InputsContainerInner<MyAction> for MyInputsContainer {
|
||||
impl InputsContainer<MyAction> for MyInputsContainer {
|
||||
fn iter_inputs<'a>(&'a self) -> Box<dyn Iterator<Item = &'a PlayerInputs<MyAction>> + 'a> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
use std::collections::HashMap;
|
||||
//use quote::quote;
|
||||
use quote::quote;
|
||||
use syn::{
|
||||
parse::{Parse, ParseStream, Result},
|
||||
parse_macro_input,
|
||||
punctuated::Punctuated,
|
||||
token::{Bracket, Add},
|
||||
Expr, Ident, ItemTrait, Token, TypeParamBound, LitStr,
|
||||
token::{Add, Bracket},
|
||||
Expr, Ident, ItemTrait, LitStr, Token, TypeParamBound,
|
||||
};
|
||||
use quote::quote;
|
||||
|
||||
// #[cfg_feature_trait_bounds {
|
||||
// "serialize" => Serialize + DeserializeOwned,
|
||||
@@ -67,18 +67,17 @@ pub fn cfg_feature_trait_bounds(attr: TokenStream, input: TokenStream) -> TokenS
|
||||
|
||||
dbg!(std::env::vars().map(|(key, _)| key).collect::<Vec<_>>());
|
||||
|
||||
|
||||
// let code = quote! {
|
||||
// trait #name: #rules {}
|
||||
// };
|
||||
//
|
||||
//
|
||||
// dbg!(code);
|
||||
|
||||
TokenStream::new()
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn game_state_supertraits(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
pub fn supertraits(_attrs: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as ItemTrait);
|
||||
|
||||
let mut bounds = Vec::new();
|
||||
@@ -99,6 +98,7 @@ pub fn game_state_supertraits(_attrs: TokenStream, input: TokenStream) -> TokenS
|
||||
ident,
|
||||
vis,
|
||||
items,
|
||||
generics,
|
||||
supertraits: bounds_old,
|
||||
..
|
||||
} = input;
|
||||
@@ -106,45 +106,7 @@ pub fn game_state_supertraits(_attrs: TokenStream, input: TokenStream) -> TokenS
|
||||
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)
|
||||
}
|
||||
|
||||
#[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)* }
|
||||
#vis trait #ident #generics: #(#bounds_old)+* + #(#bounds)+* { #(#items)* }
|
||||
};
|
||||
|
||||
// dbg!(&out);
|
||||
|
||||
@@ -6,15 +6,23 @@ use bevy_inspector_egui::inspector_options::InspectorOptionsType;
|
||||
use strum::IntoEnumIterator;
|
||||
// #[cfg(all(feature = "reflect", feature = "serialize"))]
|
||||
// use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||
use bevy_controls_macros::{cfg_feature_trait_bounds, supertraits};
|
||||
#[cfg(feature = "reflect")]
|
||||
use bevy_reflect::{FromReflect, Reflect, TypePath};
|
||||
#[cfg(feature = "serialize")]
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use bevy_controls_macros::{cfg_feature_trait_bounds, game_state_supertraits};
|
||||
|
||||
use crate::resource::PlayerInputs;
|
||||
|
||||
pub trait ActionInner:
|
||||
// ===== Action =====
|
||||
// SAFETY: inspector-egui includes reflect
|
||||
#[cfg(all(
|
||||
not(feature = "serialize"),
|
||||
not(feature = "reflect"),
|
||||
not(feature = "inspector-egui")
|
||||
))]
|
||||
#[supertraits]
|
||||
pub trait Action:
|
||||
'static
|
||||
+ std::marker::Sync
|
||||
+ std::marker::Send
|
||||
@@ -28,7 +36,18 @@ pub trait ActionInner:
|
||||
{
|
||||
}
|
||||
|
||||
pub trait InputsContainerInner<A: Action>:
|
||||
// ===== GameState =====
|
||||
// SAFETY: inspector-egui includes reflect
|
||||
#[supertraits]
|
||||
pub trait GameState:
|
||||
'static + std::marker::Sync + std::marker::Send + States + Default + std::fmt::Debug
|
||||
{
|
||||
}
|
||||
|
||||
// ===== InputsContainer =====
|
||||
// SAFETY: inspector-egui includes reflect
|
||||
#[supertraits]
|
||||
pub trait InputsContainer<A: Action>:
|
||||
'static + std::marker::Sync + std::marker::Send + Resource + Default + std::fmt::Debug
|
||||
{
|
||||
/// The method returning an iterator over references to the PlayerInputs.
|
||||
@@ -40,94 +59,6 @@ pub trait InputsContainerInner<A: Action>:
|
||||
fn me_mut<'a>(&'a mut self) -> Option<&'a mut PlayerInputs<A>>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
pub trait SerializeImpl: Serialize + DeserializeOwned {}
|
||||
|
||||
#[cfg(feature = "reflect")]
|
||||
pub trait ReflectImpl: Reflect + TypePath + FromReflect {}
|
||||
|
||||
#[cfg(feature = "inspector-egui")]
|
||||
pub trait InspectorEguiImpl: InspectorOptionsType {}
|
||||
|
||||
// ===== Action =====
|
||||
// SAFETY: inspector-egui includes reflect
|
||||
#[cfg(all(
|
||||
not(feature = "serialize"),
|
||||
not(feature = "reflect"),
|
||||
not(feature = "inspector-egui")
|
||||
))]
|
||||
|
||||
#[game_state_supertraits]
|
||||
pub trait Action: 'static
|
||||
+ std::marker::Sync
|
||||
+ std::marker::Send
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ Hash
|
||||
+ IntoEnumIterator
|
||||
+ Clone
|
||||
+ Copy
|
||||
+ std::fmt::Debug
|
||||
{}
|
||||
|
||||
// ===== GameState =====
|
||||
// SAFETY: inspector-egui includes reflect
|
||||
#[game_state_supertraits]
|
||||
pub trait GameState:
|
||||
'static
|
||||
+ std::marker::Sync
|
||||
+ std::marker::Send
|
||||
+ States
|
||||
+ Default
|
||||
+ std::fmt::Debug
|
||||
{
|
||||
}
|
||||
|
||||
// ===== InputsContainer =====
|
||||
// SAFETY: inspector-egui includes reflect
|
||||
#[cfg(all(
|
||||
not(feature = "serialize"),
|
||||
not(feature = "reflect"),
|
||||
not(feature = "inspector-egui")
|
||||
))]
|
||||
pub trait InputsContainer<A: Action>: InputsContainerInner<A> {}
|
||||
|
||||
#[cfg(all(
|
||||
feature = "serialize",
|
||||
not(feature = "reflect"),
|
||||
not(feature = "inspector-egui")
|
||||
))]
|
||||
pub trait InputsContainer<A: Action>: InputsContainerInner<A> + SerializeImpl {}
|
||||
|
||||
#[cfg(all(
|
||||
not(feature = "serialize"),
|
||||
feature = "reflect",
|
||||
not(feature = "inspector-egui")
|
||||
))]
|
||||
pub trait InputsContainer<A: Action>: InputsContainerInner<A> + ReflectImpl {}
|
||||
|
||||
#[cfg(all(
|
||||
feature = "serialize",
|
||||
feature = "reflect",
|
||||
not(feature = "inspector-egui")
|
||||
))]
|
||||
pub trait InputsContainer<A: Action>:
|
||||
InputsContainerInner<A> + SerializeImpl + ReflectImpl
|
||||
{
|
||||
}
|
||||
|
||||
#[cfg(all(not(feature = "serialize"), feature = "inspector-egui"))]
|
||||
pub trait InputsContainer<A: Action>:
|
||||
InputsContainerInner<A> + ReflectImpl + InspectorEguiImpl
|
||||
{
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "serialize", feature = "inspector-egui"))]
|
||||
pub trait InputsContainer<A: Action>:
|
||||
InputsContainerInner<A> + SerializeImpl + ReflectImpl + InspectorEguiImpl
|
||||
{
|
||||
}
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod test {
|
||||
// use bevy_ecs::{entity::Entity, schedule::States};
|
||||
|
||||
@@ -3,7 +3,11 @@ use bevy_ecs::{
|
||||
schedule::State,
|
||||
system::{Res, ResMut},
|
||||
};
|
||||
use bevy_input::{keyboard::{KeyCode, ScanCode}, mouse::MouseButton, Input};
|
||||
use bevy_input::{
|
||||
keyboard::{KeyCode, ScanCode},
|
||||
mouse::MouseButton,
|
||||
Input,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
contract::{Action, GameState, InputsContainer},
|
||||
|
||||
@@ -2,7 +2,10 @@ use std::error;
|
||||
|
||||
use bevy_derive::{Deref, DerefMut};
|
||||
use bevy_ecs::system::Resource;
|
||||
use bevy_input::{keyboard::{KeyCode, ScanCode}, mouse::MouseButton};
|
||||
use bevy_input::{
|
||||
keyboard::{KeyCode, ScanCode},
|
||||
mouse::MouseButton,
|
||||
};
|
||||
#[cfg(feature = "inspector-egui")]
|
||||
use bevy_inspector_egui::prelude::*;
|
||||
#[cfg(all(feature = "reflect", feature = "serialize"))]
|
||||
|
||||
Reference in New Issue
Block a user