From 7a79dcc46c1cec60fedbe5ae77bea746417bd242 Mon Sep 17 00:00:00 2001 From: TehPers Date: Fri, 21 Aug 2020 18:13:50 -0700 Subject: [PATCH] Add serialize/deserialize to some input types (#281) --- Cargo.toml | 2 ++ crates/bevy_input/Cargo.toml | 5 +++++ crates/bevy_input/src/keyboard.rs | 1 + crates/bevy_input/src/mouse.rs | 1 + 4 files changed, 9 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 4070279816..90b2368d1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,8 @@ flac = ["bevy_audio/flac"] wav = ["bevy_audio/wav"] vorbis = ["bevy_audio/vorbis"] +serialize = ["bevy_input/serialize"] + [workspace] members = [ "crates/*", diff --git a/crates/bevy_input/Cargo.toml b/crates/bevy_input/Cargo.toml index b560ff67b3..9d79704b6f 100644 --- a/crates/bevy_input/Cargo.toml +++ b/crates/bevy_input/Cargo.toml @@ -9,7 +9,12 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT" keywords = ["bevy"] +[features] +default = [] +serialize = ["serde"] + [dependencies] bevy_app = { path = "../bevy_app", version = "0.1" } bevy_ecs = { path = "../bevy_ecs", version = "0.1" } bevy_math = { path = "../bevy_math", version = "0.1" } +serde = { version = "1", features = ["derive"], optional = true } diff --git a/crates/bevy_input/src/keyboard.rs b/crates/bevy_input/src/keyboard.rs index bfd3069e34..92ab416752 100644 --- a/crates/bevy_input/src/keyboard.rs +++ b/crates/bevy_input/src/keyboard.rs @@ -56,6 +56,7 @@ pub fn keyboard_input_system( /// The key code of a keyboard input. #[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[repr(u32)] pub enum KeyCode { /// The '1' key over the letters. diff --git a/crates/bevy_input/src/mouse.rs b/crates/bevy_input/src/mouse.rs index 91b265738c..41cd0c2ca5 100644 --- a/crates/bevy_input/src/mouse.rs +++ b/crates/bevy_input/src/mouse.rs @@ -13,6 +13,7 @@ pub struct MouseButtonInput { /// A button on a mouse device #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum MouseButton { Left, Right,