trait ActionLike {
fn get_bindings(&self) -> &[ActionBindingDescription];
fn get_inputs(&self) -> &[TriggerMapping];
}
#[derive(Clone)]
pub struct Action {
pub(crate) name: &'static str,
pub(crate) bindings: SmallVec<[ActionBindingDescription; 8]>,
pub(crate) inputs: SmallVec<[TriggerMapping; 8]>,
pub(crate) r#type: Types,
pub(crate) tick_policy: TickPolicy,
}
impl ActionLike for Action {
fn get_bindings(&self) -> &[ActionBindingDescription] {
&self.bindings
}
fn get_inputs(&self) -> &[TriggerMapping] {
&self.inputs
}
}
pub trait InputValue: Default + Clone + Copy + 'static {
fn get_type() -> Types;
}
impl InputValue for bool {
fn get_type() -> Types {
Types::Boolean
}
}
impl InputValue for i32 {
fn get_type() -> Types {
Types::Int
}
}
impl InputValue for char {
fn get_type() -> Types {
Types::Unicode
}
}
impl InputValue for f32 {
fn get_type() -> Types {
Types::Float
}
}
impl InputValue for Vector2 {
fn get_type() -> Types {
Types::Vector2
}
}
impl InputValue for Vector3 {
fn get_type() -> Types {
Types::Vector3
}
}
impl InputValue for Quaternion {
fn get_type() -> Types {
Types::Quaternion
}
}
impl InputValue for RGBA {
fn get_type() -> Types {
Types::Rgba
}
}
impl Action {
pub fn new(name: &'static str, bindings: &[ActionBindingDescription], r#type: Types) -> Action {
Action {
name,
bindings: bindings.into(),
inputs: SmallVec::new(),
r#type,
tick_policy: TickPolicy::default(),
}
}
pub fn tick_policy(mut self, tick_policy: TickPolicy) -> Self {
self.tick_policy = tick_policy;
self
}
}
#[derive(Copy, Clone, Debug)]
pub struct ActionBindingDescription {
pub(crate) input_source: TriggerReference,
pub(crate) mapping: ValueMapping,
}
impl ActionBindingDescription {
pub fn new(input_source: &'static str) -> Self {
ActionBindingDescription {
input_source: TriggerReference::Name(input_source),
mapping: false.into(),
}
}
pub fn mapped(mut self, mapping: ValueMapping) -> Self {
self.mapping = mapping;
self
}
}
#[derive(Copy, Clone, Debug)]
pub struct TriggerMapping {
pub(crate) trigger_handle: TriggerHandle,
pub(crate) mapping: Value,
pub(crate) function: Option<Function>,
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct ActionHandle(pub(super) u32);
use math::{Quaternion, Vector2, Vector3};
use smallvec::SmallVec;
use utils::RGBA;
use super::TriggerHandle;
use super::{input_manager::TriggerReference, Function, TickPolicy, Types, Value};
use crate::core::{Entity, EntityHandle};
use crate::input::ValueMapping;