From 7549f230bf8d52f02e66204ed48f9683666f0ff3 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 29 Aug 2023 09:52:12 -0700 Subject: [PATCH] now you're thinking with functions (and piping) --- bin/editor.rs | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/bin/editor.rs b/bin/editor.rs index b95bebb..f35a43b 100644 --- a/bin/editor.rs +++ b/bin/editor.rs @@ -780,30 +780,33 @@ mod animations { pub fn add_animations_ui( player_spawned: Query<&Name, Added>, widget: Query>, - gltfs: Res>, mut commands: Commands, + gltfs: Res>, clips: Res>, ) { player_spawned.iter().for_each(|player_name| { - gltfs.iter().for_each(|(_, gltf)| { - gltf.named_animations - .iter() - .for_each(|(clip_name, handle)| { - info!("Checking clip {:?}", clip_name); - let clip = clips.get(&handle).expect("load animation clip"); - clip.compatible_with(player_name).then(|| { - create_asset_button( - &widget, - &mut commands, - ui::TargetAsset { - handle: handle.clone(), - }, - clip_name.clone(), - None, - ); - }); - }); - }); + gltfs + .iter() + .flat_map(|(_, gltf)| gltf.named_animations.iter()) + .filter_map(|(clip_name, handle)| { + if let Some(clip) = clips.get(&handle) { + Some((clip_name, handle, clip)) + } else { + None + } + }) + .filter(|(_, _, clip)| clip.compatible_with(player_name)) + .for_each(|(clip_name, handle, _)| { + create_asset_button( + &widget, + &mut commands, + ui::TargetAsset { + handle: handle.clone(), + }, + clip_name.clone(), + None, + ); + }); }); }