generated from GarandPLG/rust-flake-template
Add Building and Unit structs, extend CellWidget
Introduce empty Building and Unit types and expose them through new modules. Extend CellWidget to store optional Unit and Building, update its constructor, and adjust board rendering to create cells with these new fields (currently always None).
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Building {}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod building;
|
||||
|
||||
pub use building::Building;
|
||||
@@ -1,10 +1,12 @@
|
||||
pub mod app;
|
||||
pub mod buildings;
|
||||
pub mod helpers;
|
||||
pub mod keybind;
|
||||
pub mod keybindings;
|
||||
pub mod state;
|
||||
pub mod states;
|
||||
pub mod threads;
|
||||
pub mod units;
|
||||
pub mod view;
|
||||
pub mod views;
|
||||
pub mod widgets;
|
||||
|
||||
@@ -57,16 +57,20 @@ impl BoardState {
|
||||
|
||||
for col in 0..map_width {
|
||||
let selected: bool = row == focused_cell.get_row() && col == focused_cell.get_col();
|
||||
let player_base: bool = row == player_base_coords.0 && col == player_base_coords.1;
|
||||
let enemy_base: bool = row == enemy_base_coords.0 && col == enemy_base_coords.1;
|
||||
|
||||
let tag: CellTag = if row == player_base_coords.0 && col == player_base_coords.1 {
|
||||
let tag: CellTag = if player_base {
|
||||
CellTag::Base(Players::Player)
|
||||
} else if row == enemy_base_coords.0 && col == enemy_base_coords.1 {
|
||||
} else if enemy_base {
|
||||
CellTag::Base(Players::Enemy)
|
||||
} else {
|
||||
CellTag::Stone
|
||||
};
|
||||
|
||||
rows.push(CellWidget::new(row, col, zoom_level, selected, tag));
|
||||
rows.push(CellWidget::new(
|
||||
row, col, zoom_level, selected, tag, None, None,
|
||||
));
|
||||
}
|
||||
|
||||
cells.push(rows);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod unit;
|
||||
|
||||
pub use unit::Unit;
|
||||
@@ -0,0 +1,2 @@
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Unit {}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::ZoomLevel;
|
||||
use crate::app::{buildings::Building, states::ZoomLevel, units::Unit};
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Alignment, Rect},
|
||||
@@ -28,6 +28,8 @@ pub struct CellWidget {
|
||||
zoom_level: ZoomLevel,
|
||||
tag: CellTag,
|
||||
marked: bool,
|
||||
unit: Option<Unit>,
|
||||
building: Option<Building>,
|
||||
}
|
||||
|
||||
impl CellWidget {
|
||||
@@ -37,6 +39,8 @@ impl CellWidget {
|
||||
zoom_level: ZoomLevel,
|
||||
selected: bool,
|
||||
tag: CellTag,
|
||||
unit: Option<Unit>,
|
||||
building: Option<Building>,
|
||||
) -> Self {
|
||||
Self {
|
||||
row,
|
||||
@@ -45,6 +49,8 @@ impl CellWidget {
|
||||
zoom_level,
|
||||
tag,
|
||||
marked: false,
|
||||
unit,
|
||||
building,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user