diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index d40d64f3..411b29c7 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -109,6 +109,7 @@ impl Parse for BackgroundGfxOption { struct IncludeBackgroundGfxInput { module_name: syn::Ident, + as_pub: bool, crate_prefix: String, transparent_colour: Colour, background_gfx_options: Vec, @@ -126,6 +127,15 @@ impl Parse for IncludeBackgroundGfxInput { format_ident!("agb") }; + let lookahead = input.lookahead1(); + + let as_pub = if lookahead.peek(Token![pub]) { + let _: Token![pub] = input.parse()?; + true + } else { + false + }; + let module_name: syn::Ident = input.parse()?; let _: Token![,] = input.parse()?; @@ -146,6 +156,7 @@ impl Parse for IncludeBackgroundGfxInput { Ok(Self { module_name, + as_pub, crate_prefix: crate_prefix.to_string(), transparent_colour, background_gfx_options: background_gfx_options.into_iter().collect(), @@ -186,11 +197,13 @@ pub fn include_background_gfx(input: TokenStream) -> TokenStream { let root = std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get cargo manifest dir"); let module_name = config.module_name.clone(); - include_gfx_from_config(config, module_name, Path::new(&root)) + let as_pub = config.as_pub.clone(); + include_gfx_from_config(config, as_pub, module_name, Path::new(&root)) } fn include_gfx_from_config( config: Box, + as_pub: bool, module_name: syn::Ident, parent: &Path, ) -> TokenStream { @@ -255,11 +268,21 @@ fn include_gfx_from_config( let palette_code = rust_generator::generate_palette_code(&optimisation_results, &config.crate_prefix()); - let module = quote! { - mod #module_name { - #palette_code + let module = if as_pub { + quote! { + pub mod #module_name { + #palette_code - #(#image_code)* + #(#image_code)* + } + } + } else { + quote! { + mod #module_name { + #palette_code + + #(#image_code)* + } } };