From 3fcab53f52803753ffdbfad1e2726e93e735317b Mon Sep 17 00:00:00 2001 From: Constantin Date: Wed, 24 Jan 2024 19:19:30 +0100 Subject: [PATCH] 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;