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

Improve serde feature #12

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ rust-version = "1.67.0"

[[example]]
name = "simple"
required-features = ["inspect"]

[[example]]
name = "multiple"
required-features = ["inspect"]

[features]
default = ["serialize"]
inspect = ["bevy-inspector-egui"]
Copy link
Owner

Choose a reason for hiding this comment

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

Try not to modify the rest of the code, keep this feature so that there are no conflicts with the other PR's.

serialize = ["serde"]
default = ["serde"]
serde = ["dep:serde"]

[dependencies]
bevy = { version = "0.11" }
Copy link
Owner

Choose a reason for hiding this comment

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

Same here please

bevy-inspector-egui = { version = "0.19", optional = true }
bevy = { version = "0.11", default-features = false, features = [
"bevy_render",
"bevy_ui"
] }
serde = { version = "^1", optional = true }

[build-dependencies]
Copy link
Owner

Choose a reason for hiding this comment

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

Although I think the idea is great, I don't think it should go as a build dependency, because sometimes someone might need it in production or in some other way, so I think it should be kept as a feature base

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If they need the derive feature, they could just add it themselves? Why should we force it on them?

serde = { version = "^1", features = ["derive"], optional = true }

[dev-dependencies]
bevy = "0.11"
bevy-inspector-egui = "0.20"
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ Aviable and compatible versions
- [Multiple Joysticks Desktop](./examples/multiple.rs)

# Features
- inspect: for world inspect with egui inspector
- serialize (default): for serialization support for all types (usable for save and load settings)

- `serde` (default): for serialization support for all types through [`serde`](https://serde.rs) (useful for save and load settings)

```toml
virtual_joystick = {
version = "*",
default-features = false,
features = [ "inspect", "serialize" ]
features = [ "serde" ]
}
```

Expand All @@ -60,7 +60,7 @@ Check out the [examples](./examples) for details.

```sh
# to run example
cargo run --example simple -F=inspect
cargo run --example simple
```

Add to Cargo.toml
Expand Down
12 changes: 3 additions & 9 deletions src/behaviour.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use bevy::prelude::*;

#[cfg(feature = "inspect")]
use bevy_inspector_egui::prelude::*;
#[cfg(feature = "serialize")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[derive(Reflect, Clone, Copy, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "inspect", derive(InspectorOptions))]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "inspect", reflect(InspectorOptions))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum VirtualJoystickAxis {
#[default]
Both,
Expand Down Expand Up @@ -39,9 +35,7 @@ impl VirtualJoystickAxis {
}

#[derive(Reflect, Clone, Copy, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "inspect", derive(InspectorOptions))]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "inspect", reflect(InspectorOptions))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum VirtualJoystickType {
/// Static position
Fixed,
Expand Down
Loading