Skip to content

Commit

Permalink
Upgrade to Bevy 0.10 and release v 0.4 (#30)
Browse files Browse the repository at this point in the history
* Bump version numbers

* Simple migrations

* Repair gamepad.rs example

* Faster CI

* Add release notes stub

* App:update no longer sends AppExit
  • Loading branch information
alice-i-cecile authored Mar 7, 2023
1 parent ff29b3f commit c1779b5
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 158 deletions.
144 changes: 54 additions & 90 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,121 +1,85 @@
# modified from: https://github.com/bevyengine/bevy/blob/main/.github/workflows/ci.yml
name: CI

on:
pull_request:
branches: [main]
push:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
build:
strategy:
matrix:
toolchain: [stable]
os: [windows-latest]
runs-on: ${{ matrix.os }}
check-lints:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-build-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.toml') }}
toolchain: stable
components: rustfmt, clippy
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
- name: CI job
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci -- lints

check-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
toolchain: stable
override: true
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
if: runner.os == 'linux'
- name: Build & run tests
run: cargo test --workspace
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci -- test
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-C debuginfo=0 -D warnings"

ci:
runs-on: windows-latest
check-compiles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-ci-${{ hashFiles('**/Cargo.toml') }}
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
override: true
- name: CI job
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
- name: Check Compile
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci

check-markdown-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: check dead links
continue-on-error: true
id: run1
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
config-file: '.github/linters/markdown-link-check.json'
- name: Sleep for 30 seconds
if: steps.run1.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry)
continue-on-error: true
id: run2
if: steps.run1.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
config-file: '.github/linters/markdown-link-check.json'
- name: Sleep for 30 seconds
if: steps.run2.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry 2)
continue-on-error: true
id: run3
if: steps.run2.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
config-file: '.github/linters/markdown-link-check.json'
- name: set the status
if: always()
run: |
if ${{ steps.run1.outcome=='success' || steps.run2.outcome=='success' || steps.run3.outcome=='success' }}; then
echo success
else
exit 1
fi
run: cargo run -p ci -- compile

markdownlint:
check-doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
- name: Run Markdown Lint
uses: docker://ghcr.io/github/super-linter:slim-v4
toolchain: stable
- name: Cache Cargo build files
uses: Leafwing-Studios/[email protected]
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
if: runner.os == 'linux'
- name: Build and check doc
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci -- doc
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: true
DEFAULT_BRANCH: main
RUSTFLAGS: "-C debuginfo=0"
# - name: Installs cargo-deadlinks
# run: cargo install --force cargo-deadlinks
# - name: Checks dead links
# run: cargo deadlinks
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "leafwing_input_playback"
description = "Input recording and mocking functionality for the Bevy game engine."
version = "0.3.0"
version = "0.4.0"
authors = ["Leafwing Studios"]
homepage = "https://leafwing-studios.com/"
repository = "https://github.com/leafwing-studios/leafwing_input_playback"
Expand All @@ -21,12 +21,12 @@ members = ["./", "tools/ci"]
default = []

[dependencies]
bevy = {version ="0.9", default_features = false, features = ["serialize"]}
bevy = {version ="0.10", default_features = false, features = ["serialize"]}
serde = {version = "1.0", features = ["derive"]}
ron = "0.8"

[dev-dependencies]
bevy = {version ="0.9", default_features = true, features = ["serialize"]}
bevy = {version ="0.10", default_features = true, features = ["serialize"]}

[lib]
name = "leafwing_input_playback"
Expand Down
6 changes: 6 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes

## Version 0.3

Migrated to `bevy 0.10`.

Note that `App::update` no longer sends an `AppExit` event: this may affect your tests!

## Version 0.1

