From 3a77ef4c8bf2e9e169eb620f4c4a6b5bab720ae0 Mon Sep 17 00:00:00 2001 From: "Alexis \"spectria.limina\" Horizon" Date: Wed, 4 Dec 2024 21:53:53 -0500 Subject: [PATCH] Fix tests. lol. --- .github/workflows/ci.yml | 10 +++++----- Cargo.lock | 1 + Cargo.toml | 1 + src/spawner.rs | 17 ++++++++++++----- src/testing.rs | 39 ++++++++++++++++++++++++++++----------- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ac92c8..100dbb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ env: CARGO_TERM_COLOR: always jobs: - build-test-x86: + build-test-x86_64: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -18,9 +18,9 @@ jobs: with: shared-key: "cargo" - name: Build - run: cargo build --verbose + run: cargo build --all --verbose - name: Test - run: cargo test --verbose + run: cargo test --all --verbose build-test-wasm: runs-on: ubuntu-latest env: @@ -33,9 +33,9 @@ jobs: - name: Install Target run: rustup target add wasm32-unknown-unknown - name: Build - run: cargo build --verbose --target wasm32-unknown-unknown + run: cargo build --all --verbose --target wasm32-unknown-unknown - name: Test - run: cargo test --verbose --target wasm32-unknown-unknown + run: cargo test --all --verbose --target wasm32-unknown-unknown build-release-wasm: runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' diff --git a/Cargo.lock b/Cargo.lock index f62cf2a..3b53847 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4427,6 +4427,7 @@ dependencies = [ "tataru", "thiserror 2.0.4", "tracing", + "uuid", "wasm-bindgen", "web-sys", ] diff --git a/Cargo.toml b/Cargo.toml index ca399a9..b79dc8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,7 @@ serde_json.workspace = true tataru.workspace = true thiserror = "2.0.3" tracing.workspace = true +uuid = "1.11.0" [target.'cfg(target_arch = "wasm32")'.dependencies] convert_case = "0.6.0" diff --git a/src/spawner.rs b/src/spawner.rs index 0543ec7..754a0e9 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -216,10 +216,13 @@ mod test { use crate::widget::egui_context; use crate::{testing::*, widget}; + use avian2d::PhysicsPlugins; use bevy::app::ScheduleRunnerPlugin; + use bevy::input::mouse::MouseButtonInput; + use bevy::picking::pointer::PointerInput; use bevy::render::settings::{RenderCreation, WgpuSettings}; use bevy::render::RenderPlugin; - use bevy::window::PrimaryWindow; + use bevy::window::{PrimaryWindow, WindowEvent}; use bevy::winit::WinitPlugin; use bevy_egui::EguiPlugin; use bevy_egui::{egui, EguiContexts}; @@ -258,7 +261,7 @@ mod test { .observe(Spawner::::start_drag); commands.spawn(DragSurfaceBundle::new(Rect::from_center_half_size( Vec2::ZERO, - Vec2::splat(100.0), + Vec2::splat(200.0), ))); } @@ -280,6 +283,8 @@ mod test { .add_plugins(ScheduleRunnerPlugin { run_mode: bevy::app::RunMode::Loop { wait: None }, }) + .add_plugins(PhysicsPlugins::default()) + .add_systems(PreUpdate, forward_window_events) .add_plugins(EguiPlugin) .add_plugins(crate::cursor::plugin()) .add_plugins(SpawnerPlugin::::default()) @@ -301,7 +306,6 @@ mod test { } #[test] - #[ignore = "broken since 0.15 for some reason: the drag ain't draggin'"] fn spawner_drag() { let (mut app, _) = test_app(); @@ -314,12 +318,15 @@ mod test { button: MouseButton::Left, duration: 10.0, }); - app.add_systems(Update, MockDrag::update) + app.add_systems(First, MockDrag::update) .add_observer(observe_debug::>) .add_observer(observe_debug::>) .add_observer(observe_debug::>) + .add_systems(Update, log_debug::) .add_systems(Update, log_debug::) - .add_systems(Update, log_debug::) + .add_systems(Update, log_debug::) + .add_systems(Update, log_debug::) + .add_systems(Update, log_debug::) .add_systems(First, || { debug!("new tick"); }); diff --git a/src/testing.rs b/src/testing.rs index ff4f94f..0d407ec 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -3,7 +3,7 @@ use bevy::{ ecs::query::QuerySingleError, input::{mouse::MouseButtonInput, ButtonState}, prelude::*, - window::PrimaryWindow, + window::{PrimaryWindow, WindowEvent}, }; use itertools::Itertools; @@ -81,8 +81,7 @@ impl MockDrag { mut q: Query<(Entity, &MockDrag, Option<&mut MockDragState>)>, win_q: Query>, mut commands: Commands, - mut cursor_ev: EventWriter, - mut button_ev: EventWriter, + mut window_ev: EventWriter, ) { let win = win_q.single(); match q.get_single_mut() { @@ -93,40 +92,40 @@ impl MockDrag { pos: drag.start_pos, ..default() }); - cursor_ev.send(CursorMoved { + window_ev.send(WindowEvent::CursorMoved(CursorMoved { window: win, position: drag.start_pos, delta: None, - }); + })); debug!("beginning mock drag at {}", drag.start_pos); } Ok((id, drag, Some(ref mut state))) => { if state.tick == 0.0 { - button_ev.send(MouseButtonInput { + window_ev.send(WindowEvent::MouseButtonInput(MouseButtonInput { window: win, button: drag.button, state: ButtonState::Pressed, - }); + })); state.tick += 1.0; return; } if state.tick / drag.duration >= 1.0 + 0.0001 { - button_ev.send(MouseButtonInput { + window_ev.send(WindowEvent::MouseButtonInput(MouseButtonInput { window: win, button: drag.button, state: ButtonState::Released, - }); + })); debug!("ending mock drag"); commands.entity(id).despawn(); return; } let progress = f32::min(state.tick / drag.duration, 1.0); let pos = drag.start_pos.lerp(drag.end_pos, progress); - cursor_ev.send(CursorMoved { + window_ev.send(WindowEvent::CursorMoved(CursorMoved { window: win, position: pos, delta: Some(pos - state.pos), - }); + })); state.tick += 1.0; state.pos = pos; debug!("continuing mock drag to {}", pos); @@ -139,6 +138,24 @@ impl MockDrag { } } +pub fn forward_window_events( + mut reader: EventReader, + mut cursor_moved: EventWriter, + mut mouse_button_input: EventWriter, +) { + for ev in reader.read() { + match ev { + WindowEvent::CursorMoved(ev) => { + cursor_moved.send(ev.clone()); + } + WindowEvent::MouseButtonInput(ev) => { + mouse_button_input.send(*ev); + } + _ => {} + } + } +} + #[track_caller] pub fn debug_entities(world: &World) { for e in world.iter_entities() {