]> git.huck.website - cellseq.git/commitdiff
updated: render now calculated chars per unit
authorHuck Boles <huck@huck.website>
Fri, 2 Jun 2023 19:46:02 +0000 (14:46 -0500)
committerHuck Boles <huck@huck.website>
Fri, 2 Jun 2023 19:46:02 +0000 (14:46 -0500)
src/cells.rs
src/graphics.rs
src/graphics/map.rs
src/music.rs

index 1506ebe6e64e5156eb661507ddf978172266b2b9..f04e9b30d30ceead7600767828632cd7c7d06e25 100644 (file)
@@ -102,17 +102,16 @@ impl Map<Cell<State>> for World {
         (Attribute::Bold.into(), Attribute::Reset.into())
     }
 
-    fn try_point(&self, point: Point) -> bool {
+    fn draw_point(&self, point: Point) -> Option<char> {
         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<Cell<State>> {
-        self.get((point.y, point.x)).cloned()
     }
 }
 
index 9fbf217539cd6d69d5bc514371608bbbff284077..5415c8cdb44381ab57b4a55aedf9c3a1453f58c8 100644 (file)
@@ -45,29 +45,20 @@ pub fn draw_map<T>(map: &impl Map<T>, 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)
+            )?;
         }
     }
 
index c73646be9bf9198347620919d0f7c7d0825e67e8..61db0d83182b7579016a7c880af3f04febe93350 100644 (file)
@@ -11,8 +11,7 @@ use std::ops::{Deref, DerefMut};
 use super::*;
 
 pub trait Map<T> {
-    fn try_point(&self, point: Point) -> bool;
-    fn get_point(&self, point: Point) -> Option<T>;
+    fn draw_point(&self, point: Point) -> Option<char>;
     fn x_size(&self) -> usize;
     fn y_size(&self) -> usize;
     fn characters(&self) -> (char, char);
@@ -69,16 +68,8 @@ impl Map<Note> 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<Note> {
-        self.get((point.y, point.x)).copied()
+    fn draw_point(&self, point: Point) -> Option<char> {
+        self.get((point.y, point.x)).map(|n| n.to_char())
     }
 
     fn characters(&self) -> (char, char) {
index c0185e737bbe98ba6c04ae31bffccef5e9dc26d9..409a5798eb784eb7d1c6eb80b77a46c0e8b3d586 100644 (file)
@@ -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,