serialize keycode
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -396,6 +396,7 @@ dependencies = [
|
|||||||
"bevy_ecs",
|
"bevy_ecs",
|
||||||
"bevy_math",
|
"bevy_math",
|
||||||
"bevy_utils",
|
"bevy_utils",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1902,6 +1903,7 @@ name = "l_system_plants"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bevy",
|
"bevy",
|
||||||
|
"bevy_input",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.5"
|
bevy = "0.5"
|
||||||
|
bevy_input = { version="0.5", features=["serialize"]}
|
||||||
serde = "1.0.133"
|
serde = "1.0.133"
|
||||||
|
|||||||
26
src/main.rs
26
src/main.rs
@@ -1,9 +1,13 @@
|
|||||||
use bevy::input::mouse::MouseMotion;
|
use bevy::input::mouse::MouseMotion;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
|
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
|
||||||
|
use serde::ser::SerializeMap;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use serde::{ Serialize, Deserialize };
|
||||||
|
|
||||||
mod bundles;
|
mod bundles;
|
||||||
use bundles::camera::*;
|
use bundles::camera::*;
|
||||||
@@ -13,7 +17,23 @@ struct ActionBindings
|
|||||||
bindings: HashMap<KeyCode, Action>,
|
bindings: HashMap<KeyCode, Action>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
impl Serialize for ActionBindings
|
||||||
|
{
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer
|
||||||
|
{
|
||||||
|
let mut map = serializer.serialize_map(Some(self.bindings.len()))?;
|
||||||
|
for (k, v) in &self.bindings
|
||||||
|
{
|
||||||
|
map.serialize_entry(&k, &v)?;
|
||||||
|
}
|
||||||
|
map.end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Serialize)]
|
||||||
enum Action
|
enum Action
|
||||||
{
|
{
|
||||||
Forward,
|
Forward,
|
||||||
@@ -21,7 +41,8 @@ enum Action
|
|||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
Up,
|
Up,
|
||||||
Down
|
Down,
|
||||||
|
Accelerate
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Actions {
|
struct Actions {
|
||||||
@@ -38,6 +59,7 @@ fn main() {
|
|||||||
binds.bindings.insert(KeyCode::D, Action::Right);
|
binds.bindings.insert(KeyCode::D, Action::Right);
|
||||||
binds.bindings.insert(KeyCode::Space, Action::Up);
|
binds.bindings.insert(KeyCode::Space, Action::Up);
|
||||||
binds.bindings.insert(KeyCode::C, Action::Down);
|
binds.bindings.insert(KeyCode::C, Action::Down);
|
||||||
|
binds.bindings.insert(KeyCode::LShift, Action::Accelerate);
|
||||||
|
|
||||||
App::build()
|
App::build()
|
||||||
.insert_resource(Msaa {samples: 4})
|
.insert_resource(Msaa {samples: 4})
|
||||||
|
|||||||
Reference in New Issue
Block a user