Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dart messages to be easily handled as bevy events #349

Merged
merged 10 commits into from
Jun 30, 2024
5 changes: 5 additions & 0 deletions rust_crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ protoc-prebuilt = "0.3.0"
home = "0.5.9"
which = "6.0.0"
allo-isolate = "0.1.24"
bevy_ecs = { version = "0.13", optional = true }

[target.'cfg(target_family = "wasm")'.dependencies]
js-sys = "0.3.69"
wasm-bindgen = "0.2.92"
bevy_ecs = { version = "0.13", optional = true }

[features]
bevy = ["dep:bevy_ecs"]
5 changes: 5 additions & 0 deletions rust_crate/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ use super::interface_os::*;
#[cfg(target_family = "wasm")]
use super::interface_web::*;

#[cfg(feature = "bevy")]
use bevy_ecs::event::Event;

/// This is a mutable cell type that can be shared across threads.
pub type SharedCell<T> = OnceLock<Mutex<RefCell<Option<T>>>>;

/// This contains a message from Dart.
/// Optionally, a custom binary called `binary` can also be included.
/// This type is generic, and the message
/// can be of any type declared in Protobuf.
/// If the bevy feature is used, every message can be received as an event in bevy.
Copy link
Member

@temeddix temeddix Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small request here, do you mind change the sentence to:

If the bevy feature is used, every message can be received as an event in Bevy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did it. I hope everything fits.

#[cfg_attr(feature = "bevy", derive(Event))]
Deep-co-de marked this conversation as resolved.
Show resolved Hide resolved
pub struct DartSignal<T> {
pub message: T,
pub binary: Vec<u8>,
Expand Down