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
34
35
36
37
38
39
40
41
use std::{cell::RefCell, rc::Rc};
use super::entity_mutator::EntityMutator;
#[derive(Clone)]
pub struct Property<T: Clone> {
mutator: Option<Rc<RefCell<dyn EntityMutator>>>,
mutator_index: u8,
pub(crate) inner: T,
}
impl<T: Clone> Property<T> {
pub fn new(value: T, index: u8) -> Property<T> {
return Property::<T> {
inner: value,
mutator_index: index,
mutator: None,
};
}
pub fn get(&self) -> &T {
return &self.inner;
}
pub fn set(&mut self, value: T) {
self.inner = value;
if let Some(mutator) = &self.mutator {
mutator.as_ref().borrow_mut().mutate(self.mutator_index);
}
}
pub fn set_mutator(&mut self, mutator: &Rc<RefCell<dyn EntityMutator>>) {
self.mutator = Some(mutator.clone());
}
}