cargo fmt... also maybe fix that shared materials thing

main
Elijah C. Voigt 2 years ago
parent 2d476b89da
commit 3275582176

@ -222,7 +222,10 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
*index, *index,
SceneBundle { ..default() }, SceneBundle { ..default() },
game::Selectable, game::Selectable,
Dissolvable { start: 1.0, duration: 3.0 }, // Marks pieces as dissolving Dissolvable {
start: 1.0,
duration: 3.0,
}, // Marks pieces as dissolving
)); ));
}); });
@ -233,7 +236,10 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
GameState::Title, GameState::Title,
SceneBundle { ..default() }, SceneBundle { ..default() },
TitleText, TitleText,
Dissolvable { start: 0.0, duration: 3.0 }, // Marks title text as dissolving Dissolvable {
start: 0.0,
duration: 3.0,
}, // Marks title text as dissolving
)); ));
}); });
}); });
@ -1192,8 +1198,6 @@ fn setup_dissolve_materials(
mut dissolve_materials: ResMut<Assets<DissolveMaterial>>, mut dissolve_materials: ResMut<Assets<DissolveMaterial>>,
// Used to insert Handle<DissolveMaterial>; // Used to insert Handle<DissolveMaterial>;
mut commands: Commands, mut commands: Commands,
// Cache dissolve textures that have already been created
mut cache: Local<HashMap<Handle<StandardMaterial>, Handle<DissolveMaterial>>>,
) { ) {
events events
.iter() .iter()
@ -1202,9 +1206,7 @@ fn setup_dissolve_materials(
// Handle this entity (mesh) // Handle this entity (mesh)
.for_each(|(child, std_handle)| { .for_each(|(child, std_handle)| {
info!("Setting up dissolve material for {:?}", child); info!("Setting up dissolve material for {:?}", child);
let dis_handle = match cache.get(std_handle) {
// We have not seen this material, so create a new dissolve material
None => {
// Extension we will add to existing gltf-sourced materials // Extension we will add to existing gltf-sourced materials
let extension = DissolveExtension { percentage: 1.0 }; let extension = DissolveExtension { percentage: 1.0 };
// Base material we will extend for the duration of the dissolve effect // Base material we will extend for the duration of the dissolve effect
@ -1217,16 +1219,11 @@ fn setup_dissolve_materials(
base.base_color = Color::NONE.with_a(0.0); base.base_color = Color::NONE.with_a(0.0);
info!("Base material {:#?}", base); info!("Base material {:#?}", base);
dissolve_materials.add(ExtendedMaterial { base, extension }) let dis_handle = dissolve_materials.add(ExtendedMaterial { base, extension });
}
Some(dis_handle) => dis_handle.clone(),
};
// Insert this handle into the cache (may be redundant)
cache.insert(std_handle.clone(), dis_handle.clone());
// Add the dissolve handle as a Backup(T) // Add the dissolve handle as a Backup(T)
commands.entity(child) commands
.entity(child)
.insert(dis_handle.clone()) .insert(dis_handle.clone())
.remove::<Handle<StandardMaterial>>(); .remove::<Handle<StandardMaterial>>();
}); });
@ -1363,14 +1360,13 @@ fn dissolve_animation(
children: Query<&Children>, children: Query<&Children>,
// Used to create Handle<DissolveMaterial> // Used to create Handle<DissolveMaterial>
mut dissolve_materials: ResMut<Assets<DissolveMaterial>>, mut dissolve_materials: ResMut<Assets<DissolveMaterial>>,
object_materials: Query<( object_materials: Query<(Entity, &Handle<DissolveMaterial>)>,
Entity,
&Handle<DissolveMaterial>,
)>,
mut commands: Commands, mut commands: Commands,
time: Res<Time>, time: Res<Time>,
) { ) {
query.iter_mut().for_each(|(entity, dissolvable, mut dissolving)| { query
.iter_mut()
.for_each(|(entity, dissolvable, mut dissolving)| {
debug!("Entity {:?} has Dissolving {:?}", entity, dissolving); debug!("Entity {:?} has Dissolving {:?}", entity, dissolving);
let percentage = match *dissolving { let percentage = match *dissolving {
@ -1394,20 +1390,23 @@ fn dissolve_animation(
} }
}; };
object_materials.iter_many(children.iter_descendants(entity)).for_each( object_materials
|(_child, handle)| { .iter_many(children.iter_descendants(entity))
.for_each(|(_child, handle)| {
let dissolve_material = dissolve_materials let dissolve_material = dissolve_materials
.get_mut(handle) .get_mut(handle)
.expect("Get the dissolve material"); .expect("Get the dissolve material");
// Change the material's value to create animation // Change the material's value to create animation
dissolve_material.extension.percentage = percentage; dissolve_material.extension.percentage = percentage;
}, });
);
// If animation is done, remove dissolving component // If animation is done, remove dissolving component
if percentage <= 0.0 || percentage >= 1.0 { if percentage <= 0.0 || percentage >= 1.0 {
info!("Removing dissolving from {:?} with percentage {:?}", entity, percentage); info!(
"Removing dissolving from {:?} with percentage {:?}",
entity, percentage
);
commands.entity(entity).remove::<Dissolving>(); commands.entity(entity).remove::<Dissolving>();
} }
}); });

Loading…
Cancel
Save