(&mut self, click_pos: Point2)
| 9 | |
| 10 | impl GameState { |
| 11 | pub fn button_click_system(&mut self, click_pos: Point2) { |
| 12 | if self.busy() { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | let mut animation = Vec::new(); |
| 17 | { |
| 18 | let compound_iterator = self |
| 19 | .positions |
| 20 | .iter() |
| 21 | .zip(self.buttons.iter_mut()) |
| 22 | .filter_map(|x| x.all()) |
| 23 | .filter(|&(_, ref b)| b.state == ButtonState::Active); |
| 24 | 'outer: for (p, b) in compound_iterator { |
| 25 | let dist = click_pos - p; |
| 26 | if dist.norm_squared() <= BUTTON_RADIUS_SQUARED { |
| 27 | b.state = ButtonState::Down; |
| 28 | let (target_stack, source_stacks) = b.stacks.unwrap(); |
| 29 | let t = self.ent_lookup[&target_stack]; |
| 30 | let target_pos = self.positions[t].unwrap(); |
| 31 | let mut sound_start = Sounds::Sweep; |
| 32 | for e in source_stacks.iter() { |
| 33 | let s = self.ent_lookup[&e]; |
| 34 | let stack = self.stacks[s].as_mut().unwrap(); |
| 35 | let pos = &self.positions[s].unwrap(); |
| 36 | |
| 37 | let start_pos = pos + stack.get_stackshift() * (stack.len() - 1) as f32; |
| 38 | stack.pop_card(); |
| 39 | |
| 40 | let ani = Animation { |
| 41 | target_pos, |
| 42 | target_stack: Some(target_stack), |
| 43 | start_delay: 0.0, |
| 44 | time_left: 0.3, |
| 45 | sound_start, |
| 46 | sound_stop: Sounds::None, |
| 47 | }; |
| 48 | animation.push((start_pos, ani)); |
| 49 | sound_start = Sounds::None; // play only one sound for all cards |
| 50 | } |
| 51 | break 'outer; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | for (start_pos, ani) in animation { |
| 56 | self.animate(Suite::FaceDown, start_pos, 100.0, ani); |
| 57 | self.dirty = true; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | pub fn begin_drag_system(&mut self, mouse_pos: Point2, res: &mut Resources) { |
| 62 | if self.busy() { |
no test coverage detected