Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Derive Reflect + FromReflect for input types #6232

Closed
wants to merge 16 commits into from

Conversation

TehPers
Copy link
Contributor

@TehPers TehPers commented Oct 11, 2022

Objective

Adds support for reflecting many more of the input types. This allows those types to be used via scripting, bevy-inspector-egui, etc. These types are registered by the InputPlugin so that they're automatically available to anyone who wants to use them

Closes #6223

Solution

Many types now have #[derive(Reflect, FromReflect)] added to them in bevy_input. Additionally, #[reflect(traits...)] has been added for applicable traits to the types.

This PR does not add reflection support for types which have private fields. Notably, Touch and Touches don't implement Reflect/FromReflect.

This adds the "glam" feature to the bevy_reflect dependency for package bevy_input. Since bevy_input transitively depends on glam already, all this brings in are the reflection impls.

Migration Guide

  • Input<T> now implements Reflect via #[reflect] instead of #[reflect_value]. This means it now exposes its private fields via the Reflect trait rather than being treated as a value type. For code that relies on the Input<T> struct being treated as a value type by reflection, it is still possible to wrap the Input<T> type with a wrapper struct and apply #[reflect_value] to it.
    • As a reminder, private fields exposed via reflection are not subject to any stability guarantees.

Changelog

Added

  • Implemented Reflect + FromReflect for many input-related types. These types are automatically registered when adding the InputPlugin.

@alice-i-cecile alice-i-cecile added A-Input Player input via keyboard, mouse, gamepad, and more A-Reflection Runtime information about types C-Usability A simple quality-of-life change that makes Bevy easier to use labels Oct 11, 2022
crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
crates/bevy_input/src/lib.rs Outdated Show resolved Hide resolved
TehPers and others added 5 commits October 10, 2022 20:21
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
We're already using types from `glam` so this only brings in the reflection impls.
@TehPers
Copy link
Contributor Author

TehPers commented Oct 11, 2022

Note: do not merge this yet. Currently, the #[reflect(...)] lists conflict with each other when the "serialize" feature is enabled. I left a comment about it in the Discord server, but basically only the last reflect list is used and the previous ones are discarded. We can mark this as a draft for the time being if anyone wants.

Edit: Created #6237 which should resolve this issue

Edit 2: #6237 was merged, so this is no longer blocked.

@alice-i-cecile alice-i-cecile added the S-Blocked This cannot more forward until something else changes label Oct 11, 2022
@MrGVSV MrGVSV removed the S-Blocked This cannot more forward until something else changes label Oct 19, 2022
crates/bevy_input/src/input.rs Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added the C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide label Oct 20, 2022
@MrGVSV
Copy link
Member

MrGVSV commented Oct 24, 2022

@TehPers Could you rebase this PR?

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 24, 2022
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Oct 26, 2022
# Objective

Adds support for reflecting many more of the input types. This allows those types to be used via scripting, `bevy-inspector-egui`, etc. These types are registered by the `InputPlugin` so that they're automatically available to anyone who wants to use them 

Closes #6223 

## Solution

Many types now have `#[derive(Reflect, FromReflect)]` added to them in `bevy_input`. Additionally, `#[reflect(traits...)]` has been added for applicable traits to the types.

This PR does not add reflection support for types which have private fields. Notably, `Touch` and `Touches` don't implement `Reflect`/`FromReflect`.

This adds the "glam" feature to the `bevy_reflect` dependency for package `bevy_input`. Since `bevy_input` transitively depends on `glam` already, all this brings in are the reflection `impl`s.

## Migration Guide

- `Input<T>` now implements `Reflect` via `#[reflect]` instead of `#[reflect_value]`. This means it now exposes its private fields via the `Reflect` trait rather than being treated as a value type. For code that relies on the `Input<T>` struct being treated as a value type by reflection, it is still possible to wrap the `Input<T>` type with a wrapper struct and apply `#[reflect_value]` to it.
  - As a reminder, private fields exposed via reflection are not subject to any stability guarantees.
---

## Changelog

Added
- Implemented `Reflect` + `FromReflect` for many input-related types. These types are automatically registered when adding the `InputPlugin`.
@bors bors bot changed the title Derive Reflect + FromReflect for input types [Merged by Bors] - Derive Reflect + FromReflect for input types Oct 26, 2022
@bors bors bot closed this Oct 26, 2022
@TehPers TehPers deleted the input-derive-reflect branch October 26, 2022 20:50
@mockersf mockersf added the hacktoberfest-accepted A PR that was accepted for Hacktoberfest, an annual open source event label Oct 27, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
# Objective

Adds support for reflecting many more of the input types. This allows those types to be used via scripting, `bevy-inspector-egui`, etc. These types are registered by the `InputPlugin` so that they're automatically available to anyone who wants to use them 

Closes bevyengine#6223 

## Solution

Many types now have `#[derive(Reflect, FromReflect)]` added to them in `bevy_input`. Additionally, `#[reflect(traits...)]` has been added for applicable traits to the types.

This PR does not add reflection support for types which have private fields. Notably, `Touch` and `Touches` don't implement `Reflect`/`FromReflect`.

This adds the "glam" feature to the `bevy_reflect` dependency for package `bevy_input`. Since `bevy_input` transitively depends on `glam` already, all this brings in are the reflection `impl`s.

## Migration Guide

- `Input<T>` now implements `Reflect` via `#[reflect]` instead of `#[reflect_value]`. This means it now exposes its private fields via the `Reflect` trait rather than being treated as a value type. For code that relies on the `Input<T>` struct being treated as a value type by reflection, it is still possible to wrap the `Input<T>` type with a wrapper struct and apply `#[reflect_value]` to it.
  - As a reminder, private fields exposed via reflection are not subject to any stability guarantees.
---

## Changelog

Added
- Implemented `Reflect` + `FromReflect` for many input-related types. These types are automatically registered when adding the `InputPlugin`.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

Adds support for reflecting many more of the input types. This allows those types to be used via scripting, `bevy-inspector-egui`, etc. These types are registered by the `InputPlugin` so that they're automatically available to anyone who wants to use them 

Closes bevyengine#6223 

## Solution

Many types now have `#[derive(Reflect, FromReflect)]` added to them in `bevy_input`. Additionally, `#[reflect(traits...)]` has been added for applicable traits to the types.

This PR does not add reflection support for types which have private fields. Notably, `Touch` and `Touches` don't implement `Reflect`/`FromReflect`.

This adds the "glam" feature to the `bevy_reflect` dependency for package `bevy_input`. Since `bevy_input` transitively depends on `glam` already, all this brings in are the reflection `impl`s.

## Migration Guide

- `Input<T>` now implements `Reflect` via `#[reflect]` instead of `#[reflect_value]`. This means it now exposes its private fields via the `Reflect` trait rather than being treated as a value type. For code that relies on the `Input<T>` struct being treated as a value type by reflection, it is still possible to wrap the `Input<T>` type with a wrapper struct and apply `#[reflect_value]` to it.
  - As a reminder, private fields exposed via reflection are not subject to any stability guarantees.
---

## Changelog

Added
- Implemented `Reflect` + `FromReflect` for many input-related types. These types are automatically registered when adding the `InputPlugin`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more A-Reflection Runtime information about types C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Usability A simple quality-of-life change that makes Bevy easier to use hacktoberfest-accepted A PR that was accepted for Hacktoberfest, an annual open source event S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add support for reflection to remaining input types
4 participants