Skip to content

Commit

Permalink
Implement Reflect for InputMap
Browse files Browse the repository at this point in the history
Closes #386.
  • Loading branch information
alice-i-cecile committed Oct 26, 2023
1 parent 9f3aefa commit 0465920
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/dynamic_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
use std::any::TypeId;
use std::hash::Hash;

use bevy::reflect::TypePath;
use bevy::reflect::Reflect;
use bevy::{
prelude::{App, Resource},
utils::HashMap,
Expand All @@ -60,7 +60,7 @@ static DYN_ACTION_MAP: OnceCell<HashMap<TypeId, usize>> = OnceCell::new();
static REGISTRY_CREATED: OnceCell<()> = OnceCell::new();

/// The runtime representation of actions declared via marker types
#[derive(Copy, Clone, PartialEq, Eq, Hash, TypePath)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Reflect)]
pub struct DynAction(usize);

/// Coordinates the registration of dynamic action types
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::action_state::ActionState;
use crate::input_map::InputMap;
use bevy::ecs::prelude::*;
use bevy::reflect::TypePath;
use bevy::reflect::Reflect;
use std::hash::Hash;
use std::marker::PhantomData;

Expand Down Expand Up @@ -81,7 +81,7 @@ pub mod prelude {
/// Ultimate,
/// }
/// ```
pub trait Actionlike: Eq + Hash + Send + Sync + Clone + Hash + TypePath + 'static {
pub trait Actionlike: Eq + Hash + Send + Sync + Clone + Hash + Reflect + 'static {
/// The number of variants of this action type
fn n_variants() -> usize;

Expand Down
3 changes: 2 additions & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bevy::app::{App, Plugin};
use bevy::ecs::prelude::*;
use bevy::input::InputSystem;
use bevy::prelude::{PostUpdate, PreUpdate};
use bevy::reflect::TypePath;
#[cfg(feature = "ui")]
use bevy::ui::UiSystem;

Expand Down Expand Up @@ -79,7 +80,7 @@ enum Machine {
Client,
}

impl<A: Actionlike> Plugin for InputManagerPlugin<A> {
impl<A: Actionlike + TypePath> Plugin for InputManagerPlugin<A> {
fn build(&self, app: &mut App) {
use crate::systems::*;

Expand Down

0 comments on commit 0465920

Please sign in to comment.