From 8158bc1ff3572a6df682e76ff9894a5b231edee9 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 29 Aug 2023 13:16:57 +0100 Subject: [PATCH] Allow deduplicating background tiles --- agb-image-converter/src/lib.rs | 19 +++++++++++++++++++ examples/combo/src/lib.rs | 8 ++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 6e227d1d..af3ab982 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -36,6 +36,7 @@ struct BackgroundGfxOption { module_name: String, file_name: String, colours: Colours, + deduplicate: bool, } impl config::Image for BackgroundGfxOption { @@ -72,12 +73,30 @@ impl Parse for BackgroundGfxOption { Colours::Colours16 }; + let lookahead = input.lookahead1(); + + let deduplicate = if lookahead.peek(syn::Ident) { + let deduplicate: syn::Ident = input.parse()?; + + if deduplicate == "deduplicate" { + true + } else { + return Err(syn::Error::new_spanned( + deduplicate, + "Must either be the literal deduplicate or missing", + )); + } + } else { + false + }; + let file_name: syn::LitStr = input.parse()?; Ok(Self { module_name: module_name.to_string(), file_name: file_name.value(), colours, + deduplicate, }) } } diff --git a/examples/combo/src/lib.rs b/examples/combo/src/lib.rs index 67dd4263..69f495ae 100644 --- a/examples/combo/src/lib.rs +++ b/examples/combo/src/lib.rs @@ -47,10 +47,10 @@ impl Game { include_background_gfx!( games, "121105", - hat => "gfx/hat.png", - purple => "gfx/purple.png", - hyperspace => "gfx/hyperspace.png", - amplitude => "gfx/amplitude.png" + hat => deduplicate "gfx/hat.png", + purple => deduplicate "gfx/purple.png", + hyperspace => deduplicate "gfx/hyperspace.png", + amplitude => deduplicate "gfx/amplitude.png" ); fn get_game(gba: &mut agb::Gba) -> Game {