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_x = image.width / tile_size;
let tiles_y = image.height / tile_size; let tiles_y = image.height / tile_size;
let tile_data = (0..tiles_y) let mut tile_data = vec![];
.map(|y| {
(0..tiles_x).map(move |x| { for y in 0..tiles_y {
for x in 0..tiles_x {
let palette_index = results.assignments[y * tiles_x + x]; let palette_index = results.assignments[y * tiles_x + x];
let palette = &results.optimised_palettes[palette_index]; let palette = &results.optimised_palettes[palette_index];
(0..tile_size / 8).map(move |inner_y| { for inner_y in 0..tile_size / 8 {
(0..tile_size / 8).map(move |inner_x| { for inner_x in 0..tile_size / 8 {
(inner_y * 8..inner_y * 8 + 8).map(move |j| { for j in inner_y * 8..inner_y * 8 + 8 {
(inner_x * 8..inner_x * 8 + 8).rev().map(move |i| { for i in inner_x * 8..inner_x * 8 + 8 {
let colour = image.colour(x * tile_size + i, y * tile_size + j); let colour = image.colour(x * tile_size + i, y * tile_size + j);
palette.colour_index(colour) tile_data.push(palette.colour_index(colour));
}) }
}) }
}) }
}) }
}) }
}) }
.flatten()
.flatten()
.flatten()
.flatten()
.flatten();
let assignments = &results.assignments; let assignments = &results.assignments;