feat: Derive traits

This commit is contained in:
Alexey 2026-03-19 15:57:29 +03:00
commit ffdb5d94a8
11 changed files with 115 additions and 79 deletions

View file

@ -1,13 +1,14 @@
use bevy::prelude::*;
use leafwing_input_manager::prelude::*;
use serde::{
Deserialize,
Serialize,
Deserialize
};
pub mod plugin;
#[derive(Actionlike, PartialEq, Eq, Hash, Debug, Clone, Reflect, Serialize, Deserialize)]
#[reflect(PartialEq, Hash, Debug, Clone, Serialize, Deserialize)]
pub enum InputAction {
#[actionlike(Axis)]
Move,
@ -28,6 +29,7 @@ impl InputAction {
}
#[derive(Actionlike, PartialEq, Eq, Hash, Debug, Clone, Reflect, Serialize, Deserialize)]
#[reflect(PartialEq, Hash, Debug, Clone, Serialize, Deserialize)]
pub enum UiAction {
Rotate,
}

View file

@ -10,7 +10,7 @@ use std::{
use bevy::{
prelude::*,
reflect::GetTypeRegistration,
reflect::Reflectable,
};
use bevy_common_assets::toml::TomlAssetPlugin;
use leafwing_input_manager::{
@ -229,16 +229,16 @@ impl<Name> From<InputMap<Name>> for InputAsset<Name>
#[derive(Resource, Debug, Deref, DerefMut, Reflect, Clone, PartialEq, Eq)]
#[reflect(Resource, Debug, Clone, PartialEq)]
pub struct InputAssetHandle<T: Sized + Hash + Eq + Reflect + TypePath + Actionlike> (Option<Handle<InputAsset<T>>>);
pub struct InputAssetHandle<T: Sized + Hash + Eq + Reflectable + Actionlike> (Option<Handle<InputAsset<T>>>);
#[derive(Debug)]
pub struct InputAssetPlugin<T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned> {
pub struct InputAssetPlugin<T: Sized + Hash + Eq + Reflectable + Actionlike + DeserializeOwned> {
_phantom: PhantomData<T>,
extensions: &'static [&'static str],
}
impl<T> InputAssetPlugin<T>
where T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned {
where T: Sized + Hash + Eq + Reflectable + Actionlike + DeserializeOwned {
pub fn new(extensions: &'static [&'static str]) -> Self {
Self {
_phantom: PhantomData,
@ -248,7 +248,7 @@ impl<T> InputAssetPlugin<T>
}
impl<T> Default for InputAssetPlugin<T>
where T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned {
where T: Sized + Hash + Eq + Reflectable + Actionlike + DeserializeOwned {
fn default() -> Self {
Self {
_phantom: PhantomData,
@ -258,7 +258,7 @@ impl<T> Default for InputAssetPlugin<T>
}
impl<T> Plugin for InputAssetPlugin<T>
where T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned + GetTypeRegistration {
where T: Sized + Hash + Eq + Reflectable + Actionlike + DeserializeOwned {
fn build(&self, app: &mut App) {
app.add_plugins((
InputManagerPlugin::<T>::default(),