Skip to content
Snippets Groups Projects
Verified Commit 3cf1e7d4 authored by Louis's avatar Louis :fire:
Browse files

fmt

parent 071b535a
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,7 @@ use crate::fqpath::*;
use crate::utils::{ident_prefix, ident_suffix, snake_case_ident};
use proc_macro2::{Ident, TokenStream};
use quote::{quote, quote_spanned, ToTokens};
use syn::{
parse_quote, spanned::Spanned, Attribute, Data, DataEnum, DataStruct, DeriveInput, Field, Meta,
Variant, Visibility,
};
use syn::{parse_quote, spanned::Spanned, Data, DataEnum, DeriveInput, Field, Variant};
macro_rules! err_message {
($spannable: expr, $($tok:tt)*) => {
......@@ -45,37 +42,30 @@ pub fn event_system(DeriveInput { data, ident, .. }: DeriveInput) -> TokenStream
fn define_structs(data: &DataEnum) -> TokenStream {
data.variants
.iter()
.map(
|Variant {
ident,
attrs,
fields,
..
}| {
let event_name = ident_suffix(ident, "Event");
let fields: TokenStream = fields
.iter()
.map(|fl @ Field { ident, ty, .. }| {
let f = Field {
ident: ident.clone(),
ty: ty.clone(),
vis: parse_quote!(pub),
..fl.clone()
}
.to_token_stream();
quote!(#f,)
})
.collect();
quote! {
#[derive(#FQClone, #FQDebug, #BevyEvent, #FQSerialize, #FQDeserialize)]
pub struct #event_name {
#fields
.map(|Variant { ident, fields, .. }| {
let event_name = ident_suffix(ident, "Event");
let fields: TokenStream = fields
.iter()
.map(|fl @ Field { ident, ty, .. }| {
let f = Field {
ident: ident.clone(),
ty: ty.clone(),
vis: parse_quote!(pub),
..fl.clone()
}
.to_token_stream();
quote!(#f,)
})
.collect();
quote! {
#[derive(#FQClone, #FQDebug, #BevyEvent, #FQSerialize, #FQDeserialize)]
pub struct #event_name {
#fields
}
},
)
}
})
.collect()
}
......
......@@ -53,7 +53,6 @@ pub fn define_index_type(
vis,
index_name,
asset_name,
uuid,
..
}: &IdentContext,
) -> TokenStream {
......
......@@ -56,7 +56,7 @@
//! // The loader contains a number of functions for loading either individual assets
//! // (two parameters, path and id), or a series of assets (a single parameter, a vector
//! // of tuples each denoting path and id)
//! loader.load_images("path/to/my_image.png", "my_image");
//! loader.load_images("path/to/my_image.png", "my_image");
//!
//! // JsonLoader assets require the use of the Index type to correctly load them, even for
//! // files that only contain one object instance. The identifier (either id or asset_id)
......@@ -294,12 +294,12 @@ pub fn asset_system(_: TokenStream, input: TokenStream) -> TokenStream {
///
/// #[event_system]
/// enum ActionEvent {
/// Wait { source: Entity },
/// Move { source: Entity, to: IVec2 }
/// Wait { source: Entity },
/// Move { source: Entity, to: IVec2 }
/// }
///
/// pub fn emit_wait_event(mut event_writer: EventWriter<WaitEvent>) {
/// event_writer.send(WaitEvent { source: Entity::from_raw(0) });
/// event_writer.send(WaitEvent { source: Entity::from_raw(0) });
/// }
/// ```
#[proc_macro_attribute]
......
use micro_games_macros::event_system;
#[test]
fn event_system_correctly_generates_and_dispatches_events() {
use bevy::prelude::*;
......@@ -10,7 +9,7 @@ fn event_system_correctly_generates_and_dispatches_events() {
#[event_system]
enum MyEvents {
Wait { source: Entity },
Log { source: Entity, mesasge: String },
Log { source: Entity, message: String },
}
/// A hatch to allow us to assert that the system has actually run, so we don't miss an
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment