mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Allow exporting included background
(cherry picked from commit 0f6548cc8cb4fabec868a234488f064c12961cd8)
This commit is contained in:
parent
7833561be1
commit
98ec2c5629
|
@ -109,6 +109,7 @@ impl Parse for BackgroundGfxOption {
|
||||||
|
|
||||||
struct IncludeBackgroundGfxInput {
|
struct IncludeBackgroundGfxInput {
|
||||||
module_name: syn::Ident,
|
module_name: syn::Ident,
|
||||||
|
as_pub: bool,
|
||||||
crate_prefix: String,
|
crate_prefix: String,
|
||||||
transparent_colour: Colour,
|
transparent_colour: Colour,
|
||||||
background_gfx_options: Vec<BackgroundGfxOption>,
|
background_gfx_options: Vec<BackgroundGfxOption>,
|
||||||
|
@ -126,6 +127,15 @@ impl Parse for IncludeBackgroundGfxInput {
|
||||||
format_ident!("agb")
|
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 module_name: syn::Ident = input.parse()?;
|
||||||
let _: Token![,] = input.parse()?;
|
let _: Token![,] = input.parse()?;
|
||||||
|
|
||||||
|
@ -146,6 +156,7 @@ impl Parse for IncludeBackgroundGfxInput {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
module_name,
|
module_name,
|
||||||
|
as_pub,
|
||||||
crate_prefix: crate_prefix.to_string(),
|
crate_prefix: crate_prefix.to_string(),
|
||||||
transparent_colour,
|
transparent_colour,
|
||||||
background_gfx_options: background_gfx_options.into_iter().collect(),
|
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 root = std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get cargo manifest dir");
|
||||||
|
|
||||||
let module_name = config.module_name.clone();
|
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(
|
fn include_gfx_from_config(
|
||||||
config: Box<dyn config::Config>,
|
config: Box<dyn config::Config>,
|
||||||
|
as_pub: bool,
|
||||||
module_name: syn::Ident,
|
module_name: syn::Ident,
|
||||||
parent: &Path,
|
parent: &Path,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
|
@ -255,11 +268,21 @@ fn include_gfx_from_config(
|
||||||
let palette_code =
|
let palette_code =
|
||||||
rust_generator::generate_palette_code(&optimisation_results, &config.crate_prefix());
|
rust_generator::generate_palette_code(&optimisation_results, &config.crate_prefix());
|
||||||
|
|
||||||
let module = quote! {
|
let module = if as_pub {
|
||||||
mod #module_name {
|
quote! {
|
||||||
#palette_code
|
pub mod #module_name {
|
||||||
|
#palette_code
|
||||||
|
|
||||||
#(#image_code)*
|
#(#image_code)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
quote! {
|
||||||
|
mod #module_name {
|
||||||
|
#palette_code
|
||||||
|
|
||||||
|
#(#image_code)*
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue