1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::engine::d2::util::Value;
use super::Behavior;
pub type BindingFunction = Box<dyn Fn(f32) -> f32>;
pub struct Binding {
target: Value<f32>,
func: Option<BindingFunction>,
}
impl Binding {
pub fn new(target: Value<f32>, func: Option<BindingFunction>) -> Self {
Self { target, func }
}
}
impl Behavior for Binding {
fn update(&self, dt: f32) -> f32 {
let value = self.target.get();
if let Some(ref func) = self.func {
func(*value)
} else {
*value
}
}
fn is_complete(&self) -> bool {
false
}
}