- let c = Rc::new(Controller {id, ctrl, haptic: haptic.map(|h| Rc::new(RefCell::new(h)))});
- c.rumble(0.5, 300);
- self.controllers.push(c);
+ if self.controllers.contains_key(&id) {
+ return;
+ }
+
+ let detached = self.controllers.values().find(|c| !c.borrow().ctrl.attached());
+ match detached {
+ Some(c) => {
+ let mut c = c.borrow_mut();
+ c.ctrl = ctrl;
+ c.haptic = haptic.map(|h| Rc::new(RefCell::new(h)));
+ }
+ None => {
+ let c = Rc::new(RefCell::new(Controller {ctrl, haptic: haptic.map(|h| Rc::new(RefCell::new(h)))}));
+ self.controllers.insert(id, c);
+ }
+ };