diff --git a/CHANGELOG.md b/CHANGELOG.md index f10db823..d032a2f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - There are no longer gaps between tiles in affine graphics modes. +### Added +- Added option to export imported background graphics from `include_background_gfx` as pub. + ## [0.20.5] - 2024/06/18 ### Fixed diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index d40d64f3..0c31b95a 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; + 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)* + } } }; diff --git a/agb/src/lib.rs b/agb/src/lib.rs index 7bf5a63c..9c66f36d 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -105,6 +105,15 @@ /// # use agb::include_background_gfx; /// include_background_gfx!(generated_background, "000000", DATA => "$OUT_DIR/generated_background.aseprite"); /// ``` +/// +/// You can also make the exported background a public module which will allow other modules access them. The following +/// will declare `water_tiles` as a `pub mod` rather than a `mod`. +/// +/// ```rust,no_run +/// ##![no_std] +/// ##![no_main] +/// agb::include_background_gfx!(pub water_tiles, tiles => "examples/water_tiles.png"); +/// ``` pub use agb_image_converter::include_background_gfx; #[doc(hidden)]