use square root instead of constants

This commit is contained in:
Max Bradbury 2020-04-11 18:24:22 +01:00
parent f9140d8eb8
commit 2f3ee8f302
1 changed files with 2 additions and 10 deletions

View File

@ -1,6 +1,3 @@
const IMAGE_DIMENSION_SD: usize = 8;
const IMAGE_DIMENSION_HD: usize = 16;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
struct Colour { struct Colour {
red: u8, red: u8,
@ -114,7 +111,6 @@ struct Game {
name: String, name: String,
version: f64, version: f64,
room_format: u8, room_format: u8,
hd: bool,
palettes: Vec<Palette>, palettes: Vec<Palette>,
variables: Vec<Variable>, variables: Vec<Variable>,
} }
@ -310,14 +306,10 @@ fn test_image_from_string() {
} }
fn image_to_string(image: Image) -> String { fn image_to_string(image: Image) -> String {
image_to_string_opts(image, false)
}
fn image_to_string_opts(image: Image, hd: bool) -> String {
let mut string = String::new(); let mut string = String::new();
let chunk_size = if hd {IMAGE_DIMENSION_HD} else {IMAGE_DIMENSION_SD};
for line in image.pixels.chunks(chunk_size) { let sqrt = (room.tiles.len() as f64).sqrt() as usize; // 8 for SD, 16 for HD
for line in image.pixels.chunks(sqrt) {
for pixel in line { for pixel in line {
string.push_str(&format!("{}", *pixel)); string.push_str(&format!("{}", *pixel));
} }