From ca64a2bb786e466b137508f8a7bd2eb41c85f008 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 1 Aug 2022 12:08:22 +0100 Subject: [PATCH] perform check in proc macro for size can give a better error message, pointing at the file that contains the bad sizes --- agb-image-converter/src/lib.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 139c7aad..1cd8356b 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -116,8 +116,13 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream { for frame in frames { let width = frame.width(); let height = frame.height(); - assert!(width.is_power_of_two() && width <= 64); - assert!(height.is_power_of_two() && height <= 64); + assert!( + valid_sprite_size(width, height), + "File {} contains sprites with unrepresentable size {}x{}", + filename.display(), + width, + height + ); let image = Image::load_from_dyn_image(frame); add_to_optimiser(&mut optimiser, &image, 8, Some(transparent_colour)); @@ -398,3 +403,21 @@ mod tests { assert_eq!(AnimationDirection::PingPong as usize, 2); } } + +fn valid_sprite_size(width: u32, height: u32) -> bool { + match (width, height) { + (8, 8) => true, + (16, 16) => true, + (32, 32) => true, + (64, 64) => true, + (16, 8) => true, + (32, 8) => true, + (32, 16) => true, + (64, 32) => true, + (8, 16) => true, + (8, 32) => true, + (16, 32) => true, + (32, 64) => true, + (_, _) => false, + } +}