improve read_rle

This commit is contained in:
mos 2025-03-03 15:33:05 +01:00
parent 40795de5c3
commit b9949eff67
1 changed files with 11 additions and 11 deletions

View File

@ -168,20 +168,20 @@ impl Level {
}
fn read_rle(map: &str) -> std::result::Result<Self, ReadError> {
let mut n: usize = 1;
Self::read(
map.chars()
.filter_map(|c| match c {
'0'..='9' => {
n = c.to_digit(10).unwrap() as usize;
None
}
'|' => Some("\n".into()),
_ => Some(c.to_string().repeat(n)),
.scan(1, |n, c| {
Some(match c {
'0'..='9' => {
*n = c.to_digit(10).unwrap() as usize;
None
}
'|' => Some("\n".to_string()),
_ => Some(c.to_string().repeat(*n)),
})
})
.collect::<Vec<String>>()
.join("")
.flatten()
.collect::<String>()
.as_bytes(),
)
}