keybee/lib.rs
1/*!
2Keybee is a semantic input binding library. **It's currently an early proof of
3concept that has been extracted from a larger game project, modified, and not
4well tested.**
5
6Keybee is built around straightforward core primitives:
7- `Session` holds all state for an application
8- `Action` defines anything a player can do, like jump or move
9- `ActionSet` groups together related actions
10- `Bindings` assigns inputs to actions
11
12## Features
13- `winit`: Enable support for winit events
14- `gilrs`: Enable support for gil-rs events
15
16## Getting Started
17```rust,no_run
18use keybee::{Session, ButtonAction, Clamped, Axis2dAction};
19
20let session = keybee::Session::new();
21
22let gameplay = session.create_action_set("gameplay");
23let jump = gameplay.create_action::<ButtonAction>("jump");
24let movement = gameplay.create_action::<Clamped<Axis2dAction>>("movement");
25
26// Keybee will have support for deserializing bindings from files, but for now,
27// this isn't quite done.
28session.use_bindings(todo!("load bindings from somewhere"));
29
30loop {
31 // With the `winit` feature enabled:
32 // session.handle_winit_event::<()>(todo!("pass winit events"));
33
34 // With the `gilrs` feature enabled:
35 // session.handle_gilrs_event(todo!("pass gil-rs events"));
36
37 if jump.get() {
38 println!("Player jumped!");
39 }
40
41 let translate = movement.get();
42 if translate != (0.0, 0.0) {
43 println!("Player movement vector: {:?}", translate);
44 }
45
46 // At the end of every game tick, run `end_update` to reset relative axis
47 // movements and button presses.
48 session.end_update();
49}
50```
51
52## Future Improvements
53- Support for multiple players
54- Other backends: SDL, others
55*/
56
57mod actions;
58mod bindings;
59mod buttons;
60mod session;
61mod state;
62
63pub use crate::actions::{
64 ActionKind, Axis1dAction, Axis2dAction, Axis3dAction, ButtonAction, ButtonHeldAction, Clamped,
65};
66pub use crate::buttons::*;
67pub use crate::session::{Action, ActionSet, Session};