From 2c83b199cb65dadaab6040cc1243f9e937e2a53a Mon Sep 17 00:00:00 2001 From: yuni Date: Sun, 17 Nov 2024 18:15:19 +0100 Subject: [PATCH] build.rs: automatically find all `scene_*.blend` files --- build.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index 8f2a775..32bde6b 100644 --- a/build.rs +++ b/build.rs @@ -9,6 +9,7 @@ // + ▀████████████████████████████████████████████████████▀ use blend::Blend; +use std::fs; use std::fs::File; use std::io::Write; @@ -27,13 +28,18 @@ fn main() -> std::io::Result<()> { "// DO NOT MODIFY MANUALLY, CHANGES WILL BE OVERWRITTEN!\n" )?; write!(&file, "[\n")?; - extract_scene(&mut file, "test", "src/blender/scene_test.blend")?; - extract_scene(&mut file, "workshop", "src/blender/scene_workshop.blend")?; - extract_scene( - &mut file, - "greenhouse", - "src/blender/scene_greenhouse.blend", - )?; + + // find all scene_*.blend files and extract+export their scenes + for entry in fs::read_dir("src/blender")? { + let path = entry?.path(); + if let Some(file_name) = path.file_name().and_then(|s| s.to_str()) { + if file_name.starts_with("scene_") && file_name.ends_with(".blend") { + let scene_name = &file_name["scene_".len()..file_name.len() - ".blend".len()]; + + extract_scene(&mut file, scene_name, path.to_str().unwrap())?; + } + } + } write!(&file, "]\n")?; } Ok(())