serialize keycode
This commit is contained in:
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