feat: Player is now using leafwing-input-manager

This commit is contained in:
Alexey 2026-03-03 16:49:28 +03:00
commit 957717671a
4 changed files with 68 additions and 24 deletions

View file

@ -1,8 +1,8 @@
use std::{any::{Any, TypeId}, collections::HashMap, hash::Hash, marker::PhantomData};
use bevy::prelude::*;
use bevy::{prelude::*, reflect::GetTypeRegistration};
use bevy_common_assets::toml::TomlAssetPlugin;
use leafwing_input_manager::{Actionlike, prelude::{Axislike, Buttonlike, DualAxislike, InputMap}};
use leafwing_input_manager::{Actionlike, plugin::InputManagerPlugin, prelude::*};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
const INPUT_ASSET_EXTENSIONS: [&'static str; 1] = ["input.toml"];
@ -205,13 +205,42 @@ impl<Name> From<InputMap<Name>> for InputAsset<Name>
}
}
#[derive(Debug, Default)]
pub struct InputAssetPlugin<T> (PhantomData<T>);
#[derive(Resource, Deref)]
pub struct InputAssetHandle<T: Sized + Hash + Eq + Reflect + TypePath + Actionlike> (Option<Handle<InputAsset<T>>>);
impl<T> Plugin for InputAssetPlugin<T>
where T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned
{
fn build(&self, app: &mut App) {
app.add_plugins(TomlAssetPlugin::<InputAsset<T>>::new(&INPUT_ASSET_EXTENSIONS));
#[derive(Debug)]
pub struct InputAssetPlugin<T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned + GetTypeRegistration> {
_phantom: PhantomData<T>,
extensions: &'static [&'static str],
}
impl<T> InputAssetPlugin<T>
where T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned + GetTypeRegistration {
pub fn new(extensions: &'static [&'static str]) -> Self {
Self {
_phantom: PhantomData,
extensions,
}
}
}
impl<T> Default for InputAssetPlugin<T>
where T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned + GetTypeRegistration {
fn default() -> Self {
Self {
_phantom: PhantomData,
extensions: &INPUT_ASSET_EXTENSIONS,
}
}
}
impl<T> Plugin for InputAssetPlugin<T>
where T: Sized + Hash + Eq + Reflect + TypePath + Actionlike + DeserializeOwned + GetTypeRegistration
{
fn build(&self, app: &mut App) {
app.add_plugins((
TomlAssetPlugin::<InputAsset<T>>::new(&self.extensions),
InputManagerPlugin::<T>::default()
));
}
}