now you're thinking with functions (and piping)

main
Elijah Voigt 2 years ago
parent a6cc91aacc
commit 7549f230bf

@ -780,30 +780,33 @@ mod animations {
pub fn add_animations_ui( pub fn add_animations_ui(
player_spawned: Query<&Name, Added<AnimationPlayer>>, player_spawned: Query<&Name, Added<AnimationPlayer>>,
widget: Query<Entity, With<AnimationWidget>>, widget: Query<Entity, With<AnimationWidget>>,
gltfs: Res<Assets<Gltf>>,
mut commands: Commands, mut commands: Commands,
gltfs: Res<Assets<Gltf>>,
clips: Res<Assets<AnimationClip>>, clips: Res<Assets<AnimationClip>>,
) { ) {
player_spawned.iter().for_each(|player_name| { player_spawned.iter().for_each(|player_name| {
gltfs.iter().for_each(|(_, gltf)| { gltfs
gltf.named_animations .iter()
.iter() .flat_map(|(_, gltf)| gltf.named_animations.iter())
.for_each(|(clip_name, handle)| { .filter_map(|(clip_name, handle)| {
info!("Checking clip {:?}", clip_name); if let Some(clip) = clips.get(&handle) {
let clip = clips.get(&handle).expect("load animation clip"); Some((clip_name, handle, clip))
clip.compatible_with(player_name).then(|| { } else {
create_asset_button( None
&widget, }
&mut commands, })
ui::TargetAsset { .filter(|(_, _, clip)| clip.compatible_with(player_name))
handle: handle.clone(), .for_each(|(clip_name, handle, _)| {
}, create_asset_button(
clip_name.clone(), &widget,
None, &mut commands,
); ui::TargetAsset {
}); handle: handle.clone(),
}); },
}); clip_name.clone(),
None,
);
});
}); });
} }

Loading…
Cancel
Save