lib.rs

3.1 kB · rust · 110 lines

1#![doc = include_str!("../README.md")]2#![deny(missing_docs)]34/// The editorial constants: ladders, caps, tempos and freezes.5pub mod config;6/// The press: one quest emitted as frames, heatmap, audio and record.7pub mod emit;8/// The palettes: frame colors and the heatmap ramp.9pub mod frames;10/// The soundtrack: scores, tracks and the two-part quest audio.11pub mod music;12/// The quest: chained runs retried until a chapter settles alive.13pub mod quest;14/// The rule draw: sequences, reflection and the zero and one rolls.15pub mod sequence;16/// The samplers: boards up the ladders and the three mask paths.17pub mod variations;1819use mrlycore::errors::{value_error, Result};2021/// The two rulebooks a segment may run.22#[derive(Clone, Copy, Debug, PartialEq, Eq)]23pub enum Way {24    /// The classic B3/S23 rule on the Moore ring.25    Conway,26    /// The sequence-driven rule on a drawn mask.27    Mrly,28}2930impl Way {31    /// Returns the other way.32    pub fn flip(self) -> Way {33        match self {34            Way::Conway => Way::Mrly,35            Way::Mrly => Way::Conway,36        }37    }38    /// Returns the way's lowercase name.39    pub fn name(self) -> &'static str {40        match self {41            Way::Conway => "conway",42            Way::Mrly => "mrly",43        }44    }45    /// Parses a way name, or an error for an unknown one.46    pub fn parse(name: &str) -> Result<Way> {47        match name {48            "conway" => Ok(Way::Conway),49            "mrly" => Ok(Way::Mrly),50            other => value_error(format!("unknown way {other:?}.")),51        }52    }53}5455/// The three ways a segment draws its mask.56#[derive(Clone, Copy, Debug, PartialEq, Eq)]57pub enum Path {58    /// A three by three classic design.59    Simple,60    /// A fresh tile drawn under the mask caps.61    Basic,62    /// The segment's own board, coin-inverted.63    Copy,64}6566impl Path {67    /// Returns the path's lowercase name.68    pub fn name(self) -> &'static str {69        match self {70            Path::Simple => "simple",71            Path::Basic => "basic",72            Path::Copy => "copy",73        }74    }75    /// Parses a path name, or an error for an unknown one.76    pub fn parse(name: &str) -> Result<Path> {77        match name {78            "simple" => Ok(Path::Simple),79            "basic" => Ok(Path::Basic),80            "copy" => Ok(Path::Copy),81            other => value_error(format!("unknown path {other:?}.")),82        }83    }84}8586pub use config::Config;87pub use emit::{emit, emit_with, SEED};88pub use quest::{pivot_options, quest, Quest, Segment};8990#[cfg(test)]91mod tests {92    use super::*;93    #[test]94    fn ways_flip_back_and_forth() {95        assert_eq!(Way::Conway.flip(), Way::Mrly);96        assert_eq!(Way::Mrly.flip(), Way::Conway);97        assert_eq!(Way::Conway.flip().flip(), Way::Conway);98    }99    #[test]100    fn names_round_trip() {101        for way in [Way::Conway, Way::Mrly] {102            assert_eq!(Way::parse(way.name()).unwrap(), way);103        }104        for path in [Path::Simple, Path::Basic, Path::Copy] {105            assert_eq!(Path::parse(path.name()).unwrap(), path);106        }107        assert!(Way::parse("sideways").is_err());108        assert!(Path::parse("scenic").is_err());109    }110}