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

Add Reflect and FromReflect to UserInput #331

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/axislike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
/// # Warning
///
/// `positive_low` must be greater than or equal to `negative_low` for this type to be validly constructed.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Reflect, FromReflect)]
pub struct SingleAxis {
/// The axis that is being checked.
pub axis_type: AxisType,
Expand Down Expand Up @@ -163,7 +163,7 @@ impl std::hash::Hash for SingleAxis {
/// # Warning
///
/// `positive_low` must be greater than or equal to `negative_low` for both `x` and `y` for this type to be validly constructed.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, Reflect, FromReflect)]
pub struct DualAxis {
/// The axis representing horizontal movement.
pub x: SingleAxis,
Expand Down Expand Up @@ -259,7 +259,7 @@ impl DualAxis {
/// even though it can be stored as an [`InputKind`].
///
/// Instead, use it directly as [`InputKind::DualAxis`]!
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, FromReflect)]
pub struct VirtualDPad {
/// The input that represents the up direction in this virtual DPad
pub up: InputKind,
Expand Down Expand Up @@ -347,7 +347,7 @@ impl VirtualDPad {
/// even though it can be stored as an [`InputKind`].
///
/// Instead, use it directly as [`InputKind::SingleAxis`]!
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, FromReflect)]
pub struct VirtualAxis {
/// The input that represents the negative direction of this virtual axis
pub negative: InputKind,
Expand Down Expand Up @@ -392,7 +392,7 @@ impl VirtualAxis {
/// The type of axis used by a [`UserInput`](crate::user_input::UserInput).
///
/// This is stored in either a [`SingleAxis`] or [`DualAxis`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, FromReflect)]
pub enum AxisType {
/// Input associated with a gamepad, such as the triggers or one axis of an analog stick.
Gamepad(GamepadAxisType),
Expand All @@ -405,7 +405,7 @@ pub enum AxisType {
/// The direction of motion of the mouse wheel.
///
/// Stored in the [`AxisType`] enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, FromReflect)]
pub enum MouseWheelAxisType {
/// Horizontal movement.
///
Expand All @@ -420,7 +420,7 @@ pub enum MouseWheelAxisType {
/// The direction of motion of the mouse.
///
/// Stored in the [`AxisType`] enum.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, FromReflect)]
pub enum MouseMotionAxisType {
/// Horizontal movement.
X,
Expand Down
4 changes: 2 additions & 2 deletions src/buttonlike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ButtonState {
/// A buttonlike-input triggered by [`MouseWheel`](bevy::input::mouse::MouseWheel) events
///
/// These will be considered pressed if non-zero net movement in the correct direction is detected.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, FromReflect)]
pub enum MouseWheelDirection {
/// Corresponds to `+y`
Up,
Expand All @@ -104,7 +104,7 @@ pub enum MouseWheelDirection {
/// A buttonlike-input triggered by [`MouseMotion`](bevy::input::mouse::MouseMotion) events
///
/// These will be considered pressed if non-zero net movement in the correct direction is detected.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Reflect, FromReflect)]
pub enum MouseMotionDirection {
/// Corresponds to `+y`
Up,
Expand Down
10 changes: 5 additions & 5 deletions src/clashing_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

use crate::action_state::ActionData;
use crate::axislike::{VirtualAxis, VirtualDPad};
use crate::input_chord::InputChord;
use crate::input_map::InputMap;
use crate::input_streams::InputStreams;
use crate::user_input::{InputKind, UserInput};
use crate::Actionlike;

use bevy::prelude::Resource;
use itertools::Itertools;
use petitset::PetitSet;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::marker::PhantomData;
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<A: Actionlike> Clash<A> {

// Does the `button` clash with the `chord`?
#[must_use]
fn button_chord_clash(button: &InputKind, chord: &PetitSet<InputKind, 8>) -> bool {
fn button_chord_clash(button: &InputKind, chord: &InputChord<8>) -> bool {
if chord.len() <= 1 {
return false;
}
Expand All @@ -213,7 +213,7 @@ fn button_chord_clash(button: &InputKind, chord: &PetitSet<InputKind, 8>) -> boo

// Does the `dpad` clash with the `chord`?
#[must_use]
fn dpad_chord_clash(dpad: &VirtualDPad, chord: &PetitSet<InputKind, 8>) -> bool {
fn dpad_chord_clash(dpad: &VirtualDPad, chord: &InputChord<8>) -> bool {
if chord.len() <= 1 {
return false;
}
Expand Down Expand Up @@ -266,7 +266,7 @@ fn virtual_axis_dpad_clash(axis: &VirtualAxis, dpad: &VirtualDPad) -> bool {
}

#[must_use]
fn virtual_axis_chord_clash(axis: &VirtualAxis, chord: &PetitSet<InputKind, 8>) -> bool {
fn virtual_axis_chord_clash(axis: &VirtualAxis, chord: &InputChord<8>) -> bool {
if chord.len() <= 1 {
return false;
}
Expand All @@ -284,7 +284,7 @@ fn virtual_axis_virtual_axis_clash(axis1: &VirtualAxis, axis2: &VirtualAxis) ->

/// Does the `chord_a` clash with `chord_b`?
#[must_use]
fn chord_chord_clash(chord_a: &PetitSet<InputKind, 8>, chord_b: &PetitSet<InputKind, 8>) -> bool {
fn chord_chord_clash(chord_a: &InputChord<8>, chord_b: &InputChord<8>) -> bool {
if chord_a.len() <= 1 || chord_b.len() <= 1 {
return false;
}
Expand Down
Loading