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 MIT License
Copyright © 2021 Max Bradbury Copyright (c) 2020 Max Bradbury
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal 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)] #[derive(Debug)]
pub enum Error { pub enum Error {
Colour, Colour,
@ -37,9 +31,7 @@ pub enum Error {
Game { Game {
missing: NotFound, missing: NotFound,
}, },
Image { Image,
err: ImageError,
},
Item, Item,
Palette, Palette,
Position, Position,

View File

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