generated from GarandPLG/rust-flake-template
Move skirmish Offset and FocusedCell to own module
Extract Offset and FocusedCell structs from skirmish.rs into a new skirmish_states module. Re-export the structs from the top-level states module and adjust imports in skirmish.rs.
This commit is contained in:
@@ -3,9 +3,11 @@ pub mod perk_decks;
|
||||
pub mod settings;
|
||||
pub mod skills_config;
|
||||
pub mod skirmish;
|
||||
pub mod skirmish_states;
|
||||
|
||||
pub use main_menu::MainMenuState;
|
||||
pub use perk_decks::{PerkDecks, PerkDecksState};
|
||||
pub use settings::SettingsState;
|
||||
pub use skills_config::SkillsConfigState;
|
||||
pub use skirmish::{FocusedCell, GameMode, Offset, SkirmishState, ZoomLevel};
|
||||
pub use skirmish::{GameMode, SkirmishState, ZoomLevel};
|
||||
pub use skirmish_states::{FocusedCell, Offset};
|
||||
|
||||
@@ -1,90 +1,9 @@
|
||||
use crate::app::widgets::CellWidget;
|
||||
use crate::app::{
|
||||
states::{FocusedCell, Offset},
|
||||
widgets::CellWidget,
|
||||
};
|
||||
use clap::ValueEnum;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Offset {
|
||||
value: usize,
|
||||
max: usize,
|
||||
value_initiated: bool,
|
||||
max_initiated: bool,
|
||||
}
|
||||
|
||||
impl Offset {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
value: 0,
|
||||
max: 0,
|
||||
value_initiated: false,
|
||||
max_initiated: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_value(&self) -> usize {
|
||||
self.value
|
||||
}
|
||||
|
||||
pub fn set_initial_value(&mut self, value: usize) {
|
||||
if self.value_initiated {
|
||||
return;
|
||||
}
|
||||
|
||||
self.value = value;
|
||||
self.value_initiated = true;
|
||||
}
|
||||
|
||||
pub fn set_max(&mut self, max: usize) {
|
||||
// if self.max_initiated {
|
||||
// return;
|
||||
// }
|
||||
|
||||
self.max = max;
|
||||
self.max_initiated = true;
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
self.value = self.value.saturating_add(1).min(self.max);
|
||||
}
|
||||
|
||||
pub fn prev(&mut self) {
|
||||
self.value = self.value.saturating_sub(1).max(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct FocusedCell {
|
||||
pub row: usize,
|
||||
pub col: usize,
|
||||
pub max_row: usize,
|
||||
pub max_col: usize,
|
||||
}
|
||||
|
||||
impl FocusedCell {
|
||||
pub fn new(row: usize, col: usize, max_row: usize, max_col: usize) -> Self {
|
||||
Self {
|
||||
row,
|
||||
col,
|
||||
max_row,
|
||||
max_col,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_up(&mut self) {
|
||||
self.row = self.row.saturating_sub(1).max(0);
|
||||
}
|
||||
|
||||
pub fn move_down(&mut self) {
|
||||
self.row = self.row.saturating_add(1).min(self.max_row - 1);
|
||||
}
|
||||
|
||||
pub fn move_left(&mut self) {
|
||||
self.col = self.col.saturating_sub(1).max(0);
|
||||
}
|
||||
|
||||
pub fn move_right(&mut self) {
|
||||
self.col = self.col.saturating_add(1).min(self.max_col - 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SkirmishState {
|
||||
pub id: usize,
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct FocusedCell {
|
||||
pub row: usize,
|
||||
pub col: usize,
|
||||
pub max_row: usize,
|
||||
pub max_col: usize,
|
||||
}
|
||||
|
||||
impl FocusedCell {
|
||||
pub fn new(row: usize, col: usize, max_row: usize, max_col: usize) -> Self {
|
||||
Self {
|
||||
row,
|
||||
col,
|
||||
max_row,
|
||||
max_col,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_up(&mut self) {
|
||||
self.row = self.row.saturating_sub(1).max(0);
|
||||
}
|
||||
|
||||
pub fn move_down(&mut self) {
|
||||
self.row = self.row.saturating_add(1).min(self.max_row - 1);
|
||||
}
|
||||
|
||||
pub fn move_left(&mut self) {
|
||||
self.col = self.col.saturating_sub(1).max(0);
|
||||
}
|
||||
|
||||
pub fn move_right(&mut self) {
|
||||
self.col = self.col.saturating_add(1).min(self.max_col - 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
pub mod focused_cell;
|
||||
pub mod offset;
|
||||
|
||||
pub use focused_cell::FocusedCell;
|
||||
pub use offset::Offset;
|
||||
@@ -0,0 +1,48 @@
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Offset {
|
||||
value: usize,
|
||||
max: usize,
|
||||
value_initiated: bool,
|
||||
max_initiated: bool,
|
||||
}
|
||||
|
||||
impl Offset {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
value: 0,
|
||||
max: 0,
|
||||
value_initiated: false,
|
||||
max_initiated: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_value(&self) -> usize {
|
||||
self.value
|
||||
}
|
||||
|
||||
pub fn set_initial_value(&mut self, value: usize) {
|
||||
if self.value_initiated {
|
||||
return;
|
||||
}
|
||||
|
||||
self.value = value;
|
||||
self.value_initiated = true;
|
||||
}
|
||||
|
||||
pub fn set_max(&mut self, max: usize) {
|
||||
if self.max_initiated {
|
||||
return;
|
||||
}
|
||||
|
||||
self.max = max;
|
||||
self.max_initiated = true;
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
self.value = self.value.saturating_add(1).min(self.max);
|
||||
}
|
||||
|
||||
pub fn prev(&mut self) {
|
||||
self.value = self.value.saturating_sub(1).max(0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user