From 3fcab53f52803753ffdbfad1e2726e93e735317b Mon Sep 17 00:00:00 2001 From: Constantin Date: Wed, 24 Jan 2024 19:19:30 +0100 Subject: [PATCH 1/5] Expand $OUT_DIR in background and sprite include macros --- agb-image-converter/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index d5fa34e4..8511f387 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -42,7 +42,9 @@ struct BackgroundGfxOption { impl config::Image for BackgroundGfxOption { fn filename(&self) -> String { - self.file_name.clone() + self.file_name + .clone() + .replace(OUT_DIR, &get_out_dir(&self.file_name)) } fn colours(&self) -> Colours { @@ -293,6 +295,8 @@ pub fn include_colours_inner(input: TokenStream) -> TokenStream { #[proc_macro] pub fn include_aseprite_inner(input: TokenStream) -> TokenStream { + let out_dir = get_out_dir(&input.to_string()); + let parser = Punctuated::::parse_terminated; let parsed = match parser.parse(input) { Ok(e) => e, @@ -310,6 +314,7 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream { let filenames: Vec = parsed .iter() .map(|s| s.value()) + .map(|s| s.replace(OUT_DIR, &out_dir)) .map(|s| Path::new(&root).join(&*s)) .collect(); @@ -663,6 +668,16 @@ fn valid_sprite_size(width: u32, height: u32) -> bool { } } +const OUT_DIR: &str = "$OUT_DIR"; + +fn get_out_dir(raw_input: &str) -> String { + if raw_input.contains(OUT_DIR) { + std::env::var("OUT_DIR").expect("Failed to get OUT_DIR") + } else { + String::new() + } +} + #[cfg(test)] mod tests { use asefile::AnimationDirection; From 3cd71b120ffaab03c51b39ec74edd1852dc384fa Mon Sep 17 00:00:00 2001 From: Constantin Date: Wed, 24 Jan 2024 20:17:04 +0100 Subject: [PATCH 2/5] Names update --- agb-image-converter/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 8511f387..f1d6f32e 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -44,7 +44,7 @@ impl config::Image for BackgroundGfxOption { fn filename(&self) -> String { self.file_name .clone() - .replace(OUT_DIR, &get_out_dir(&self.file_name)) + .replace(OUT_DIR_TOKEN, &get_out_dir(&self.file_name)) } fn colours(&self) -> Colours { @@ -295,7 +295,7 @@ pub fn include_colours_inner(input: TokenStream) -> TokenStream { #[proc_macro] pub fn include_aseprite_inner(input: TokenStream) -> TokenStream { - let out_dir = get_out_dir(&input.to_string()); + let out_dir_path = get_out_dir(&input.to_string()); let parser = Punctuated::::parse_terminated; let parsed = match parser.parse(input) { @@ -314,7 +314,7 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream { let filenames: Vec = parsed .iter() .map(|s| s.value()) - .map(|s| s.replace(OUT_DIR, &out_dir)) + .map(|s| s.replace(OUT_DIR_TOKEN, &out_dir_path)) .map(|s| Path::new(&root).join(&*s)) .collect(); @@ -668,10 +668,10 @@ fn valid_sprite_size(width: u32, height: u32) -> bool { } } -const OUT_DIR: &str = "$OUT_DIR"; +const OUT_DIR_TOKEN: &str = "$OUT_DIR"; fn get_out_dir(raw_input: &str) -> String { - if raw_input.contains(OUT_DIR) { + if raw_input.contains(OUT_DIR_TOKEN) { std::env::var("OUT_DIR").expect("Failed to get OUT_DIR") } else { String::new() From b03268f363ce06eb64041a3ece4d05bf8c2ad866 Mon Sep 17 00:00:00 2001 From: Constantin Date: Sat, 3 Feb 2024 13:40:59 +0100 Subject: [PATCH 3/5] Added macro doc --- agb-image-converter/src/lib.rs | 9 +++++++++ agb/src/display/object/sprites/sprite.rs | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index f1d6f32e..4831da61 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -171,6 +171,15 @@ impl config::Config for IncludeBackgroundGfxInput { } } +/// Including from the out directory is supported through the `$OUT_DIR` token. +/// +/// ```rust,ignore +/// # #![no_std] +/// # #![no_main] +/// # use agb::include_background_gfx; +/// include_background_gfx!(generated_background, "000000", DATA => "$OUT_DIR/generated_background.aseprite"); +/// ``` +/// #[proc_macro] pub fn include_background_gfx(input: TokenStream) -> TokenStream { let config = Box::new(parse_macro_input!(input as IncludeBackgroundGfxInput)); diff --git a/agb/src/display/object/sprites/sprite.rs b/agb/src/display/object/sprites/sprite.rs index 0857e283..1c688dee 100644 --- a/agb/src/display/object/sprites/sprite.rs +++ b/agb/src/display/object/sprites/sprite.rs @@ -91,6 +91,17 @@ macro_rules! align_bytes { /// name in code. You should ensure tags are unique as this is not enforced by /// aseprite. /// +/// Including from the out directory is supported through the `$OUT_DIR` token. +/// +/// ```rust,ignore +/// # #![no_std] +/// # #![no_main] +/// # use agb::{display::object::Graphics, include_aseprite}; +/// const GRAPHICS: &Graphics = include_aseprite!( +/// "$OUT_DIR/generated_sprite.aseprite" +/// ); +/// ``` +/// #[macro_export] macro_rules! include_aseprite { ($($aseprite_path: expr),*) => {{ From 03fb125d52dfd948605db60ef13da462f8840e64 Mon Sep 17 00:00:00 2001 From: Constantin Date: Sat, 3 Feb 2024 13:41:27 +0100 Subject: [PATCH 4/5] Changelog update --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3402c156..b7971029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- You can now use include_aseprite and include_background_gfx to include files from the out directory using the `$OUT_DIR` token. + ## [0.18.0] - 2023/10/31 ### Added From ade1ba57184e4deaa071d0fd33c11b007bb2ed49 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Sat, 3 Feb 2024 20:22:06 +0000 Subject: [PATCH 5/5] Also include the docs in the agb lib itself --- agb/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/agb/src/lib.rs b/agb/src/lib.rs index 44d3615b..c7483b93 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -97,6 +97,15 @@ /// bg.show(); /// # } /// ``` +/// +/// Including from the out directory is supported through the `$OUT_DIR` token. +/// +/// ```rust,ignore +/// # #![no_std] +/// # #![no_main] +/// # use agb::include_background_gfx; +/// include_background_gfx!(generated_background, "000000", DATA => "$OUT_DIR/generated_background.aseprite"); +/// ``` pub use agb_image_converter::include_background_gfx; #[doc(hidden)]