Feels cleaner with a bunch of for loops

This commit is contained in:
Gwilym Kuiper 2021-07-26 23:30:46 +01:00
parent fdff081c32
commit 3626e2cb18

View file

@ -38,29 +38,25 @@ pub(crate) fn generate_code(
let tiles_x = image.width / tile_size;
let tiles_y = image.height / tile_size;
let tile_data = (0..tiles_y)
.map(|y| {
(0..tiles_x).map(move |x| {
let palette_index = results.assignments[y * tiles_x + x];
let palette = &results.optimised_palettes[palette_index];
let mut tile_data = vec![];
(0..tile_size / 8).map(move |inner_y| {
(0..tile_size / 8).map(move |inner_x| {
(inner_y * 8..inner_y * 8 + 8).map(move |j| {
(inner_x * 8..inner_x * 8 + 8).rev().map(move |i| {
let colour = image.colour(x * tile_size + i, y * tile_size + j);
palette.colour_index(colour)
})
})
})
})
})
})
.flatten()
.flatten()
.flatten()
.flatten()
.flatten();
for y in 0..tiles_y {
for x in 0..tiles_x {
let palette_index = results.assignments[y * tiles_x + x];
let palette = &results.optimised_palettes[palette_index];
for inner_y in 0..tile_size / 8 {
for inner_x in 0..tile_size / 8 {
for j in inner_y * 8..inner_y * 8 + 8 {
for i in inner_x * 8..inner_x * 8 + 8 {
let colour = image.colour(x * tile_size + i, y * tile_size + j);
tile_data.push(palette.colour_index(colour));
}
}
}
}
}
}
let assignments = &results.assignments;