perform check in proc macro for size

can give a better error message, pointing at the file that contains the bad sizes
This commit is contained in:
Corwin 2022-08-01 12:08:22 +01:00
parent 9410f6ed1d
commit ca64a2bb78

View file

@ -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,
}
}