-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "bevy_enhanced_input" | |
version = "0.1.0" | ||
authors = ["Hennadii Chernyshchyk <[email protected]>"] | ||
edition = "2021" | ||
description = "Dynamic and contextual input mappings for Bevy " | ||
description = "Dynamic and contextual input mappings for Bevy" | ||
readme = "README.md" | ||
repository = "https://github.com/projectharmonia/bevy_enhanced_input" | ||
keywords = ["bevy", "input"] | ||
|
@@ -12,6 +12,7 @@ license = "MIT OR Apache-2.0" | |
include = ["/src", "/tests", "/LICENSE*"] | ||
|
||
[dependencies] | ||
bevy_enhanced_input_macros = { path = "macros" } | ||
bevy = { version = "0.14", default-features = false, features = ["serialize"] } | ||
bevy_egui = { version = "0.30", default-features = false, features = [ | ||
"immutable_ctx", # Require to get read-only access in our exclusive system. | ||
|
@@ -34,3 +35,6 @@ ui_priority = ['bevy/bevy_ui'] | |
|
||
# Prioritizes 'egui' over actions when processing inputs. | ||
egui_priority = ['dep:bevy_egui'] | ||
|
||
[workspace] | ||
members = ["macros"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "bevy_enhanced_input_macros" | ||
version = "0.1.0" | ||
description = "Bevy Enhanced Input Macros" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
syn = { version = "2.0", features = ["full"] } | ||
quote = "1.0" | ||
proc-macro2 = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use proc_macro::TokenStream; | ||
use proc_macro2::TokenTree; | ||
use quote::quote; | ||
use syn::{parse_macro_input, DeriveInput, Meta}; | ||
|
||
#[proc_macro_derive(InputAction, attributes(action_dim))] | ||
pub fn input_action_derive(item: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(item as DeriveInput); | ||
|
||
const ATTR_NAME: &str = "action_dim"; | ||
let mut dim = None; | ||
for attr in input.attrs { | ||
let Meta::List(list) = attr.meta else { | ||
continue; | ||
}; | ||
|
||
if list | ||
.path | ||
.segments | ||
.iter() | ||
.any(|segment| segment.ident == ATTR_NAME) | ||
{ | ||
assert!(dim.is_none(), "`{ATTR_NAME}` can be defined only once"); | ||
|
||
let mut token_iter = list.tokens.into_iter(); | ||
let token = token_iter | ||
.next() | ||
.unwrap_or_else(|| panic!("`{ATTR_NAME}` should have argument")); | ||
|
||
let TokenTree::Ident(indent) = token else { | ||
panic!("`{token}` is invalid argument for `{ATTR_NAME}`"); | ||
}; | ||
|
||
dim = Some(indent); | ||
|
||
assert!( | ||
token_iter.next().is_none(), | ||
"`{ATTR_NAME}` should have only a single argument" | ||
); | ||
} | ||
} | ||
|
||
let dim = dim.unwrap_or_else(|| panic!("`InputAction` should have `{ATTR_NAME}` attribute")); | ||
let struct_name = input.ident; | ||
TokenStream::from(quote! { | ||
impl InputAction for #struct_name { | ||
const DIM: ActionValueDim = ActionValueDim::#dim; | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters