Skip to content

Commit

Permalink
Update Bevy to 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-hansen committed Jul 10, 2023
1 parent 76076be commit 7fb55b0
Show file tree
Hide file tree
Showing 42 changed files with 357 additions and 315 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ egui = ['dep:bevy_egui']

[dependencies]
leafwing_input_manager_macros = { path = "macros", version = "0.9" }
bevy = { version = "0.10", default-features = false, features = [
bevy = { version = "0.11", default-features = false, features = [
"serialize",
"bevy_gilrs",
] }
Expand All @@ -43,7 +43,7 @@ once_cell = "1.17.1"

[dev-dependencies]
bevy_egui = { version = "0.20" }
bevy = { version = "0.10", default-features = false, features = [
bevy = { version = "0.11", default-features = false, features = [
"bevy_asset",
"bevy_sprite",
"bevy_text",
Expand All @@ -66,3 +66,6 @@ harness = false
[lib]
name = "leafwing_input_manager"
path = "src/lib.rs"

[patch.crates-io]
bevy_egui = {git="https://github.com/Vrixyz/bevy_egui.git", rev="852b2db"}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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::LControl, KeyCode::Shift, KeyCode::C])`
- `input_map.insert_chord(Action::Console, [KeyCode::ControlLeft, KeyCode::Shift, KeyCode::C])`
- 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
Expand Down Expand Up @@ -62,11 +62,11 @@ fn main() {
.add_plugins(DefaultPlugins)
// This plugin maps inputs to an input-type agnostic action-state
// We need to provide it with an enum which stores the possible actions a player could take
.add_plugin(InputManagerPlugin::<Action>::default())
.add_plugins(InputManagerPlugin::<Action>::default())
// The InputMap and ActionState components will be added to any entity with the Player component
.add_startup_system(spawn_player)
.add_systems(Startup,spawn_player)
// Read the ActionState in your systems using queries!
.add_system(jump)
.add_systems(Update, jump)
.run();
}
Expand Down
5 changes: 3 additions & 2 deletions benches/action_state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::prelude::Reflect;
use criterion::{criterion_group, criterion_main, Criterion};
use leafwing_input_manager::{
action_state::{ActionData, Timing},
Expand All @@ -6,7 +7,7 @@ use leafwing_input_manager::{
Actionlike,
};

#[derive(Actionlike, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Actionlike, Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
enum TestAction {
A,
B,
Expand Down Expand Up @@ -44,7 +45,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let action_state = ActionState::<TestAction>::default();

c.bench_function("action_state_default", |b| {
b.iter(|| ActionState::<TestAction>::default())
b.iter(ActionState::<TestAction>::default)
});
c.bench_function("pressed", |b| b.iter(|| pressed(&action_state)));
c.bench_function("just_pressed", |b| b.iter(|| just_pressed(&action_state)));
Expand Down
9 changes: 5 additions & 4 deletions benches/input_map.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::prelude::Reflect;
use bevy::{
input::InputPlugin,
prelude::{App, KeyCode},
Expand All @@ -10,7 +11,7 @@ use leafwing_input_manager::{
Actionlike,
};

#[derive(Actionlike, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Actionlike, Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
enum TestAction {
A,
B,
Expand Down Expand Up @@ -63,16 +64,16 @@ fn which_pressed(input_streams: &InputStreams, clash_strategy: ClashStrategy) ->

pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("construct_input_map_from_iter", |b| {
b.iter(|| construct_input_map_from_iter())
b.iter(construct_input_map_from_iter)
});
c.bench_function("construct_input_map_from_chained_calls", |b| {
b.iter(|| construct_input_map_from_chained_calls())
b.iter(construct_input_map_from_chained_calls)
});
let mut which_pressed_group = c.benchmark_group("which_pressed");

// Constructing our test app / input stream outside of the timed benchmark
let mut app = App::new();
app.add_plugin(InputPlugin);
app.add_plugins(InputPlugin);
app.send_input(KeyCode::A);
app.send_input(KeyCode::B);
app.update();
Expand Down
19 changes: 9 additions & 10 deletions examples/arpg_indirection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
// These are the generic "slots" that make up the player's action bar
.add_plugin(InputManagerPlugin::<Slot>::default())
.add_plugins(InputManagerPlugin::<Slot>::default())
// These are the actual abilities used by our characters
.add_plugin(InputManagerPlugin::<Ability>::default())
.add_startup_system(spawn_player)
.add_plugins(InputManagerPlugin::<Ability>::default())
.add_systems(Startup, spawn_player)
// This system coordinates the state of our two actions
.add_system(
copy_action_state
.in_base_set(CoreSet::PreUpdate)
.after(InputManagerSystem::ManualControl),
.add_systems(
PreUpdate,
copy_action_state.after(InputManagerSystem::ManualControl),
)
// Try it out, using QWER / left click / right click!
.add_system(report_abilities_used)
.add_systems(Update, report_abilities_used)
.run();
}

#[derive(Actionlike, PartialEq, Eq, Clone, Debug, Hash, Copy)]
#[derive(Actionlike, PartialEq, Eq, Clone, Debug, Hash, Copy, Reflect)]
enum Slot {
Primary,
Secondary,
Expand All @@ -40,7 +39,7 @@ enum Slot {
}

// The list of possible abilities is typically longer than the list of slots
#[derive(Actionlike, PartialEq, Eq, Clone, Debug, Copy)]
#[derive(Actionlike, PartialEq, Eq, Clone, Debug, Copy, Reflect)]
enum Ability {
Slash,
Shoot,
Expand Down
8 changes: 4 additions & 4 deletions examples/axis_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ fn main() {
.add_plugins(DefaultPlugins)
// This plugin maps inputs to an input-type agnostic action-state
// We need to provide it with an enum which stores the possible actions a player could take
.add_plugin(InputManagerPlugin::<Action>::default())
.add_plugins(InputManagerPlugin::<Action>::default())
// Spawn an entity with Player, InputMap, and ActionState components
.add_startup_system(spawn_player)
.add_systems(Startup, spawn_player)
// Read the ActionState in your systems using queries!
.add_system(move_player)
.add_systems(Update, move_player)
.run();
}

#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug)]
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)]
enum Action {
Move,
Throttle,
Expand Down
25 changes: 15 additions & 10 deletions examples/binding_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ fn main() {
App::new()
.insert_resource(ControlSettings::default())
.add_plugins(DefaultPlugins)
.add_plugin(EguiPlugin)
.add_plugin(InputManagerPlugin::<ControlAction>::default())
.add_plugin(InputManagerPlugin::<UiAction>::default())
.add_startup_system(spawn_player_system)
.add_system(controls_window_system)
.add_system(buttons_system)
.add_system(binding_window_system)
.add_plugins(EguiPlugin)
.add_plugins(InputManagerPlugin::<ControlAction>::default())
.add_plugins(InputManagerPlugin::<UiAction>::default())
.add_systems(Startup, spawn_player_system)
.add_systems(
Update,
(
controls_window_system,
buttons_system,
binding_window_system,
),
)
.run();
}

Expand Down Expand Up @@ -183,7 +188,7 @@ fn binding_window_system(
});
}

#[derive(Actionlike, Debug, PartialEq, Clone, Copy, Display)]
#[derive(Actionlike, Debug, PartialEq, Clone, Copy, Display, Reflect)]
pub(crate) enum ControlAction {
// Movement
Forward,
Expand All @@ -199,7 +204,7 @@ pub(crate) enum ControlAction {
Ultimate,
}

#[derive(Actionlike, Debug, PartialEq, Clone, Copy)]
#[derive(Actionlike, Debug, PartialEq, Clone, Copy, Reflect)]
pub(crate) enum UiAction {
Back,
}
Expand All @@ -221,7 +226,7 @@ impl Default for ControlSettings {
.insert(MouseButton::Left, ControlAction::BaseAttack)
.insert(KeyCode::Q, ControlAction::Ability1)
.insert(KeyCode::E, ControlAction::Ability2)
.insert(KeyCode::LShift, ControlAction::Ability3)
.insert(KeyCode::ShiftLeft, ControlAction::Ability3)
.insert(KeyCode::R, ControlAction::Ultimate);
Self { input }
}
Expand Down
8 changes: 4 additions & 4 deletions examples/clash_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use leafwing_input_manager::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(InputManagerPlugin::<TestAction>::default())
.add_startup_system(spawn_input_map)
.add_system(report_pressed_actions)
.add_plugins(InputManagerPlugin::<TestAction>::default())
.add_systems(Startup, spawn_input_map)
.add_systems(Update, report_pressed_actions)
// Change the value of this resource to change how clashes should be handled in your game
.insert_resource(ClashStrategy::PrioritizeLongest)
.run()
}

#[derive(Actionlike, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Actionlike, Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
enum TestAction {
One,
Two,
Expand Down
14 changes: 7 additions & 7 deletions examples/consuming_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use menu_mocking::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(InputManagerPlugin::<MenuAction>::default())
.add_plugins(InputManagerPlugin::<MenuAction>::default())
.init_resource::<ActionState<MenuAction>>()
.insert_resource(InputMap::<MenuAction>::new([
(KeyCode::Escape, MenuAction::CloseWindow),
Expand All @@ -18,18 +18,18 @@ fn main() {
]))
.init_resource::<MainMenu>()
.init_resource::<SubMenu>()
.add_system(report_menus)
.add_system(open_main_menu)
.add_system(open_sub_menu)
.add_systems(Update, report_menus)
.add_systems(Update, open_main_menu)
.add_systems(Update, open_sub_menu)
// We want to ensure that if both the main menu and submenu are open
// only the submenu is closed if the user hits (or holds) Escape
.add_system(close_menu::<SubMenu>.before(close_menu::<MainMenu>))
.add_systems(Update, close_menu::<SubMenu>.before(close_menu::<MainMenu>))
// We can do this by ordering our systems and using `ActionState::consume`
.add_system(close_menu::<MainMenu>)
.add_systems(Update, close_menu::<MainMenu>)
.run()
}

#[derive(Actionlike, Debug, Clone)]
#[derive(Actionlike, Debug, Clone, Reflect)]
enum MenuAction {
CloseWindow,
OpenMainMenu,
Expand Down
8 changes: 4 additions & 4 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ fn main() {
.add_plugins(DefaultPlugins)
// This plugin maps inputs to an input-type agnostic action-state
// We need to provide it with an enum which stores the possible actions a player could take
.add_plugin(InputManagerPlugin::<Action>::default())
.add_plugins(InputManagerPlugin::<Action>::default())
// The InputMap and ActionState components will be added to any entity with the Player component
.add_startup_system(spawn_player)
.add_systems(Startup, spawn_player)
// Read the ActionState in your systems using queries!
.add_system(jump)
.add_systems(Update, jump)
.run();
}

// This is the list of "things in the game I want to be able to do based on input"
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug)]
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)]
enum Action {
Run,
Jump,
Expand Down
8 changes: 4 additions & 4 deletions examples/mouse_motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use leafwing_input_manager::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(InputManagerPlugin::<CameraMovement>::default())
.add_startup_system(setup)
.add_system(pan_camera)
.add_plugins(InputManagerPlugin::<CameraMovement>::default())
.add_systems(Startup, setup)
.add_systems(Update, pan_camera)
.run()
}

#[derive(Actionlike, Clone, Debug, Copy, PartialEq, Eq)]
#[derive(Actionlike, Clone, Debug, Copy, PartialEq, Eq, Reflect)]
enum CameraMovement {
Pan,
}
Expand Down
17 changes: 8 additions & 9 deletions examples/mouse_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ use leafwing_input_manager::{
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(InputManagerPlugin::<BoxMovement>::default())
.add_startup_system(setup)
.add_system(
.add_plugins(InputManagerPlugin::<BoxMovement>::default())
.add_systems(Startup, setup)
.add_systems(
Startup,
update_cursor_state_from_window
.run_if(run_if_enabled::<BoxMovement>)
.in_base_set(CoreSet::PreUpdate)
.in_set(InputManagerSystem::ManualControl)
.before(InputManagerSystem::ReleaseOnDisable)
.after(InputManagerSystem::Tick)
.after(InputManagerSystem::Update)
.after(InputSystem),
)
.add_system(pan_camera)
.add_systems(Update, pan_camera)
.run();
}

#[derive(Actionlike, Clone, Debug, Copy, PartialEq, Eq)]
#[derive(Actionlike, Clone, Debug, Copy, PartialEq, Eq, Reflect)]
enum BoxMovement {
MousePosition,
}
Expand Down Expand Up @@ -59,9 +59,8 @@ fn update_cursor_state_from_window(
.expect("Entity does not exist, or does not have an `ActionState` component");

if let Some(val) = window.cursor_position() {
action_state
.action_data_mut(driver.action.clone())
.axis_pair = Some(DualAxisData::from_xy(val));
action_state.action_data_mut(driver.action).axis_pair =
Some(DualAxisData::from_xy(val));
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use leafwing_input_manager::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(InputManagerPlugin::<CameraMovement>::default())
.add_startup_system(setup)
.add_system(zoom_camera)
.add_system(pan_camera.after(zoom_camera))
.add_plugins(InputManagerPlugin::<CameraMovement>::default())
.add_systems(Startup, setup)
.add_systems(Update, zoom_camera)
.add_systems(Update, pan_camera.after(zoom_camera))
.run()
}

#[derive(Actionlike, Clone, Debug, Copy, PartialEq, Eq)]
#[derive(Actionlike, Clone, Debug, Copy, PartialEq, Eq, Reflect)]
enum CameraMovement {
Zoom,
PanLeft,
Expand Down
7 changes: 3 additions & 4 deletions examples/multiplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use leafwing_input_manager::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(InputManagerPlugin::<Action>::default())
.add_startup_system(spawn_players)
.add_plugins(InputManagerPlugin::<Action>::default())
.add_systems(Startup, spawn_players)
.run();
}

#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug)]
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)]
enum Action {
Left,
Right,
Expand All @@ -25,7 +25,6 @@ enum Player {
#[derive(Bundle)]
struct PlayerBundle {
player: Player,
#[bundle]
input_manager: InputManagerBundle<Action>,
}

Expand Down
Loading

0 comments on commit 7fb55b0

Please sign in to comment.