Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
408df51
Target bevy main to migrate to 0.10
TimJentzsch Feb 8, 2023
485d5c6
Fix errors in plugin.rs
TimJentzsch Feb 8, 2023
a6c632e
Fix compile errors in systems.rs
TimJentzsch Feb 8, 2023
5e90e27
Port gamepad events to Bevy 0.10
TimJentzsch Feb 8, 2023
163b08d
Fix mutable access
TimJentzsch Feb 8, 2023
0c7a96b
Fix use of in_set instead of in_base_set
TimJentzsch Feb 8, 2023
6401fc4
Fix some errors in examples
TimJentzsch Feb 8, 2023
2ba31e4
Fix set assignments that I messed up
TimJentzsch Feb 8, 2023
e752b50
Merge branch 'main' into bevy-0.10
TimJentzsch Mar 2, 2023
6fcea54
Test bevy_egui branch for bevy main
TimJentzsch Mar 6, 2023
7c5b215
Use bevy 0.10 instead of main
TimJentzsch Mar 6, 2023
951a60f
Move to new 0.10 branch of bevy_egui
TimJentzsch Mar 7, 2023
daa6f0b
Fix compile error with enabled egui feature
TimJentzsch Mar 7, 2023
1b28798
Fix clippy lint warnings
TimJentzsch Mar 7, 2023
8173eb1
Bump egui dependency to released version
alice-i-cecile Mar 8, 2023
5271f7f
Update binding_menu example
alice-i-cecile Mar 8, 2023
bc63f9d
Merge branch 'main' into bevy-0.10
alice-i-cecile Mar 8, 2023
53fd8ed
Fix merge conflicts
alice-i-cecile Mar 8, 2023
279e90a
Fix compile errors in examples
TimJentzsch Mar 8, 2023
236e0fb
Fix broken import
alice-i-cecile Mar 8, 2023
d211155
Fix egui configuration in update_action_state
TimJentzsch Mar 8, 2023
3abbcef
Merge branch 'bevy-0.10' of github.com:TimJentzsch/leafwing-input-man…
TimJentzsch Mar 8, 2023
b85961e
Bump once_cell dependency
TimJentzsch Mar 8, 2023
d99ff62
Bump LWIM to version 0.9.0
TimJentzsch Mar 8, 2023
1ebd797
Revert "Bump LWIM to version 0.9.0"
TimJentzsch Mar 8, 2023
83fd073
Add dependency bumps to release notes
TimJentzsch Mar 8, 2023
c0a37a1
Fix compile errors in tests
TimJentzsch Mar 8, 2023
e361adc
Replace deprecated ChangeTrackers in favor of Ref
TimJentzsch Mar 8, 2023
d481180
Try to fix test failure
TimJentzsch Mar 8, 2023
1085510
Second attempt to fix change detection for action state
TimJentzsch Mar 8, 2023
d46dfc3
Fix find-and-replace error in docs
alice-i-cecile Mar 8, 2023
cb5ee94
Merge remote-tracking branch 'TimJentzsch/bevy-0.10' into bevy-0.10
alice-i-cecile Mar 8, 2023
dcd5740
Remove broken test: should be failed due to timers ticking
alice-i-cecile Mar 8, 2023
9561c55
Revert "Second attempt to fix change detection for action state"
TimJentzsch Mar 8, 2023
f16f0f4
Revert "Try to fix test failure"
TimJentzsch Mar 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,33 @@ egui = ['dep:bevy_egui']

[dependencies]
leafwing_input_manager_macros = { path = "macros", version = "0.7" }

bevy = {version = "0.9", default-features = false, features = ["serialize", "bevy_gilrs"]}
bevy_egui = {version = "0.19", optional = true}

petitset = {version = "0.2.1", features = ["serde_compat"]}
derive_more = {version = "0.99", default-features = false, features = ["display", "error"]}
bevy = { version = "0.10", default-features = false, features = [
"serialize",
"bevy_gilrs",
] }
bevy_egui = { version = "0.20", optional = true }

petitset = { version = "0.2.1", features = ["serde_compat"] }
derive_more = { version = "0.99", default-features = false, features = [
"display",
"error",
] }
itertools = "0.10"
serde = {version = "1.0", features = ["derive"]}
fixedbitset = "0.4.2"
once_cell = "1.17.0"
serde = { version = "1.0", features = ["derive"] }
fixedbitset = "0.4.2"
once_cell = "1.17.1"

