Compare commits

..

No commits in common. "b8c30fe873c1a6a2e2a65bf26b99a6d2e6cd3839" and "4182079a7387c9a8392671c61b33bc38f048e4c2" have entirely different histories.

3 changed files with 6 additions and 24 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright © 2021 Max Bradbury
Copyright (c) 2020 Max Bradbury
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -21,12 +21,6 @@ impl fmt::Display for NotFound {
}
}
#[derive(Debug)]
pub enum ImageError {
MalformedPixel,
WrongSize,
}
#[derive(Debug)]
pub enum Error {
Colour,
@ -37,9 +31,7 @@ pub enum Error {
Game {
missing: NotFound,
},
Image {
err: ImageError,
},
Image,
Item,
Palette,
Position,

View File

@ -1,5 +1,4 @@
use std::fmt;
use crate::error::ImageError;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Image {
@ -57,7 +56,7 @@ impl Image {
let mut warnings = Vec::new();
if str.contains("NaN") {
warnings.push(crate::Error::Image { err: ImageError::MalformedPixel });
warnings.push(crate::Error::Image);
}
let string = str.trim().replace("NaN", "0");
@ -69,24 +68,15 @@ impl Image {
for line in lines {
let line = &line[..dimension];
for char in line.chars().into_iter() {
pixels.push(match char {
'0' => 0,
'1' => 1,
_ => {
warnings.push(
crate::Error::Image { err: ImageError::MalformedPixel }
);
0
}
});
// todo push warning on integers other than 0/1
pixels.push(match char {'1' => 1, _ => 0});
}
}
// 8×8 (normal) or 16×16 (Bitsy HD)
if [64, 256].contains(&pixels.len()) {
Ok((Image { pixels }, warnings))
} else {
Err(crate::Error::Image { err: ImageError::WrongSize })
Err(crate::Error::Image)
}
}
}