### Enhancements
Expand Down
20 changes: 14 additions & 6 deletions examples/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod gamepad_viewer_example {
use std::f32::consts::PI;

use bevy::{
input::gamepad::{GamepadButton, GamepadSettings},
input::gamepad::{GamepadButton, GamepadButtonChangedEvent, GamepadEvent, GamepadSettings},
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
};
Expand Down Expand Up @@ -401,7 +401,7 @@ mod gamepad_viewer_example {
style,
},
])
.with_alignment(TextAlignment::BOTTOM_CENTER),
.with_alignment(TextAlignment::Center),
..default()
})
.insert(TextWithAxes { x_axis, y_axis });
Expand Down Expand Up @@ -466,7 +466,7 @@ mod gamepad_viewer_example {
color: TEXT_COLOR,
},
)
.with_alignment(TextAlignment::CENTER),
.with_alignment(TextAlignment::Center),
..default()
})
.insert(TextWithButtonValue(button_type));
Expand Down Expand Up @@ -528,9 +528,14 @@ mod gamepad_viewer_example {
mut query: Query<(&mut Text, &TextWithButtonValue)>,
) {
for event in events.iter() {
if let GamepadEventType::ButtonChanged(button_type, value) = event.event_type {
if let GamepadEvent::Button(GamepadButtonChangedEvent {
gamepad: _,
button_type,
value,
}) = event
{
for (mut text, text_with_button_value) in query.iter_mut() {
if button_type == **text_with_button_value {
if *button_type == **text_with_button_value {
text.sections[0].value = format!("{:.3}", value);
}
}
Expand All @@ -544,7 +549,10 @@ mod gamepad_viewer_example {
mut text_query: Query<(&mut Text, &TextWithAxes)>,
) {
for event in events.iter() {
if let GamepadEventType::AxisChanged(axis_type, value) = event.event_type {
if let GamepadEvent::Axis(axis_changed_event) = event {
let axis_type = axis_changed_event.axis_type;
let value = axis_changed_event.value;

for (mut transform, move_with) in query.iter_mut() {
if axis_type == move_with.x_axis {
transform.translation.x = value * move_with.scale;
Expand Down
6 changes: 3 additions & 3 deletions examples/input_playback.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::PrimaryWindow};

use leafwing_input_playback::{
input_capture::{InputCapturePlugin, InputModesCaptured},
Expand Down Expand Up @@ -56,14 +56,14 @@ struct Box;

fn spawn_boxes(
mut commands: Commands,
windows: Res<Windows>,
windows: Query<&Window, With<PrimaryWindow>>,
mouse_input: Res<Input<MouseButton>>,
camera_query: Query<(&Transform, &Camera)>,
) {
const BOX_SCALE: f32 = 50.0;

if mouse_input.pressed(MouseButton::Left) {
let primary_window = windows.primary();
let primary_window = windows.single();
// Don't break if we leave the window
if let Some(cursor_pos) = cursor_pos_as_world_pos(primary_window, &camera_query) {
commands
Expand Down
20 changes: 10 additions & 10 deletions src/input_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//!
//! These are unified into a single [`TimestampedInputs`](crate::timestamped_input::TimestampedInputs) resource, which can be played back.
use bevy::app::{App, AppExit, CoreStage, Plugin};
use bevy::app::{App, AppExit, CoreSet, Plugin};
use bevy::ecs::prelude::*;
use bevy::input::gamepad::GamepadEventRaw;
use bevy::input::gamepad::GamepadEvent;
use bevy::input::keyboard::KeyboardInput;
use bevy::input::mouse::{MouseButtonInput, MouseWheel};
use bevy::time::Time;
Expand All @@ -30,20 +30,20 @@ impl Plugin for InputCapturePlugin {
// Avoid double-adding frame_counter
if !app.world.contains_resource::<FrameCount>() {
app.init_resource::<FrameCount>()
.add_system_to_stage(CoreStage::First, frame_counter);
.add_system(frame_counter.in_base_set(CoreSet::First));
}

app.init_resource::<TimestampedInputs>()
.init_resource::<InputModesCaptured>()
.init_resource::<PlaybackFilePath>()
.add_system_to_stage(
.add_system(
// Capture any mocked input as well
CoreStage::Last,
capture_input,
capture_input.in_base_set(CoreSet::Last),
)
.add_system_to_stage(
CoreStage::Last,
serialize_captured_input_on_exit.after(capture_input),
.add_system(
serialize_captured_input_on_exit
.in_base_set(CoreSet::Last)
.after(capture_input),
);
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn capture_input(
mut mouse_wheel_events: EventReader<MouseWheel>,
mut cursor_moved_events: EventReader<CursorMoved>,
mut keyboard_events: EventReader<KeyboardInput>,
mut gamepad_events: EventReader<GamepadEventRaw>,
mut gamepad_events: EventReader<GamepadEvent>,
mut app_exit_events: EventReader<AppExit>,
mut timestamped_input: ResMut<TimestampedInputs>,
input_modes_captured: Res<InputModesCaptured>,
Expand Down
Loading

0 comments on commit c1779b5

Please sign in to comment.