diff --git a/rust/cli_player/src/ui_screens/set_boats_layout.rs b/rust/cli_player/src/ui_screens/set_boats_layout.rs index 0af6f41..3a88691 100644 --- a/rust/cli_player/src/ui_screens/set_boats_layout.rs +++ b/rust/cli_player/src/ui_screens/set_boats_layout.rs @@ -44,20 +44,50 @@ pub fn set_boat_layout( .unwrap_or_else(|| Duration::from_secs(0)); if event::poll(timeout)? { + let mut move_boat = None; + let event = event::read()?; if let Event::Key(key) = &event { match key.code { KeyCode::Char('q') => return Ok(ScreenResult::Canceled), + + // Select next boat + KeyCode::Char('n') => model.curr_boat += model.layout.number_of_boats() - 1, + + // Rotate boat + KeyCode::Char('r') => { + model.layout.0[model.curr_boat].direction = + match model.layout.0[model.curr_boat].direction { + BoatDirection::Right => BoatDirection::Down, + _ => BoatDirection::Right, + } + } + + // Move boat + KeyCode::Left => move_boat = Some((-1, 0)), + KeyCode::Right => move_boat = Some((1, 0)), + KeyCode::Up => move_boat = Some((0, -1)), + KeyCode::Down => move_boat = Some((0, 1)), + + // Submit configuration KeyCode::Enter => { if model.layout.is_valid(rules) { return Ok(ScreenResult::Ok(model.layout)); } } - KeyCode::Char('n') => model.curr_boat += model.layout.number_of_boats() - 1, + _ => {} } model.curr_boat %= model.layout.number_of_boats(); + + // Apply boat move + if let Some((x, y)) = move_boat { + let new_pos = model.layout.0[model.curr_boat].start.add_x(x).add_y(y); + if new_pos.is_valid(rules) { + model.layout.0[model.curr_boat].start = new_pos; + } + } } // Mouse event else if let Event::Mouse(mouse) = event { @@ -87,6 +117,7 @@ pub fn set_boat_layout( } } } + if last_tick.elapsed() >= TICK_RATE { last_tick = Instant::now(); }