Skip to content

Commit

Permalink
Update to Bevy 0.11 (#42)
Browse files Browse the repository at this point in the history
* Use `EntityCommands` and remove `InsertExt`

* Update crate version to 0.6.

* Steal Bevy CI for tests.

---------

Co-authored-by: JoJoJet <21144246+JoJoJet@users.noreply.github.com>
  • Loading branch information
zdimension and JoJoJet committed Jul 14, 2023
1 parent fd118a6 commit c130b7f
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 203 deletions.
69 changes: 60 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,73 @@
on: [pull_request]
on: [push, pull_request]

name: CI

jobs:

test:
name: Test Suite
runs-on: windows-latest
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- name: Install Bevy dependencies
run: |
sudo apt-get update;
DEBIAN_FRONTEND=noninteractive sudo apt-get install --no-install-recommends -yq \
libasound2-dev libudev-dev;
- name: install xvfb, llvmpipe and lavapipe
run: |
sudo apt-get update -y -qq
sudo add-apt-repository ppa:oibaf/graphics-drivers -y
sudo apt-get update
sudo apt install -y xvfb libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-run-examples-${{ hashFiles('**/Cargo.toml') }}
- uses: dtolnay/rust-toolchain@stable
- name: Run examples
run: |
for example in examples/*.rs; do
example_name=`basename $example .rs`
echo -n $example_name > last_example_run
echo "running $example_name - "`date`
time TRACE_CHROME=trace-$example_name.json CI_TESTING_CONFIG=.github/workflows/testing.ron xvfb-run cargo run --example $example_name --features "bevy/bevy_ci_testing,bevy/trace,bevy/trace_chrome"
sleep 10
if [ `find ./ -maxdepth 1 -name 'screenshot-*.png' -print -quit` ]; then
mkdir screenshots-$example_name
mv screenshot-*.png screenshots-$example_name/
fi
done
zip traces.zip trace*.json
touch placeholder
zip -r screenshots.zip screenshots-* placeholder
- name: save traces
uses: actions/upload-artifact@v3
with:
name: example-traces.zip
path: traces.zip
- name: save screenshots
uses: actions/upload-artifact@v3
with:
name: screenshots.zip
path: screenshots.zip
- name: Save PR number
if: ${{ failure() && github.event_name == 'pull_request' }}
run: |
mkdir -p ./example-run
echo ${{ github.event.number }} > ./example-run/NR
mv last_example_run ./example-run/
- uses: actions/upload-artifact@v2
if: ${{ failure() && github.event_name == 'pull_request' }}
with:
command: test
name: example-run
path: example-run/

fmt:
name: Rustfmt
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/testing.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(
exit_after: Some(300)
)
19 changes: 13 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_mouse_tracking_plugin"
description = "A plugin for effortless mouse tracking in the bevy game engine."
version = "0.5.3"
version = "0.6.0"
authors = ["JoJoJet <joe102000@gmail.com>"]
edition = "2021"
license = "MIT"
Expand All @@ -11,16 +11,23 @@ keywords = ["gamedev", "bevy", "mouse", "input"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.bevy]
version = "0.9"
version = "0.11"
default-features = false
features = [ "render" ]
features = [
"bevy_core_pipeline",
"bevy_render"
]

[dev-dependencies.bevy]
version = "0.9"
version = "0.11"
default-features = false
features = [
"render",
"bevy_core_pipeline",
"bevy_render",
"bevy_sprite",
"bevy_text",
"png",
"bevy_asset",
"bevy_winit"
"bevy_winit",
"x11"
]
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

| Bevy Version | Crate Version |
|--------------|---------------|
| 0.11 | 0.6 |
| 0.9 | 0.5 |
| 0.8 | 0.4 |
| 0.7 | 0.2.1 |
Expand All @@ -31,19 +32,20 @@ use bevy_mouse_tracking_plugin::prelude::*;
// First, add the plugin to your `App`.

App::new()
.add_plugins(DefaultPlugins)
.add_plugin(MousePosPlugin)
.add_startup_system(setup)
.add_system(dbg_mouse)
.add_plugins((DefaultPlugins, MousePosPlugin))
.add_systems(Startup, setup)
.add_systems(Update, dbg_mouse)
// ...


fn setup(mut commands: Commands) {
commands
// Spawn a camera bundle
.spawn(Camera2dBundle::default())
// Opt in to mouse tracking
.add_mouse_tracking();
// Opt in to mouse tracking.
// `InitMouseTracking` is a command that adds the mouse tracking
// component to the camera with a correct initial value.
.add(InitMouseTracking);
}

// Now, we can track the mouse position by querying for it.
Expand All @@ -67,7 +69,7 @@ fn setup(mut commands: Commands) {
commands
// Spawn a camera with tracking.
.spawn(Camera2dBundle::default())
.add_mouse_tracking()
.add(InitMouseTracking)
// Add a component to mark it as the main camera.
.insert(MainCamera);
}
Expand All @@ -94,7 +96,7 @@ fn setup(mut commands: Commands) {
.spawn(Camera2dBundle::default())
// Opt in to world-space mouse tracking.
// This will automatically opt into screen-space tracking.
.add_world_tracking()
.add(InitWorldTracking)
// ...
}

Expand Down
32 changes: 16 additions & 16 deletions examples/screen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::PrimaryWindow};

use bevy_mouse_tracking_plugin::{prelude::*, MainCamera, MouseMotion, MousePos};
use bevy_mouse_tracking_plugin::{
mouse_pos::InitMouseTracking, prelude::*, MainCamera, MouseMotion, MousePos,
};

#[derive(Component)]
struct Cursor;
Expand All @@ -10,23 +12,25 @@ struct Hud;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins((DefaultPlugins, MousePosPlugin, MouseMotionPlugin))
.insert_resource(ClearColor(Color::BLACK))
.add_plugin(MousePosPlugin)
.add_plugin(MouseMotionPlugin)
.add_startup_system(setup)
.add_system(bevy::window::close_on_esc)
.add_system(run)
.add_systems(Startup, setup)
.add_systems(Update, bevy::window::close_on_esc)
.add_systems(Update, run)
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, windows: Res<Windows>) {
let window = windows.get_primary().unwrap();
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
window: Query<&Window, With<PrimaryWindow>>,
) {
let window = window.single();

// Spawn a Camera
commands
.spawn(Camera2dBundle::default())
.add_mouse_tracking()
.add(InitMouseTracking)
.insert(MainCamera);

// Reference for the origin
Expand All @@ -42,10 +46,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, windows: Res<Wi
font_size: 24.0,
color: Color::ORANGE,
};
let alignment = TextAlignment {
vertical: VerticalAlign::Top,
horizontal: HorizontalAlign::Left,
};
let (win_width, win_height) = (window.width(), window.height());
let (hud_x, hud_y) = (win_width / 2. * -1., win_height / 2.);
let translation = Vec3::new(hud_x, hud_y, 0.);
Expand All @@ -54,7 +54,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, windows: Res<Wi

commands.spawn((
Text2dBundle {
text: Text::from_section(value, style).with_alignment(alignment),
text: Text::from_section(value, style).with_alignment(TextAlignment::Left),
transform,
..Default::default()
},
Expand Down
33 changes: 17 additions & 16 deletions examples/world.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::PrimaryWindow};

use bevy_mouse_tracking_plugin::{prelude::*, MainCamera, MousePos, MousePosWorld};
use bevy_mouse_tracking_plugin::{
mouse_pos::InitWorldTracking, prelude::*, MainCamera, MousePos, MousePosWorld,
};

#[derive(Component)]
struct Cursor;
Expand All @@ -10,24 +12,27 @@ struct Hud;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins((DefaultPlugins, MousePosPlugin))
.insert_resource(ClearColor(Color::BLACK))
.add_plugin(MousePosPlugin)
.add_startup_system(setup)
.add_system(bevy::window::close_on_esc)
.add_system(pan_camera)
.add_system(run)
.add_systems(Startup, setup)
.add_systems(Update, bevy::window::close_on_esc)
.add_systems(Update, (pan_camera, run))
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>, windows: Res<Windows>) {
let window = windows.get_primary().unwrap();
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
window: Query<&Window, With<PrimaryWindow>>,
) {
let window = window.single();

// Spawn a Camera
let mut camera_bundle = Camera2dBundle::default();
camera_bundle.projection.scale = 0.5; // works fine with non-unit scaling.
commands
.spawn((camera_bundle, MainCamera))
.add_world_tracking();
.add(InitWorldTracking);

// Reference for the origin
commands.spawn(SpriteBundle {
Expand All @@ -51,10 +56,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, windows: Res<Wi
font_size: 24.0,
color: Color::ORANGE,
};
let alignment = TextAlignment {
vertical: VerticalAlign::Top,
horizontal: HorizontalAlign::Left,
};
let (win_width, win_height) = (window.width(), window.height());
let (hud_x, hud_y) = (win_width / 2. * -1., win_height / 2.);
let translation = Vec3::new(hud_x, hud_y, 0.);
Expand All @@ -63,7 +64,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, windows: Res<Wi

commands.spawn((
Text2dBundle {
text: Text::from_section(value, style).with_alignment(alignment),
text: Text::from_section(value, style).with_alignment(TextAlignment::Left),
transform,
..Default::default()
},
Expand Down
Loading

0 comments on commit c130b7f

Please sign in to comment.