use crate::app::states::skirmish_states::{Players, tasks::Tasks}; use ratatui::{ style::{Color, Stylize}, text::{Line, Span}, }; use std::collections::VecDeque; pub trait Unit { fn is_unit(&self) -> bool { true } fn get_owner(&self) -> Players; fn get_tag(&self) -> char; fn get_name(&self) -> &'static str; fn get_hp(&self) -> u16; fn get_max_hp(&self) -> u16; fn get_can_dig(&self) -> bool; fn get_can_build(&self) -> bool { false } fn get_digging_power(&self) -> f32; fn get_coords(&self) -> (usize, usize); fn set_coords(&mut self, coords: (usize, usize)); fn get_ref_tasks(&self) -> &VecDeque; fn get_mut_tasks(&mut self) -> &mut VecDeque; fn set_task(&mut self, task: Tasks); fn get_tasks_formatted(&self) -> Vec>; fn base_text(&self) -> Vec> { let owner: Span<'_> = self.get_owner().get_span(); let hp: u16 = self.get_hp(); let max_hp: u16 = self.get_max_hp(); let hp_percent: u16 = hp * 100 / max_hp; let can_dig: bool = self.get_can_dig(); let digging_power: f32 = self.get_digging_power(); let have_any_tasks: bool = self.get_ref_tasks().is_empty(); let tasks: Vec> = self.get_tasks_formatted(); let mut lines: Vec> = Vec::from([ Line::from_iter(["Owner: ".fg(Color::Rgb(192, 192, 192)), owner]), Line::from_iter([ "HP: ".fg(Color::Rgb(192, 192, 192)), hp.fg(Color::Rgb(0, 128, 0)), "/".fg(Color::Rgb(192, 192, 192)), max_hp.fg(Color::Rgb(0, 128, 0)), " ( ".fg(Color::Rgb(192, 192, 192)), hp_percent.fg(Color::Rgb(0, 128, 0)), "% )".fg(Color::Rgb(192, 192, 192)), ]), ]); if can_dig { lines.push(Line::from_iter([ "Digging power: ".fg(Color::Rgb(192, 192, 192)), digging_power.fg(Color::Rgb(0, 128, 0)), ])); } if self.get_can_build() { lines.push(Line::from("Can build: Yes").fg(Color::Rgb(0, 128, 0))); } if !have_any_tasks { lines.push(Line::from("Tasks Queue: ".fg(Color::Rgb(192, 192, 192)))); for task in tasks { lines.push(task); } } lines } fn text(&self) -> Vec> { self.base_text() } }