use crate::render::TerminalRenderer;
use crossterm::style::Color;
use std::io;
#[derive(Default)]
pub struct Decorations;
impl Decorations {
pub fn new() -> Self {
Self
}
pub fn render(
&self,
renderer: &mut TerminalRenderer,
horizon_y: u16,
house_x: u16,
house_width: u16,
path_center: u16,
width: u16,
) -> io::Result<()> {
let (tree_lines, tree_color) = self.get_tree();
let tree_height = tree_lines.len() as u16;
let tree_y = horizon_y.saturating_sub(tree_height);
let tree_x = house_x.saturating_sub(20);
if tree_x > 0 {
for (i, line) in tree_lines.iter().enumerate() {
renderer.render_line_colored(tree_x, tree_y + i as u16, line, tree_color)?;
}
}
let (fence_lines, fence_color) = self.get_fence();
let fence_height = fence_lines.len() as u16;
let fence_y = horizon_y.saturating_sub(fence_height); let fence_x = house_x + house_width + 2;
if fence_x < width {
for (i, line) in fence_lines.iter().enumerate() {
renderer.render_line_colored(fence_x, fence_y + i as u16, line, fence_color)?;
}
}
let (mailbox_lines, mailbox_color) = self.get_mailbox();
let mailbox_x = path_center + 6; let mailbox_y = horizon_y + 1;
if mailbox_x < width {
for (i, line) in mailbox_lines.iter().enumerate() {
renderer.render_line_colored(
mailbox_x,
mailbox_y + i as u16,
line,
mailbox_color,
)?;
}
}
let (bush_lines, bush_color) = self.get_bush();
let bush_height = bush_lines.len() as u16;
let bush_x = path_center.saturating_sub(10);
let bush_y = horizon_y.saturating_sub(bush_height / 2);
if bush_x > 0 {
for (i, line) in bush_lines.iter().enumerate() {
renderer.render_line_colored(bush_x, bush_y + i as u16, line, bush_color)?;
}
}
Ok(())
}
fn get_tree(&self) -> (Vec<&'static str>, Color) {
(
vec![
" #### ",
" ######## ",
" ########## ",
" ######## ",
" _||_ ",
],
Color::DarkGreen,
)
}
fn get_bush(&self) -> (Vec<&'static str>, Color) {
(vec![" ,., ", " (,,,,)", " \"||\" "], Color::Green)
}
fn get_fence(&self) -> (Vec<&'static str>, Color) {
(vec!["|--|--|--|--|", "| | | | |"], Color::White)
}
fn get_mailbox(&self) -> (Vec<&'static str>, Color) {
(vec![" ___ ", "|___|", " | "], Color::Blue)
}
}