generated from GarandPLG/rust-flake-template
Rename marking methods and use get_coords
Introduce push_marked_cell, pop_marked_cell and end_marking_cells to replace the previous set_marked_cell, undo_marked_cell and clear_marked_cells. Collapse get_row/get_col into get_coords and update all callers accordingly.
This commit is contained in:
@@ -83,10 +83,10 @@ pub fn skirmish_keybindings(app: &mut App, key_event: &KeyEvent) {
|
||||
ZoomLevel::ZoomedOut => {}
|
||||
},
|
||||
Action::Space => board.toggle_marking(),
|
||||
Action::Backspace => board.undo_marked_cell(),
|
||||
Action::Backspace => board.pop_marked_cell(),
|
||||
Action::Delete => {
|
||||
board.marked_cells.marking_cells = false;
|
||||
board.clear_marked_cells()
|
||||
board.end_marking_cells()
|
||||
}
|
||||
Action::Tab => {
|
||||
states.skirmish.side_panel = !states.skirmish.side_panel;
|
||||
|
||||
@@ -68,7 +68,8 @@ impl BoardState {
|
||||
let mut rows: Vec<CellWidget> = Vec::new();
|
||||
|
||||
for col in 0..map_width {
|
||||
let selected: bool = row == focused_cell.get_row() && col == focused_cell.get_col();
|
||||
let (focused_row, focused_col) = focused_cell.get_coords();
|
||||
let selected: bool = row == focused_row && col == focused_col;
|
||||
let player_base: bool = row == player_base_coords.0 && col == player_base_coords.1;
|
||||
let player_ore: bool =
|
||||
row == player_base_coords.0 && col == player_base_coords.1 - 1;
|
||||
@@ -154,11 +155,11 @@ impl BoardState {
|
||||
if self.marked_cells.marking_cells {
|
||||
self.start_marking_cells();
|
||||
} else {
|
||||
self.clear_marked_cells();
|
||||
self.end_marking_cells();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_marked_cell(&mut self, new_cell: (usize, usize)) {
|
||||
pub fn push_marked_cell(&mut self, new_cell: (usize, usize)) {
|
||||
let cell: &mut CellWidget = self.get_mut_cell(new_cell.0, new_cell.1);
|
||||
|
||||
if !cell.get_marked() {
|
||||
@@ -168,11 +169,9 @@ impl BoardState {
|
||||
self.marked_cells
|
||||
.marked_cells
|
||||
.push_back((new_cell.0, new_cell.1));
|
||||
|
||||
// info!("{:?}", self.marked_cells.marked_cells);
|
||||
}
|
||||
|
||||
pub fn undo_marked_cell(&mut self) {
|
||||
pub fn pop_marked_cell(&mut self) {
|
||||
if self.marked_cells.marked_cells.len() < 2 {
|
||||
return;
|
||||
}
|
||||
@@ -202,8 +201,7 @@ impl BoardState {
|
||||
}
|
||||
|
||||
pub fn start_marking_cells(&mut self) {
|
||||
let row: usize = self.focused_cell.get_row();
|
||||
let col: usize = self.focused_cell.get_col();
|
||||
let (row, col) = self.focused_cell.get_coords();
|
||||
|
||||
let cell: &mut CellWidget = self.get_mut_cell(row, col);
|
||||
cell.set_marked(true);
|
||||
@@ -212,7 +210,7 @@ impl BoardState {
|
||||
self.marked_cells.marked_cells.push_back((row, col));
|
||||
}
|
||||
|
||||
pub fn clear_marked_cells(&mut self) {
|
||||
pub fn end_marking_cells(&mut self) {
|
||||
for (row, col) in self.marked_cells.marked_cells.clone() {
|
||||
self.get_mut_cell(row, col).set_marked(false);
|
||||
}
|
||||
@@ -244,8 +242,7 @@ impl BoardState {
|
||||
let vertical_offset: usize = self.vertical_offset.get_value();
|
||||
let horizontal_offset: usize = self.horizontal_offset.get_value();
|
||||
|
||||
let row: usize = self.focused_cell.get_row();
|
||||
let col: usize = self.focused_cell.get_col();
|
||||
let (row, col) = self.focused_cell.get_coords();
|
||||
|
||||
if 0usize.saturating_add(vertical_offset) > row
|
||||
|| row >= self.rows.saturating_add(vertical_offset)
|
||||
@@ -293,12 +290,10 @@ impl BoardState {
|
||||
self.horizontal_offset =
|
||||
Offset::new(Some(self.horizontal_offset.get_value()), Some(h_max_offset));
|
||||
|
||||
self.focused_cell = FocusedCell::new(
|
||||
self.focused_cell.get_row(),
|
||||
self.focused_cell.get_col(),
|
||||
self.map_height,
|
||||
self.map_width,
|
||||
);
|
||||
let (focused_row, focused_coll) = self.focused_cell.get_coords();
|
||||
|
||||
self.focused_cell =
|
||||
FocusedCell::new(focused_row, focused_coll, self.map_height, self.map_width);
|
||||
|
||||
for row in 0..self.map_height {
|
||||
for col in 0..self.map_width {
|
||||
@@ -308,7 +303,7 @@ impl BoardState {
|
||||
}
|
||||
|
||||
pub fn change_focused_cell(&mut self, direction: MoveFocusedCell) {
|
||||
let old_cell: (usize, usize) = (self.focused_cell.get_row(), self.focused_cell.get_col());
|
||||
let old_cell: (usize, usize) = self.focused_cell.get_coords();
|
||||
let new_cell: (usize, usize) = self.focused_cell.move_focused_cell(direction);
|
||||
|
||||
self.get_mut_cell(old_cell.0, old_cell.1)
|
||||
@@ -316,7 +311,7 @@ impl BoardState {
|
||||
self.get_mut_cell(new_cell.0, new_cell.1).set_selected(true);
|
||||
|
||||
if self.marked_cells.marking_cells {
|
||||
self.set_marked_cell(new_cell);
|
||||
self.push_marked_cell(new_cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,8 @@ impl FocusedCell {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_row(&self) -> usize {
|
||||
self.row
|
||||
}
|
||||
|
||||
pub fn get_col(&self) -> usize {
|
||||
self.col
|
||||
pub fn get_coords(&self) -> (usize, usize) {
|
||||
(self.row, self.col)
|
||||
}
|
||||
|
||||
pub fn move_focused_cell(&mut self, direction: MoveFocusedCell) -> (usize, usize) {
|
||||
|
||||
@@ -130,8 +130,7 @@ pub fn skirmish_view(app: &App, area: Rect, buf: &mut Buffer) {
|
||||
BoardWidget::new(&board).render(cells_area, buf);
|
||||
|
||||
if states.skirmish.side_panel {
|
||||
let row: usize = board.get_focused_cell().get_row();
|
||||
let col: usize = board.get_focused_cell().get_col();
|
||||
let (row, col) = board.get_focused_cell().get_coords();
|
||||
let mut is_unit_marked: bool = false;
|
||||
|
||||
if let Some((first_row, first_col)) = board.marked_cells.marked_cells.get(0) {
|
||||
|
||||
Reference in New Issue
Block a user