Skip to content

Commit

Permalink
suiro: Add Map::gen
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jun 23, 2022
1 parent 512e378 commit 4b90572
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 2 additions & 7 deletions suiro/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use clap::Parser;
use cursor::Cursor;
use size::Size;
use std::{
collections::VecDeque,
io::{self, StdoutLock, Write},
str::FromStr,
};
Expand Down Expand Up @@ -241,13 +242,7 @@ fn main() -> anyhow::Result<()> {
.map(|s| Map::from_str(s.as_str()))
.unwrap_or_else(|| {
let size = Size::new(16, 16).map_err(map::Error::from)?;
Map::new(
size,
(0..u16::from(size.width()) * u16::from(size.height()))
.into_iter()
.map(|_| Pipe::try_from('─').expect("pipe broken"))
.collect::<Vec<Pipe>>(),
)
Map::gen(size)
})?;

let stdout = io::stdout().lock();
Expand Down
9 changes: 9 additions & 0 deletions suiro/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ impl FromStr for Map {
}

impl Map {
pub fn gen(size: Size) -> Result<Self> {
// TODO:
let pipes = (0..u16::from(size.width()) * u16::from(size.height()))
.into_iter()
.map(|_| Pipe::try_from('─').expect("pipe broken"))
.collect::<Vec<Pipe>>();
Ok(Self { size, pipes })
}

pub fn new(size: Size, pipes: Vec<Pipe>) -> Result<Self> {
let length = u16::try_from(pipes.len()).map_err(|_| Error::TooManyPipes)?;
match length.cmp(&(u16::from(size.width()) * u16::from(size.height()))) {
Expand Down

0 comments on commit 4b90572

Please sign in to comment.