Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Micro Game Macros
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Micro Game Macros
Commits
3cf1e7d4
Verified
Commit
3cf1e7d4
authored
1 year ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
fmt
parent
071b535a
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/event_system/components.rs
+23
-33
23 additions, 33 deletions
src/event_system/components.rs
src/json_loader/components.rs
+0
-1
0 additions, 1 deletion
src/json_loader/components.rs
src/lib.rs
+4
-4
4 additions, 4 deletions
src/lib.rs
tests/mod.rs
+1
-2
1 addition, 2 deletions
tests/mod.rs
with
28 additions
and
40 deletions
src/event_system/components.rs
+
23
−
33
View file @
3cf1e7d4
...
...
@@ -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
()
}
...
...
This diff is collapsed.
Click to expand it.
src/json_loader/components.rs
+
0
−
1
View file @
3cf1e7d4
...
...
@@ -53,7 +53,6 @@ pub fn define_index_type(
vis
,
index_name
,
asset_name
,
uuid
,
..
}:
&
IdentContext
,
)
->
TokenStream
{
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
4
−
4
View file @
3cf1e7d4
...
...
@@ -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]
...
...
This diff is collapsed.
Click to expand it.
tests/mod.rs
+
1
−
2
View file @
3cf1e7d4
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
,
mes
a
sge
:
String
},
Log
{
source
:
Entity
,
mess
a
ge
:
String
},
}
/// A hatch to allow us to assert that the system has actually run, so we don't miss an
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment