use crate::render::TerminalRenderer;
use crossterm::style::Color;
use std::io;
#[derive(Default)]
pub struct Decorations;
pub struct DecorationRenderConfig {
pub horizon_y: u16,
pub house_x: u16,
pub house_width: u16,
pub path_center: u16,
pub width: u16,
pub is_day: bool,
}
impl Decorations {
pub fn new() -> Self {
Self
}
pub fn render(
&self,
renderer: &mut TerminalRenderer,
config: &DecorationRenderConfig,
) -> io::Result<()> {
let (tree_lines, tree_color) = self.get_tree(config.is_day);
let tree_height = tree_lines.len() as u16;
let tree_y = config.horizon_y.saturating_sub(tree_height);
let tree_x = config.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(config.is_day);
let fence_height = fence_lines.len() as u16;
let fence_y = config.horizon_y.saturating_sub(fence_height); let fence_x = config.house_x + config.house_width + 2;
if fence_x < config.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(config.is_day);
let mailbox_x = config.path_center + 6; let mailbox_y = config.horizon_y + 1;
if mailbox_x < config.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(config.is_day);
let bush_height = bush_lines.len() as u16;
let bush_x = config.path_center.saturating_sub(10);
let bush_y = config.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, is_day: bool) -> (Vec<&'static str>, Color) {
(
vec![
" #### ",
" ######## ",
" ########## ",
" ######## ",
" _||_ ",
],
if is_day {
Color::DarkGreen
} else {
Color::Rgb { r: 0, g: 50, b: 0 }
},
)
}
fn get_bush(&self, is_day: bool) -> (Vec<&'static str>, Color) {
(
vec![" ,., ", " (,,,,)", " \"||\" "],
if is_day {
Color::Green
} else {
Color::DarkGreen
},
)
}
fn get_fence(&self, is_day: bool) -> (Vec<&'static str>, Color) {
(
vec!["|--|--|--|--|", "| | | | |"],
if is_day { Color::White } else { Color::Grey },
)
}
fn get_mailbox(&self, is_day: bool) -> (Vec<&'static str>, Color) {
(
vec![" ___ ", "|___|", " | "],
if is_day { Color::Blue } else { Color::DarkBlue },
)
}
}