107 lines
3.4 KiB
Rust
107 lines
3.4 KiB
Rust
//! Implementation of all needed traits for the Entity struct
|
||
use cli_table::{Style, WithTitle, print_stdout};
|
||
use colored::*; // [3] – colored‑rs examples
|
||
|
||
use crate::Displayable;
|
||
use crate::entity::Entity;
|
||
|
||
// ---------- Implementation ----------
|
||
impl Displayable for Entity {
|
||
// Detailed multi‑line view (used e.g. in logs)
|
||
fn print_full(&self) {
|
||
println!(
|
||
"{:?}\n{}",
|
||
self.metadata.position, // Display
|
||
format!(
|
||
"{} | {} | {} | {:?} | {}",
|
||
self.metadata.capital,
|
||
self.metadata.governor,
|
||
self.metadata.faction,
|
||
self.metadata.links,
|
||
self.metadata.prestige
|
||
)
|
||
.blue() // colour the whole line (you can tweak colours per field)
|
||
);
|
||
let meta_ext = format!(
|
||
"{:?} | {:?} | {:?} | {:?}",
|
||
self.duration, self.effect_nature, self.effect_bounds, self.entity_type
|
||
)
|
||
.green(); // another colour
|
||
println!("{meta_ext}");
|
||
print_stdout(vec![&self.stats, &self.temp_stats].with_title().bold(true)).expect("");
|
||
}
|
||
|
||
// Short, single‑line representation
|
||
fn print_short(&self) {
|
||
println!(
|
||
"{} | {:?} | {:?} | {:?} | {:?} | {:?} | {:?}",
|
||
self.name,
|
||
self.metadata.position,
|
||
self.duration,
|
||
self.effect_nature,
|
||
self.effect_bounds,
|
||
self.entity_type,
|
||
self.metadata.prestige
|
||
);
|
||
print_stdout(vec![&self.stats].with_title().bold(true)).expect("")
|
||
}
|
||
|
||
// One‑liner used for auto‑generation of Vec<T> displays
|
||
fn oneline_display(&self) -> String {
|
||
format!(
|
||
"{} | {:?} | {:?} | {:?} | {:?} | {:?} | {:?} | {:?}",
|
||
self.name,
|
||
self.metadata.position,
|
||
self.duration,
|
||
self.effect_nature,
|
||
self.effect_bounds,
|
||
self.entity_type,
|
||
self.metadata.capital,
|
||
self.metadata.prestige
|
||
)
|
||
}
|
||
}
|
||
|
||
impl Entity {
|
||
/// Just show a pretty tree
|
||
pub fn to_pretty_tree(&self) -> String {
|
||
// Helper that indents a line
|
||
let indent = |level: usize, s: &str| -> String {
|
||
format!(" {}{}", "│ ".repeat(level.saturating_sub(1)), s)
|
||
};
|
||
|
||
let mut out = String::new();
|
||
|
||
// out.push_str(&indent(0, "self\n"));
|
||
out.push_str(&indent(0, &format!("name: {}\n", self.name)));
|
||
out.push_str(&indent(1, "├─ metadata\n"));
|
||
out.push_str(&indent(
|
||
2,
|
||
&format!("├─ position: {:?}\n", self.metadata.position),
|
||
));
|
||
out.push_str(&indent(
|
||
2,
|
||
&format!("├─ capital: {:?}\n", self.metadata.capital),
|
||
));
|
||
out.push_str(&indent(
|
||
2,
|
||
&format!("└─ prestige: {:?}\n", self.metadata.prestige),
|
||
));
|
||
out.push_str(&indent(1, &format!("├─ duration: {:?}\n", self.duration)));
|
||
out.push_str(&indent(
|
||
1,
|
||
&format!("├─ effect_nature: {:?}\n", self.effect_nature),
|
||
));
|
||
out.push_str(&indent(
|
||
1,
|
||
&format!("├─ effect_bounds: {:?}\n", self.effect_bounds),
|
||
));
|
||
out.push_str(&indent(
|
||
1,
|
||
&format!("└─ entity_type: {:?}\n", self.entity_type),
|
||
));
|
||
|
||
out
|
||
}
|
||
}
|