make [copy, paste, menu, start, stop] use new input system
This commit is contained in:
parent
70fd50d3bc
commit
3548679bbb
2 changed files with 27 additions and 15 deletions
22
src/input.rs
22
src/input.rs
|
@ -1,4 +1,4 @@
|
|||
use std::{collections::HashMap, mem::transmute};
|
||||
use std::{collections::BTreeMap, mem::transmute};
|
||||
|
||||
use raylib::{
|
||||
ffi::{KeyboardKey, MouseButton},
|
||||
|
@ -6,13 +6,18 @@ use raylib::{
|
|||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[repr(u8)]
|
||||
pub enum ActionId {
|
||||
StepSim,
|
||||
Undo,
|
||||
Redo,
|
||||
// just like in C, because this way doesn't need more depenedencies
|
||||
Copy,
|
||||
Paste,
|
||||
ToggleMenu,
|
||||
StartSim,
|
||||
StopSim,
|
||||
StepSim,
|
||||
// just like in C, because this way doesn't need more dependencies
|
||||
_ActionIdSize,
|
||||
}
|
||||
|
||||
|
@ -26,9 +31,14 @@ impl Default for Input {
|
|||
trigger: InputTrigger::Key(key),
|
||||
}];
|
||||
};
|
||||
bind_key(ActionId::StepSim, vec![], KEY_SPACE);
|
||||
bind_key(ActionId::Undo, vec![KEY_LEFT_CONTROL], KEY_Z);
|
||||
bind_key(ActionId::Redo, vec![KEY_LEFT_CONTROL], KEY_Y);
|
||||
bind_key(ActionId::Copy, vec![KEY_LEFT_CONTROL], KEY_C);
|
||||
bind_key(ActionId::Paste, vec![KEY_LEFT_CONTROL], KEY_V);
|
||||
bind_key(ActionId::ToggleMenu, vec![], KEY_ESCAPE);
|
||||
bind_key(ActionId::StartSim, vec![], KEY_ENTER);
|
||||
bind_key(ActionId::StopSim, vec![], KEY_ENTER);
|
||||
bind_key(ActionId::StepSim, vec![], KEY_SPACE);
|
||||
|
||||
Self {
|
||||
bindings,
|
||||
|
@ -46,7 +56,7 @@ enum BindingState {
|
|||
Released,
|
||||
}
|
||||
|
||||
type InputMap = HashMap<ActionId, Vec<Binding>>;
|
||||
type InputMap = BTreeMap<ActionId, Vec<Binding>>;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(from = "InputMap", into = "InputMap")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue