Skip to content

Commit

Permalink
Update for bevy 0.13 and bevy_egui 0.25 (#470)
Browse files Browse the repository at this point in the history
* Update for Bevy 0.13

* RELEASES.md

* Fix new test added by #473

* Update for bevy_egui 0.25

* fmt
  • Loading branch information
Shute052 authored Feb 20, 2024
1 parent e87af97 commit c9181b6
Show file tree
Hide file tree
Showing 36 changed files with 265 additions and 1,434 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ egui = ['dep:bevy_egui']

[dependencies]
leafwing_input_manager_macros = { path = "macros", version = "0.12" }
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.13", default-features = false, features = [
"serialize",
"bevy_gilrs",
] }
bevy_egui = { version = "0.24", optional = true }
bevy_egui = { version = "0.25", optional = true }

derive_more = { version = "0.99", default-features = false, features = [
"display",
Expand All @@ -52,7 +52,7 @@ itertools = "0.12"
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.13", default-features = false, features = [
"bevy_asset",
"bevy_sprite",
"bevy_text",
Expand All @@ -61,7 +61,7 @@ bevy = { version = "0.12", default-features = false, features = [
"bevy_core_pipeline",
"x11",
] }
bevy_egui = { version = "0.24" }
bevy_egui = "0.25"
serde_test = "1.0"
criterion = "0.5"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ and a single input can result in multiple actions being triggered, which can be
- Ergonomic insertion API that seamlessly blends multiple input types for you
- Can't decide between `input_map.insert(Action::Jump, KeyCode::Space)` and `input_map.insert(Action::Jump, GamepadButtonType::South)`? Have both!
- Full support for arbitrary button combinations: chord your heart out.
- `input_map.insert_chord(Action::Console, [KeyCode::ControlLeft, KeyCode::Shift, KeyCode::C])`
- `input_map.insert_chord(Action::Console, [KeyCode::ControlLeft, KeyCode::Shift, KeyCode::KeyC])`
- Sophisticated input disambiguation with the `ClashStrategy` enum: stop triggering individual buttons when you meant to press a chord!
- Create an arbitrary number of strongly typed disjoint action sets by adding multiple copies of this plugin: decouple your camera and player state
- Local multiplayer support: freely bind keys to distinct entities, rather than worrying about singular global state
- Networked multiplayer support: serializable structs, and a space-conscious `ActionDiff` representation to send on the wire
- Powerful and easy-to-use input mocking API for integration testing your Bevy applications
- `app.send_input(KeyCode::B)` or `world.send_input(UserInput::chord([KeyCode::B, KeyCode::E, KeyCode::V, KeyCode::Y])`
- `app.send_input(KeyCode::KeyB)` or `world.send_input(UserInput::chord([KeyCode::KeyB, KeyCode::KeyE, KeyCode::KeyV, KeyCode::KeyY])`
- Control which state this plugin is active in: stop wandering around while in a menu!
- Leafwing Studio's trademark `#![forbid(missing_docs)]`

Expand Down
13 changes: 13 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
### Breaking Changes

- `Modifier::Win` has been renamed to `Modifier::Super`, consistent with `KeyCode::SuperLeft` and `KeyCode::SuperRight`.
- both `KeyCode`-based logical keybindings and `ScanCode`-based physical keybindings are no longer supported; please migrate to:
- `KeyCode`s are now representing physical keybindings.
- `InputKind::Keyboard` has been removed.
- `InputKind::KeyLocation` has been removed; please use `InputKind::PhysicalKey` instead.
- All `ScanCode`s and `QwertyScanCode`s have been removed; please use `KeyCode` instead:
- all letter keys now follow the format `KeyCode::Key<Letter>`, e.g., `ScanCode::K` is now `KeyCode::KeyK`.
- all number keys over letters now follow the format `KeyCode::Digit<Number>`, e.g., `ScanCode::Key1` is now `KeyCode::Digit1`.
- all arrow keys now follow the format `KeyCode::Arrow<Direction>`, e.g., `ScanCode::Up` is now `KeyCode::ArrowUp`.

### Usability

- `bevy` dependency has been bumped from 0.12 to 0.13.
- `bevy_egui` dependency has been bumped from 0.24 to 0.25.

## Version 0.12.1

Expand Down
44 changes: 22 additions & 22 deletions benches/input_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ enum TestAction {

fn construct_input_map_from_iter() -> InputMap<TestAction> {
black_box(InputMap::new([
(TestAction::A, KeyCode::A),
(TestAction::B, KeyCode::B),
(TestAction::C, KeyCode::C),
(TestAction::D, KeyCode::D),
(TestAction::E, KeyCode::E),
(TestAction::F, KeyCode::F),
(TestAction::G, KeyCode::G),
(TestAction::H, KeyCode::H),
(TestAction::I, KeyCode::I),
(TestAction::J, KeyCode::J),
(TestAction::A, KeyCode::KeyA),
(TestAction::B, KeyCode::KeyB),
(TestAction::C, KeyCode::KeyC),
(TestAction::D, KeyCode::KeyD),
(TestAction::E, KeyCode::KeyE),
(TestAction::F, KeyCode::KeyF),
(TestAction::G, KeyCode::KeyG),
(TestAction::H, KeyCode::KeyH),
(TestAction::I, KeyCode::KeyI),
(TestAction::J, KeyCode::KeyJ),
]))
}

fn construct_input_map_from_chained_calls() -> InputMap<TestAction> {
black_box(
InputMap::default()
.insert(TestAction::A, KeyCode::A)
.insert(TestAction::B, KeyCode::B)
.insert(TestAction::C, KeyCode::C)
.insert(TestAction::D, KeyCode::D)
.insert(TestAction::E, KeyCode::E)
.insert(TestAction::F, KeyCode::F)
.insert(TestAction::G, KeyCode::G)
.insert(TestAction::H, KeyCode::H)
.insert(TestAction::I, KeyCode::I)
.insert(TestAction::J, KeyCode::J)
.insert(TestAction::A, KeyCode::KeyA)
.insert(TestAction::B, KeyCode::KeyB)
.insert(TestAction::C, KeyCode::KeyC)
.insert(TestAction::D, KeyCode::KeyD)
.insert(TestAction::E, KeyCode::KeyE)
.insert(TestAction::F, KeyCode::KeyF)
.insert(TestAction::G, KeyCode::KeyG)
.insert(TestAction::H, KeyCode::KeyH)
.insert(TestAction::I, KeyCode::KeyI)
.insert(TestAction::J, KeyCode::KeyJ)
.build(),
)
}
Expand All @@ -78,8 +78,8 @@ pub fn criterion_benchmark(c: &mut Criterion) {
// Constructing our test app / input stream outside of the timed benchmark
let mut app = App::new();
app.add_plugins(InputPlugin);
app.send_input(KeyCode::A);
app.send_input(KeyCode::B);
app.send_input(KeyCode::KeyA);
app.send_input(KeyCode::KeyB);
app.update();

let input_streams = InputStreams::from_world(&app.world, None);
Expand Down
2 changes: 1 addition & 1 deletion examples/action_state_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl PlayerAction {
fn mkb_input_map() -> InputMap<PlayerAction> {
use KeyCode::*;
InputMap::new([
(Self::Jump, UserInput::Single(InputKind::Keyboard(Space))),
(Self::Jump, UserInput::Single(InputKind::PhysicalKey(Space))),
(Self::Move, UserInput::VirtualDPad(VirtualDPad::wasd())),
])
}
Expand Down
8 changes: 4 additions & 4 deletions examples/arpg_indirection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ fn spawn_player(mut commands: Commands) {
commands.spawn(PlayerBundle {
player: Player,
slot_input_map: InputMap::new([
(Slot::Ability1, Q),
(Slot::Ability2, W),
(Slot::Ability3, E),
(Slot::Ability4, R),
(Slot::Ability1, KeyQ),
(Slot::Ability2, KeyW),
(Slot::Ability3, KeyE),
(Slot::Ability4, KeyR),
])
.insert(Slot::Primary, MouseButton::Left)
.insert(Slot::Secondary, MouseButton::Right)
Expand Down
10 changes: 5 additions & 5 deletions examples/clash_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ fn spawn_input_map(mut commands: Commands) {
let mut input_map = InputMap::default();

// Setting up input mappings in the obvious way
input_map.insert_multiple([(One, Key1), (Two, Key2), (Three, Key3)]);
input_map.insert_multiple([(One, Digit1), (Two, Digit2), (Three, Digit3)]);

input_map.insert_chord(OneAndTwo, [Key1, Key2]);
input_map.insert_chord(OneAndThree, [Key1, Key3]);
input_map.insert_chord(TwoAndThree, [Key2, Key3]);
input_map.insert_chord(OneAndTwo, [Digit1, Digit2]);
input_map.insert_chord(OneAndThree, [Digit1, Digit3]);
input_map.insert_chord(TwoAndThree, [Digit2, Digit3]);

input_map.insert_chord(OneAndTwoAndThree, [Key1, Key2, Key3]);
input_map.insert_chord(OneAndTwoAndThree, [Digit1, Digit2, Digit3]);

commands.spawn(InputManagerBundle {
input_map,
Expand Down
4 changes: 2 additions & 2 deletions examples/consuming_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn main() {
.init_resource::<ActionState<MenuAction>>()
.insert_resource(InputMap::<MenuAction>::new([
(MenuAction::CloseWindow, KeyCode::Escape),
(MenuAction::OpenMainMenu, KeyCode::M),
(MenuAction::OpenSubMenu, KeyCode::S),
(MenuAction::OpenMainMenu, KeyCode::KeyM),
(MenuAction::OpenSubMenu, KeyCode::KeyS),
]))
.init_resource::<MainMenu>()
.init_resource::<SubMenu>()
Expand Down
2 changes: 1 addition & 1 deletion examples/default_controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl PlayerAction {
// Match against the provided action to get the correct default keyboard-mouse input
match self {
Self::Run => UserInput::VirtualDPad(VirtualDPad::wasd()),
Self::Jump => UserInput::Single(InputKind::Keyboard(KeyCode::Space)),
Self::Jump => UserInput::Single(InputKind::PhysicalKey(KeyCode::Space)),
Self::UseItem => UserInput::Single(InputKind::Mouse(MouseButton::Left)),
}
}
Expand Down
12 changes: 6 additions & 6 deletions examples/multiplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ impl PlayerBundle {
fn input_map(player: Player) -> InputMap<Action> {
let mut input_map = match player {
Player::One => InputMap::new([
(Action::Left, KeyCode::A),
(Action::Right, KeyCode::D),
(Action::Jump, KeyCode::W),
(Action::Left, KeyCode::KeyA),
(Action::Right, KeyCode::KeyD),
(Action::Jump, KeyCode::KeyW),
])
// This is a quick and hacky solution:
// you should coordinate with the `Gamepads` resource to determine the correct gamepad for each player
Expand All @@ -44,9 +44,9 @@ impl PlayerBundle {
.set_gamepad(Gamepad { id: 0 })
.build(),
Player::Two => InputMap::new([
(Action::Left, KeyCode::Left),
(Action::Right, KeyCode::Right),
(Action::Jump, KeyCode::Up),
(Action::Left, KeyCode::ArrowLeft),
(Action::Right, KeyCode::ArrowRight),
(Action::Jump, KeyCode::ArrowUp),
])
.set_gamepad(Gamepad { id: 1 })
.build(),
Expand Down
73 changes: 0 additions & 73 deletions examples/physical_key_bindings.rs

This file was deleted.

8 changes: 4 additions & 4 deletions examples/press_duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ impl PlayerBundle {
use Action::*;

InputMap::new([
(Left, KeyCode::A),
(Left, KeyCode::Left),
(Right, KeyCode::D),
(Right, KeyCode::Right),
(Left, KeyCode::KeyA),
(Left, KeyCode::ArrowLeft),
(Right, KeyCode::KeyD),
(Right, KeyCode::ArrowRight),
])
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/register_gamepads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn join(
mut commands: Commands,
mut joined_players: ResMut<JoinedPlayers>,
gamepads: Res<Gamepads>,
button_inputs: Res<Input<GamepadButton>>,
button_inputs: Res<ButtonInput<GamepadButton>>,
) {
for gamepad in gamepads.iter() {
// Join the game when both bumpers (L+R) on the controller are pressed
Expand Down
2 changes: 1 addition & 1 deletion examples/send_actions_over_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn spawn_player(mut commands: Commands) {

commands
.spawn(InputManagerBundle {
input_map: InputMap::new([(MoveLeft, W), (MoveRight, D), (Jump, Space)])
input_map: InputMap::new([(MoveLeft, KeyW), (MoveRight, KeyD), (Jump, Space)])
.insert(Shoot, MouseButton::Left)
.build(),
..default()
Expand Down
16 changes: 8 additions & 8 deletions examples/single_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,34 @@ impl PlayerBundle {
let mut input_map = InputMap::default();

// Movement
input_map.insert(Up, KeyCode::Up);
input_map.insert(Up, KeyCode::ArrowUp);
input_map.insert(Up, GamepadButtonType::DPadUp);

input_map.insert(Down, KeyCode::Down);
input_map.insert(Down, KeyCode::ArrowDown);
input_map.insert(Down, GamepadButtonType::DPadDown);

input_map.insert(Left, KeyCode::Left);
input_map.insert(Left, KeyCode::ArrowLeft);
input_map.insert(Left, GamepadButtonType::DPadLeft);

input_map.insert(Right, KeyCode::Right);
input_map.insert(Right, KeyCode::ArrowRight);
input_map.insert(Right, GamepadButtonType::DPadRight);

// Abilities
input_map.insert(Ability1, KeyCode::Q);
input_map.insert(Ability1, KeyCode::KeyQ);
input_map.insert(Ability1, GamepadButtonType::West);
input_map.insert(Ability1, MouseButton::Left);

input_map.insert(Ability2, KeyCode::W);
input_map.insert(Ability2, KeyCode::KeyW);
input_map.insert(Ability2, GamepadButtonType::North);
input_map.insert(Ability2, MouseButton::Right);

input_map.insert(Ability3, KeyCode::E);
input_map.insert(Ability3, KeyCode::KeyE);
input_map.insert(Ability3, GamepadButtonType::East);

input_map.insert(Ability4, KeyCode::Space);
input_map.insert(Ability4, GamepadButtonType::South);

input_map.insert(Ultimate, KeyCode::R);
input_map.insert(Ultimate, KeyCode::KeyR);
input_map.insert(Ultimate, GamepadButtonType::LeftTrigger2);

input_map
Expand Down
8 changes: 5 additions & 3 deletions examples/twin_stick_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ pub struct InputModeManagerPlugin;

impl Plugin for InputModeManagerPlugin {
fn build(&self, app: &mut App) {
// Add a state to record the current active input
app.add_state::<ActiveInput>()
// Init a state to record the current active input
app.init_state::<ActiveInput>()
// System to switch to gamepad as active input
.add_systems(
Update,
Expand Down Expand Up @@ -156,7 +156,9 @@ fn player_mouse_look(
if let Some(p) = window
.cursor_position()
.and_then(|cursor| camera.viewport_to_world(camera_transform, cursor))
.and_then(|ray| Some(ray).zip(ray.intersect_plane(player_transform.translation, Vec3::Y)))
.and_then(|ray| {
Some(ray).zip(ray.intersect_plane(player_transform.translation, Plane3d::new(Vec3::Y)))
})
.map(|(ray, p)| ray.get_point(p))
{
let diff = (p - player_transform.translation).xz();
Expand Down
Loading

0 comments on commit c9181b6

Please sign in to comment.