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