fn mouse_cursor_movement(&mut self, c: &[f64; 2]) {
        self.mouse_cursor = *c;

        if let Some(grid_pos) = self.mouse_cursor_grid_position() {
            if self.game.is_state_placement() {
                let player = self.game.active_player();
                let ship_dir = player
                    .placement_ship()
                    .expect("failed to get player's placement ship")
                    .dir();
                // Subtract 1 from the ship count to not consider the placement ship itself.
                let ship_count = player.ships().len() - 1;
                let ship_len = self.game.settings().ships[ship_count];

                if let Some(ship) = player.get_ship_position(grid_pos, ship_dir, ship_len) {
                    // `set_pos()` will return an error if the position was invalid.
                    self.game
                        .set_placement_ship(ship)
                        .expect("tried to set placement ship to invalid position");
                }
            } else if self.game.is_state_active()
                && !self.game.active_player().is_cpu()
                && self.game.set_grid_cursor(&grid_pos).is_err()
            {
                // TODO: might be good to have some visual effect.
            }
        }
    }
/// Records the last known mouse cursor position.
Records the last known mouse cursor position.
Records the last known mouse cursor position .
fn mouse_cursor_movement(&mut self, c: &[f64; 2]) {
        self.mouse_cursor = *c;
        if let Some(grid_pos) = self.mouse_cursor_grid_position() {
            if self.game.is_state_placement() {
                let player = self.game.active_player();
                let ship_dir = player
                    .placement_ship()
                    .expect("failed to get player's placement ship")
                    .dir();
                // Subtract 1 from the ship count to not consider the placement ship itself.
                let ship_count = player.ships().len() - 1;
                let ship_len = self.game.settings().ships[ship_count];
                if let Some(ship) = player.get_ship_position(grid_pos, ship_dir, ship_len) {
                    // `set_pos()` will return an error if the position was invalid.
                    self.game
                        .set_placement_ship(ship)
                        .expect("tried to set placement ship to invalid position");
                }
            } else if self.game.is_state_active()
                && !self.game.active_player().is_cpu()
                && self.game.set_grid_cursor(&grid_pos).is_err()
            {
                // TODO: might be good to have some visual effect.
            }
        }
    }
fn mouse_cursor_movement ( & mut self , c : & [ f64 ; 2 ] ) { self . mouse_cursor = * c ; if let Some ( grid_pos ) = self . mouse_cursor_grid_position ( ) { if self . game . is_state_placement ( ) { let player = self . game . active_player ( ) ; let ship_dir = player . placement_ship ( ) . expect ( " " ) . dir ( ) ; // Subtract 1 from the ship count to not consider the placement ship itself. let ship_count = player . ships ( ) . len ( ) - 1 ; let ship_len = self . game . settings ( ) . ships [ ship_count ] ; if let Some ( ship ) = player . get_ship_position ( grid_pos , ship_dir , ship_len ) { // `set_pos()` will return an error if the position was invalid. self . game . set_placement_ship ( ship ) . expect ( " " ) ; } } else if self . game . is_state_active ( ) && ! self . game . active_player ( ) . is_cpu ( ) && self . game . set_grid_cursor ( & grid_pos ) . is_err ( ) { // TODO: might be good to have some visual effect. } } }
Records the last known mouse cursor position.
Records the last known mouse cursor position .
&mut self
c
&[f64; 2]
&mut self
c
&[f64; 2]