[dev-dependencies]
bevy = {version = "0.9", default-features = false, features = ["bevy_asset", "bevy_sprite", "bevy_text", "bevy_ui", "bevy_render", "bevy_core_pipeline", "x11"]}
bevy_egui = {version = "0.19"}
bevy_egui = { version = "0.20" }
bevy = { version = "0.10", default-features = false, features = [
"bevy_asset",
"bevy_sprite",
"bevy_text",
"bevy_ui",
"bevy_render",
"bevy_core_pipeline",
"x11",
] }
serde_test = "1.0"

[lib]
Expand Down
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Usability

- Added `ActionState::consume_all()` to consume all actions.
- `bevy_egui` dependency has been bumped from 0.19 to 0.20.
- `bevy` dependency has been bumped from 0.9 to 0.10.

### Enhancements

Expand Down
7 changes: 4 additions & 3 deletions examples/arpg_indirection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ fn main() {
.add_plugin(InputManagerPlugin::<Ability>::default())
.add_startup_system(spawn_player)
// This system coordinates the state of our two actions
.add_system_to_stage(
CoreStage::PreUpdate,
copy_action_state.after(InputManagerSystem::ManualControl),
.add_system(
copy_action_state
.in_base_set(CoreSet::PreUpdate)
.after(InputManagerSystem::ManualControl),
)
// Try it out, using QWER / left click / right click!
.add_system(report_abilities_used)
Expand Down
33 changes: 19 additions & 14 deletions examples/binding_menu.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use bevy::{
ecs::system::SystemParam,
input::{keyboard::KeyboardInput, mouse::MouseButtonInput, ButtonState},
input::{
gamepad::{GamepadButtonChangedEvent, GamepadEvent},
keyboard::KeyboardInput,
mouse::MouseButtonInput,
ButtonState,
},
prelude::*,
window::PrimaryWindow,
};
use bevy_egui::{
egui::{Align2, Area, Grid, Window},
EguiContext, EguiPlugin,
EguiContexts, EguiPlugin,
};
use derive_more::Display;
use leafwing_input_manager::{prelude::*, user_input::InputKind};
Expand Down Expand Up @@ -37,12 +43,12 @@ fn spawn_player_system(mut commands: Commands, control_settings: Res<ControlSett

fn controls_window_system(
mut commands: Commands,
mut egui: ResMut<EguiContext>,
windows: Res<Windows>,
mut egui: EguiContexts,
windows: Query<&bevy::window::Window, With<PrimaryWindow>>,
control_settings: ResMut<ControlSettings>,
) {
// The window may not exist when the application closes
let Some(main_window) = windows.get_primary() else {
let Ok(main_window) = windows.get_single() else {
return;
};
let window_width_margin = egui.ctx_mut().style().spacing.window_margin.left * 2.0;
Expand Down Expand Up @@ -89,7 +95,7 @@ fn controls_window_system(
}

fn buttons_system(
mut egui: ResMut<EguiContext>,
mut egui: EguiContexts,
mut control_settings: ResMut<ControlSettings>,
mut player_mappings: Query<&mut InputMap<ControlAction>>,
) {
Expand All @@ -109,7 +115,7 @@ fn buttons_system(

fn binding_window_system(
mut commands: Commands,
mut egui: ResMut<EguiContext>,
mut egui: EguiContexts,
mut input_events: InputEvents,
active_binding: Option<ResMut<ActiveBinding>>,
mut control_settings: ResMut<ControlSettings>,
Expand Down Expand Up @@ -265,15 +271,14 @@ impl InputEvents<'_, '_> {
return Some(mouse_input.button.into());
}
}
if let Some(GamepadEvent {
if let Some(GamepadEvent::Button(GamepadButtonChangedEvent {
gamepad: _,
event_type,
}) = self.gamepad_events.iter().next()
button_type,
value: strength,
})) = self.gamepad_events.iter().next()
{
if let GamepadEventType::ButtonChanged(button, strength) = event_type.to_owned() {
if strength <= 0.5 {
return Some(button.into());
}
if *strength <= 0.5 {
return Some((*button_type).into());
}
}
None
Expand Down
9 changes: 6 additions & 3 deletions examples/press_duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
//! Press Left / Right or A / D to move your character to the left and right!

use bevy::prelude::*;
use bevy::{prelude::*, window::PrimaryWindow};
use leafwing_input_manager::prelude::*;

fn main() {
Expand Down Expand Up @@ -115,8 +115,11 @@ fn drag(mut query: Query<&mut Velocity>, time: Res<Time>) {
}
}

fn wall_collisions(mut query: Query<(&Transform, &mut Velocity)>, windows: Res<Windows>) {
let window_width = windows.get_primary().unwrap().width();
fn wall_collisions(
mut query: Query<(&Transform, &mut Velocity)>,
windows: Query<&Window, With<PrimaryWindow>>,
) {
let window_width = windows.single().width();
let left_side = 0.0 - window_width / 2.0;
let right_side = 0.0 + window_width / 2.0;

Expand Down
10 changes: 2 additions & 8 deletions examples/send_actions_over_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ fn main() {
.add_plugin(InputPlugin)
.add_plugin(InputManagerPlugin::<FpsAction>::default())
// Creates an event stream of `ActionDiffs` to send to the server
.add_system_to_stage(
CoreStage::PostUpdate,
generate_action_diffs::<FpsAction, StableId>,
)
.add_system(generate_action_diffs::<FpsAction, StableId>.in_base_set(CoreSet::PostUpdate))
.add_event::<ActionDiff<FpsAction, StableId>>()
.add_startup_system(spawn_player);

Expand All @@ -49,10 +46,7 @@ fn main() {
.add_plugin(InputManagerPlugin::<FpsAction>::server())
.add_event::<ActionDiff<FpsAction, StableId>>()
// Reads in the event stream of `ActionDiffs` to update the `ActionState`
.add_system_to_stage(
CoreStage::PreUpdate,
process_action_diffs::<FpsAction, StableId>,
)
.add_system(process_action_diffs::<FpsAction, StableId>.in_base_set(CoreSet::PreUpdate))
// Typically, the rest of this information would synchronized as well
.add_startup_system(spawn_player);

Expand Down
2 changes: 1 addition & 1 deletion examples/ui_driven_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.add_plugin(InputManagerPlugin::<Action>::default())
.add_startup_system(spawn_player)
.add_startup_system(spawn_cameras)
.add_startup_system_to_stage(StartupStage::PostStartup, spawn_ui)
.add_startup_system(spawn_ui.in_base_set(StartupSet::PostStartup))
.add_system(move_player)
.run();
}
Expand Down
51 changes: 30 additions & 21 deletions src/input_mocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use bevy::ecs::system::{ResMut, SystemState};
use bevy::ecs::world::World;
#[cfg(feature = "ui")]
use bevy::ecs::{component::Component, query::With, system::Query};
use bevy::input::gamepad::GamepadEventRaw;
use bevy::input::gamepad::{GamepadAxisChangedEvent, GamepadButtonChangedEvent};
use bevy::input::mouse::MouseScrollUnit;
use bevy::input::ButtonState;
use bevy::input::{
gamepad::{Gamepad, GamepadButton, GamepadEvent, GamepadEventType},
gamepad::{Gamepad, GamepadButton, GamepadEvent},
keyboard::{KeyCode, KeyboardInput},
mouse::{MouseButton, MouseButtonInput, MouseMotion, MouseWheel},
touch::{TouchInput, Touches},
Expand Down Expand Up @@ -216,10 +216,12 @@ impl MockInput for MutableInputStreams<'_> {
// Gamepad buttons
for button_type in raw_inputs.gamepad_buttons {
if let Some(gamepad) = gamepad {
self.gamepad_events.send(GamepadEventRaw {
gamepad,
event_type: GamepadEventType::ButtonChanged(button_type, 1.0),
});
self.gamepad_events
.send(GamepadEvent::Button(GamepadButtonChangedEvent {
gamepad,
button_type,
value: 1.0,
}));
}
}

Expand All @@ -229,10 +231,12 @@ impl MockInput for MutableInputStreams<'_> {
match outer_axis_type {
AxisType::Gamepad(axis_type) => {
if let Some(gamepad) = gamepad {
self.gamepad_events.send(GamepadEventRaw {
gamepad,
event_type: GamepadEventType::AxisChanged(axis_type, position_data),
});
self.gamepad_events
.send(GamepadEvent::Axis(GamepadAxisChangedEvent {
gamepad,
axis_type,
value: position_data,
}));
}
}
AxisType::MouseWheel(axis_type) => {
Expand Down Expand Up @@ -281,10 +285,12 @@ impl MockInput for MutableInputStreams<'_> {

for button_type in raw_inputs.gamepad_buttons {
if let Some(gamepad) = gamepad {
self.gamepad_events.send(GamepadEventRaw {
gamepad,
event_type: GamepadEventType::ButtonChanged(button_type, 1.0),
});
self.gamepad_events
.send(GamepadEvent::Button(GamepadButtonChangedEvent {
gamepad,
button_type,
value: 1.0,
}));
}
}

Expand Down Expand Up @@ -481,7 +487,10 @@ impl MockInput for App {
mod test {
use crate::input_mocking::MockInput;
use bevy::{
input::{gamepad::GamepadInfo, InputPlugin},
input::{
gamepad::{GamepadConnection, GamepadConnectionEvent, GamepadEvent, GamepadInfo},
InputPlugin,
},
prelude::*,
};

Expand Down Expand Up @@ -522,12 +531,12 @@ mod test {

let gamepad = Gamepad { id: 0 };
let mut gamepad_events = app.world.resource_mut::<Events<GamepadEvent>>();
gamepad_events.send(GamepadEvent {
gamepad_events.send(GamepadEvent::Connection(GamepadConnectionEvent {
gamepad,
event_type: GamepadEventType::Connected(GamepadInfo {
connection: GamepadConnection::Connected(GamepadInfo {
name: "TestController".into(),
}),
});
}));
app.update();

// Test that buttons are unpressed by default
Expand Down Expand Up @@ -562,12 +571,12 @@ mod test {

let gamepad = Gamepad { id: 0 };
let mut gamepad_events = app.world.resource_mut::<Events<GamepadEvent>>();
gamepad_events.send(GamepadEvent {
gamepad_events.send(GamepadEvent::Connection(GamepadConnectionEvent {
gamepad,
event_type: GamepadEventType::Connected(GamepadInfo {
connection: GamepadConnection::Connected(GamepadInfo {
name: "TestController".into(),
}),
});
}));
app.update();

// Test that buttons are unpressed by default
Expand Down
17 changes: 7 additions & 10 deletions src/input_streams.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
//! Unified input streams for working with [`bevy::input`] data.

use bevy::{
input::{
gamepad::{Gamepad, GamepadAxis, GamepadButton, GamepadEventRaw, Gamepads},
keyboard::{KeyCode, KeyboardInput},
mouse::{MouseButton, MouseButtonInput, MouseMotion, MouseWheel},
Axis, Input,
},
prelude::ScanCode,
use bevy::input::{
gamepad::{Gamepad, GamepadAxis, GamepadButton, GamepadEvent, Gamepads},
keyboard::{KeyCode, KeyboardInput, ScanCode},
mouse::{MouseButton, MouseButtonInput, MouseMotion, MouseWheel},
Axis, Input,
};
use petitset::PetitSet;

Expand Down Expand Up @@ -403,7 +400,7 @@ pub struct MutableInputStreams<'a> {
/// A list of registered [`Gamepads`]
pub gamepads: &'a mut Gamepads,
/// Events used for mocking gamepad-related inputs
pub gamepad_events: &'a mut Events<GamepadEventRaw>,
pub gamepad_events: &'a mut Events<GamepadEvent>,

/// A [`KeyCode`] [`Input`] stream
pub keycodes: &'a mut Input<KeyCode>,
Expand Down Expand Up @@ -433,7 +430,7 @@ impl<'a> MutableInputStreams<'a> {
ResMut<Axis<GamepadButton>>,
ResMut<Axis<GamepadAxis>>,
ResMut<Gamepads>,
ResMut<Events<GamepadEventRaw>>,
ResMut<Events<GamepadEvent>>,
ResMut<Input<KeyCode>>,
ResMut<Input<ScanCode>>,
ResMut<Events<KeyboardInput>>,
Expand Down
Loading