From: Huck Boles Date: Fri, 2 Jun 2023 19:46:02 +0000 (-0500) Subject: updated: render now calculated chars per unit X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=7af4ed68cf43fd5c915f02e76c4ce43ceb3db992;p=cellseq.git updated: render now calculated chars per unit --- diff --git a/src/cells.rs b/src/cells.rs index 1506ebe..f04e9b3 100644 --- a/src/cells.rs +++ b/src/cells.rs @@ -102,17 +102,16 @@ impl Map> for World { (Attribute::Bold.into(), Attribute::Reset.into()) } - fn try_point(&self, point: Point) -> bool { + fn draw_point(&self, point: Point) -> Option { if let Some(cell) = self.get((point.y, point.x)) { if cell.get() == State::Alive { - return true; + return Some('●'); + } else { + return Some('◌'); } + } else { + return None; } - false - } - - fn get_point(&self, point: Point) -> Option> { - self.get((point.y, point.x)).cloned() } } diff --git a/src/graphics.rs b/src/graphics.rs index 9fbf217..5415c8c 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -45,29 +45,20 @@ pub fn draw_map(map: &impl Map, area: &Area) -> Result<()> { for x in 0..=(map.x_size()) { for y in 0..=(map.y_size()) { let point = Point::new(x, y); + let char = map.draw_point(point).unwrap_or(' '); let (x_off, y_off) = origin.u16_offset(point)?; if x_off <= x_zero || x_off >= x_max || y_off <= y_zero || y_off >= y_max - 1 { continue; } - if map.try_point(point) { - queue!( - stdout(), - MoveTo(x_off, y_off), - SetAttributes(style_on), - SetColors(on_colors), - Print(char_on) - )?; - } else { - queue!( - stdout(), - MoveTo(x_off, y_off), - SetAttributes(style_off), - SetColors(off_colors), - Print(char_off) - )?; - } + queue!( + stdout(), + MoveTo(x_off, y_off), + SetAttributes(style_on), + SetColors(on_colors), + Print(char) + )?; } } diff --git a/src/graphics/map.rs b/src/graphics/map.rs index c73646b..61db0d8 100644 --- a/src/graphics/map.rs +++ b/src/graphics/map.rs @@ -11,8 +11,7 @@ use std::ops::{Deref, DerefMut}; use super::*; pub trait Map { - fn try_point(&self, point: Point) -> bool; - fn get_point(&self, point: Point) -> Option; + fn draw_point(&self, point: Point) -> Option; fn x_size(&self) -> usize; fn y_size(&self) -> usize; fn characters(&self) -> (char, char); @@ -69,16 +68,8 @@ impl Map for Mask { self.nrows() } - fn try_point(&self, point: Point) -> bool { - if let Some(note) = self.get((point.y, point.x)) { - *note != Note::Off - } else { - false - } - } - - fn get_point(&self, point: Point) -> Option { - self.get((point.y, point.x)).copied() + fn draw_point(&self, point: Point) -> Option { + self.get((point.y, point.x)).map(|n| n.to_char()) } fn characters(&self) -> (char, char) { diff --git a/src/music.rs b/src/music.rs index c0185e7..409a579 100644 --- a/src/music.rs +++ b/src/music.rs @@ -4,7 +4,7 @@ mod transport; pub use scale::*; pub use transport::*; -use std::fmt::Display; +use std::{fmt::Display, ops::Deref}; #[derive(Clone, Copy, Debug)] pub struct TimeSignature { @@ -50,6 +50,21 @@ impl Display for Note { } } +impl Note { + pub fn to_char(&self) -> char { + match self { + Note::Off => ' ', + Note::A(_) => 'a', + Note::B(_) => 'b', + Note::C(_) => 'c', + Note::D(_) => 'd', + Note::E(_) => 'e', + Note::F(_) => 'f', + Note::G(_) => 'g', + } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum Acc { Flt,