|
|
|
|
@ -222,7 +222,10 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
|
|
|
|
|
*index,
|
|
|
|
|
SceneBundle { ..default() },
|
|
|
|
|
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,
|
|
|
|
|
SceneBundle { ..default() },
|
|
|
|
|
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>>,
|
|
|
|
|
// Used to insert Handle<DissolveMaterial>;
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
// Cache dissolve textures that have already been created
|
|
|
|
|
mut cache: Local<HashMap<Handle<StandardMaterial>, Handle<DissolveMaterial>>>,
|
|
|
|
|
) {
|
|
|
|
|
events
|
|
|
|
|
.iter()
|
|
|
|
|
@ -1202,31 +1206,24 @@ fn setup_dissolve_materials(
|
|
|
|
|
// Handle this entity (mesh)
|
|
|
|
|
.for_each(|(child, std_handle)| {
|
|
|
|
|
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
|
|
|
|
|
let extension = DissolveExtension { percentage: 1.0 };
|
|
|
|
|
// Base material we will extend for the duration of the dissolve effect
|
|
|
|
|
let mut base: StandardMaterial = standard_materials
|
|
|
|
|
.get(std_handle)
|
|
|
|
|
.expect("Resolve material data")
|
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
|
|
base.alpha_mode = AlphaMode::Mask(0.5);
|
|
|
|
|
base.base_color = Color::NONE.with_a(0.0);
|
|
|
|
|
info!("Base material {:#?}", base);
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
// Extension we will add to existing gltf-sourced materials
|
|
|
|
|
let extension = DissolveExtension { percentage: 1.0 };
|
|
|
|
|
// Base material we will extend for the duration of the dissolve effect
|
|
|
|
|
let mut base: StandardMaterial = standard_materials
|
|
|
|
|
.get(std_handle)
|
|
|
|
|
.expect("Resolve material data")
|
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
|
|
base.alpha_mode = AlphaMode::Mask(0.5);
|
|
|
|
|
base.base_color = Color::NONE.with_a(0.0);
|
|
|
|
|
info!("Base material {:#?}", base);
|
|
|
|
|
|
|
|
|
|
let dis_handle = dissolve_materials.add(ExtendedMaterial { base, extension });
|
|
|
|
|
|
|
|
|
|
// Add the dissolve handle as a Backup(T)
|
|
|
|
|
commands.entity(child)
|
|
|
|
|
commands
|
|
|
|
|
.entity(child)
|
|
|
|
|
.insert(dis_handle.clone())
|
|
|
|
|
.remove::<Handle<StandardMaterial>>();
|
|
|
|
|
});
|
|
|
|
|
@ -1363,52 +1360,54 @@ fn dissolve_animation(
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
// Used to create Handle<DissolveMaterial>
|
|
|
|
|
mut dissolve_materials: ResMut<Assets<DissolveMaterial>>,
|
|
|
|
|
object_materials: Query<(
|
|
|
|
|
Entity,
|
|
|
|
|
&Handle<DissolveMaterial>,
|
|
|
|
|
)>,
|
|
|
|
|
object_materials: Query<(Entity, &Handle<DissolveMaterial>)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
) {
|
|
|
|
|
query.iter_mut().for_each(|(entity, dissolvable, mut dissolving)| {
|
|
|
|
|
debug!("Entity {:?} has Dissolving {:?}", entity, dissolving);
|
|
|
|
|
query
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.for_each(|(entity, dissolvable, mut dissolving)| {
|
|
|
|
|
debug!("Entity {:?} has Dissolving {:?}", entity, dissolving);
|
|
|
|
|
|
|
|
|
|
let percentage = match *dissolving {
|
|
|
|
|
Dissolving::In(mut sec) => {
|
|
|
|
|
// Check if seconds is below 0.0
|
|
|
|
|
sec = (sec - time.delta_seconds()).max(0.0);
|
|
|
|
|
let percentage = match *dissolving {
|
|
|
|
|
Dissolving::In(mut sec) => {
|
|
|
|
|
// Check if seconds is below 0.0
|
|
|
|
|
sec = (sec - time.delta_seconds()).max(0.0);
|
|
|
|
|
|
|
|
|
|
*dissolving = Dissolving::In(sec);
|
|
|
|
|
*dissolving = Dissolving::In(sec);
|
|
|
|
|
|
|
|
|
|
// Calculate the target percentage value
|
|
|
|
|
1.0 - (sec / dissolvable.duration)
|
|
|
|
|
}
|
|
|
|
|
Dissolving::Out(mut sec) => {
|
|
|
|
|
// Check if seconds is below 0.0
|
|
|
|
|
sec = (sec - time.delta_seconds()).max(0.0);
|
|
|
|
|
// Calculate the target percentage value
|
|
|
|
|
1.0 - (sec / dissolvable.duration)
|
|
|
|
|
}
|
|
|
|
|
Dissolving::Out(mut sec) => {
|
|
|
|
|
// Check if seconds is below 0.0
|
|
|
|
|
sec = (sec - time.delta_seconds()).max(0.0);
|
|
|
|
|
|
|
|
|
|
*dissolving = Dissolving::Out(sec);
|
|
|
|
|
*dissolving = Dissolving::Out(sec);
|
|
|
|
|
|
|
|
|
|
// Calculate the target percentage value
|
|
|
|
|
sec / dissolvable.duration
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// Calculate the target percentage value
|
|
|
|
|
sec / dissolvable.duration
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
object_materials.iter_many(children.iter_descendants(entity)).for_each(
|
|
|
|
|
|(_child, handle)| {
|
|
|
|
|
let dissolve_material = dissolve_materials
|
|
|
|
|
.get_mut(handle)
|
|
|
|
|
.expect("Get the dissolve material");
|
|
|
|
|
object_materials
|
|
|
|
|
.iter_many(children.iter_descendants(entity))
|
|
|
|
|
.for_each(|(_child, handle)| {
|
|
|
|
|
let dissolve_material = dissolve_materials
|
|
|
|
|
.get_mut(handle)
|
|
|
|
|
.expect("Get the dissolve material");
|
|
|
|
|
|
|
|
|
|
// Change the material's value to create animation
|
|
|
|
|
dissolve_material.extension.percentage = percentage;
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
// Change the material's value to create animation
|
|
|
|
|
dissolve_material.extension.percentage = percentage;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// If animation is done, remove dissolving component
|
|
|
|
|
if percentage <= 0.0 || percentage >= 1.0 {
|
|
|
|
|
info!("Removing dissolving from {:?} with percentage {:?}", entity, percentage);
|
|
|
|
|
commands.entity(entity).remove::<Dissolving>();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// If animation is done, remove dissolving component
|
|
|
|
|
if percentage <= 0.0 || percentage >= 1.0 {
|
|
|
|
|
info!(
|
|
|
|
|
"Removing dissolving from {:?} with percentage {:?}",
|
|
|
|
|
entity, percentage
|
|
|
|
|
);
|
|
|
|
|
commands.entity(entity).remove::<Dissolving>();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|