diff --git a/Cargo.toml b/Cargo.toml index 06b4fc3668a5b15ab46aa682959b42890b4016c1..52ed5f146351f7c1bea64c3a823fde03ff6c9c59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "micro_bevy_web_utils" -version = "0.3.0" +version = "0.4.0" edition = "2021" description = "Utilities for patching various missing parts from Bevy web/touch support" authors = [ @@ -11,9 +11,10 @@ homepage = "https://lab.lcr.gr/microhacks/bevy-web-utils" license = "Apache-2.0" [dependencies] -bevy_ecs = "0.11.0" -bevy_input = "0.11.0" -bevy_math = "0.11.0" +bevy_ecs = "0.13.0" +bevy_input = "0.13.0" +bevy_math = "0.13.0" +bevy_window = "0.13.0" wasm-bindgen = "0.2.83" -serde = "1.0.151" -serde_json = "1.0.91" \ No newline at end of file +serde = "1.0" +serde_json = "1.0" \ No newline at end of file diff --git a/src/bevy.rs b/src/bevy.rs index 4cba45c85edab899d2205f6fa16d3ec9816055ef..a2971eda4dfb35d2c4e6d943434386f234d32b7b 100644 --- a/src/bevy.rs +++ b/src/bevy.rs @@ -1,6 +1,10 @@ +use bevy_ecs::entity::Entity; use bevy_ecs::event::EventWriter; +use bevy_ecs::query::With; +use bevy_ecs::system::Query; use bevy_input::touch::{TouchInput, TouchPhase}; use bevy_math::Vec2; +use bevy_window::{PrimaryWindow, Window}; use std::fmt::{Display, Formatter}; #[derive(serde::Deserialize)] @@ -39,10 +43,19 @@ fn inner_touch_events() -> Result<impl IntoIterator<Item = InnerTouchInput>, Tou Ok(touch_events.into_iter()) } -pub fn emit_touch_events(mut events: EventWriter<TouchInput>) { +pub fn emit_touch_events( + windows: Query<Entity, With<PrimaryWindow>>, + mut events: EventWriter<TouchInput>, +) { + let window = match windows.iter().next() { + Some(window) => window, + None => return, + }; + if let Ok(inner_events) = inner_touch_events() { for input in inner_events { events.send(TouchInput { + window, phase: input.phase, position: input.position, id: input.id,