generated from GarandPLG/rust-flake-template
Add BaseBuilding and MinerUnit with UI rendering
This commit is contained in:
@@ -3,4 +3,29 @@ use crate::app::states::Players;
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct BaseBuilding {
|
pub struct BaseBuilding {
|
||||||
owner: Players,
|
owner: Players,
|
||||||
|
level: u8,
|
||||||
|
tag: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BaseBuilding {
|
||||||
|
pub fn new(owner: Players) -> Self {
|
||||||
|
Self {
|
||||||
|
owner,
|
||||||
|
level: 1,
|
||||||
|
tag: "B",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_tag(&self) -> &'static str {
|
||||||
|
self.tag
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_level(&self) -> &'static str {
|
||||||
|
match self.level {
|
||||||
|
1 => "1",
|
||||||
|
2 => "2",
|
||||||
|
3 => "3",
|
||||||
|
_ => " ",
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
|
use crate::app::buildings::BaseBuilding;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Buildings {}
|
pub enum Buildings {
|
||||||
|
Base(BaseBuilding),
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod base;
|
pub mod base;
|
||||||
pub mod building;
|
pub mod building;
|
||||||
|
|
||||||
|
pub use base::BaseBuilding;
|
||||||
pub use building::Buildings;
|
pub use building::Buildings;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use crate::app::{
|
use crate::app::{
|
||||||
|
buildings::{BaseBuilding, Buildings},
|
||||||
helpers::{CellSizes, cell_size_helper, cells_area_helper},
|
helpers::{CellSizes, cell_size_helper, cells_area_helper},
|
||||||
states::{CellTag, FocusedCell, Offset, Players, ZoomLevel, skirmish_states::MoveFocusedCell},
|
states::{CellTag, FocusedCell, Offset, Players, ZoomLevel, skirmish_states::MoveFocusedCell},
|
||||||
|
units::{MinerUnit, Units},
|
||||||
widgets::CellWidget,
|
widgets::CellWidget,
|
||||||
};
|
};
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
@@ -68,8 +70,24 @@ impl BoardState {
|
|||||||
CellTag::Stone
|
CellTag::Stone
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let unit: Option<Units> = if player_base {
|
||||||
|
Some(Units::Miner(MinerUnit::new(Players::Player)))
|
||||||
|
} else if enemy_base {
|
||||||
|
Some(Units::Miner(MinerUnit::new(Players::Enemy)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let building: Option<Buildings> = if player_base {
|
||||||
|
Some(Buildings::Base(BaseBuilding::new(Players::Player)))
|
||||||
|
} else if enemy_base {
|
||||||
|
Some(Buildings::Base(BaseBuilding::new(Players::Enemy)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
rows.push(CellWidget::new(
|
rows.push(CellWidget::new(
|
||||||
row, col, zoom_level, selected, tag, None, None,
|
row, col, zoom_level, selected, tag, unit, building,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
use crate::app::states::Players;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct MinerUnit {
|
||||||
|
owner: Players,
|
||||||
|
tag: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MinerUnit {
|
||||||
|
pub fn new(owner: Players) -> Self {
|
||||||
|
Self { owner, tag: "M" }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_tag(self) -> &'static str {
|
||||||
|
self.tag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod miner;
|
pub mod miner;
|
||||||
pub mod unit;
|
pub mod unit;
|
||||||
|
|
||||||
|
pub use miner::MinerUnit;
|
||||||
pub use unit::Units;
|
pub use unit::Units;
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
|
use crate::app::units::MinerUnit;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Units {}
|
pub enum Units {
|
||||||
|
Miner(MinerUnit),
|
||||||
|
}
|
||||||
|
|||||||
+30
-9
@@ -100,27 +100,48 @@ impl CellWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_text_area(&self) -> Vec<Line<'_>> {
|
fn get_text_area(&self) -> Vec<Line<'_>> {
|
||||||
let tag: &str = match self.tag {
|
let tag: &str = match self.building {
|
||||||
CellTag::Base(_) => "B",
|
Some(building) => match building {
|
||||||
CellTag::Tunel => "T",
|
Buildings::Base(base) => base.get_tag(),
|
||||||
CellTag::Stone => " ",
|
// _ => " ",
|
||||||
|
},
|
||||||
|
None => match self.tag {
|
||||||
|
CellTag::Tunel => "T",
|
||||||
|
CellTag::Stone => " ",
|
||||||
|
_ => " ",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let b_level: &str = match self.building {
|
||||||
|
Some(building) => match building {
|
||||||
|
Buildings::Base(base) => base.get_level(),
|
||||||
|
// _ => " ",
|
||||||
|
},
|
||||||
|
None => " ",
|
||||||
|
};
|
||||||
|
|
||||||
|
let unit: &str = match self.unit {
|
||||||
|
Some(unit) => match unit {
|
||||||
|
Units::Miner(miner) => miner.get_tag(),
|
||||||
|
// _ => " ",
|
||||||
|
},
|
||||||
|
None => " ",
|
||||||
};
|
};
|
||||||
let units: &str = " "; // TODO: units count on that cell
|
|
||||||
|
|
||||||
let mut text_area: Vec<Line<'_>> = Vec::new();
|
let mut text_area: Vec<Line<'_>> = Vec::new();
|
||||||
|
|
||||||
match self.zoom_level {
|
match self.zoom_level {
|
||||||
ZoomLevel::ZoomedIn => {
|
ZoomLevel::ZoomedIn => {
|
||||||
text_area.push(Line::from(format!(" {}", units)));
|
text_area.push(Line::from(format!(" {} ", unit)));
|
||||||
text_area.push(Line::from(format!(" ")));
|
text_area.push(Line::from(format!(" ")));
|
||||||
text_area.push(Line::from(format!(" {} ", tag)));
|
text_area.push(Line::from(format!(" {} ", tag)));
|
||||||
text_area.push(Line::from(format!(" ")));
|
text_area.push(Line::from(format!(" ")));
|
||||||
text_area.push(Line::from(format!(" ")));
|
text_area.push(Line::from(format!(" {} ", b_level)));
|
||||||
}
|
}
|
||||||
ZoomLevel::Default => {
|
ZoomLevel::Default => {
|
||||||
text_area.push(Line::from(format!(" {}", units)));
|
text_area.push(Line::from(format!(" {} ", unit)));
|
||||||
text_area.push(Line::from(format!(" {} ", tag)));
|
text_area.push(Line::from(format!(" {} ", tag)));
|
||||||
text_area.push(Line::from(format!(" ")));
|
text_area.push(Line::from(format!(" {} ", b_level)));
|
||||||
}
|
}
|
||||||
ZoomLevel::ZoomedOut => {
|
ZoomLevel::ZoomedOut => {
|
||||||
text_area.push(Line::from(format!(" {} ", tag)));
|
text_area.push(Line::from(format!(" {} ", tag)));
|
||||||
|
|||||||
Reference in New Issue
Block a user