Skip to content

Commit

Permalink
feat: migrate to bevy 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Nov 18, 2023
1 parent c9955ad commit f020c58
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 205 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ inspect = ["bevy-inspector-egui"]
serde = ["dep:serde"]

[dependencies]
bevy = { version = "0.11", default-features = false, features = [
bevy = { version = "0.12", default-features = false, features = [
"bevy_render",
"bevy_ui"
"bevy_ui",
] }
bevy-inspector-egui = { version = "0.19", optional = true }
bevy-inspector-egui = { version = "0.21", optional = true }
serde = { version = "^1", features = ["derive"], optional = true }

[dev-dependencies]
bevy = "0.11"
bevy = "0.12"
18 changes: 7 additions & 11 deletions src/input.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::hash::Hash;

use bevy::{
input::{mouse::MouseButtonInput, touch::TouchPhase, ButtonState},
prelude::*,
reflect::TypePath,
window::PrimaryWindow,
};

use crate::VirtualJoystickID;
use crate::{
joystick::VirtualJoystickKnob, VirtualJoystickEvent, VirtualJoystickEventType,
joystick::VirtualJoystickData, VirtualJoystickEvent, VirtualJoystickEventType,
VirtualJoystickNode, VirtualJoystickType,
};

Expand All @@ -30,14 +28,12 @@ fn is_some_and<T>(opt: Option<T>, cb: impl FnOnce(T) -> bool) -> bool {
false
}

pub fn update_input<
S: Hash + Sync + Send + Clone + Default + Reflect + TypePath + FromReflect + 'static,
>(
pub fn update_input<S: VirtualJoystickID>(
mut input_events: EventReader<InputEvent>,
mut send_values: EventWriter<VirtualJoystickEvent<S>>,
mut joysticks: Query<(&VirtualJoystickNode<S>, &mut VirtualJoystickKnob)>,
mut joysticks: Query<(&VirtualJoystickNode<S>, &mut VirtualJoystickData)>,
) {
let input_events = input_events.iter().collect::<Vec<&InputEvent>>();
let input_events = input_events.read().collect::<Vec<&InputEvent>>();

for (node, mut knob) in joysticks.iter_mut() {
for event in &input_events {
Expand Down Expand Up @@ -121,7 +117,7 @@ pub fn update_joystick(
mut send_values: EventWriter<InputEvent>,
) {
let touches = touch_events
.iter()
.read()
.map(|e| (e.id, e.phase, e.position))
.collect::<Vec<(u64, TouchPhase, Vec2)>>();

Expand Down Expand Up @@ -152,7 +148,7 @@ pub fn update_joystick_by_mouse(
let window = windows.single();
let pos = window.cursor_position().unwrap_or(Vec2::ZERO);

for mousebtn in mousebtn_evr.iter() {
for mousebtn in mousebtn_evr.read() {
// End drag
if mousebtn.button == MouseButton::Left && mousebtn.state == ButtonState::Released {
send_values.send(InputEvent::EndDrag { id: 0, pos });
Expand Down
Loading

0 comments on commit f020c58

Please sign in to comment.