|
|
|
|
@ -14,6 +14,7 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
))
|
|
|
|
|
.init_state::<DissolvingAnimation>()
|
|
|
|
|
.init_resource::<PiecePointer>()
|
|
|
|
|
.insert_resource(AnimationSpeed(1.0))
|
|
|
|
|
.insert_resource(Msaa::Off)
|
|
|
|
|
.insert_resource(AmbientLight {
|
|
|
|
|
color: Color::WHITE,
|
|
|
|
|
@ -91,15 +92,19 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
put_down.run_if(any_component_removed::<game::Selected>()),
|
|
|
|
|
dissolve_animation.run_if(any_with_component::<Dissolving>),
|
|
|
|
|
capture_piece.run_if(any_with_component::<game::Captured>),
|
|
|
|
|
skip_animation
|
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
|
.run_if(pressed(KeyCode::Enter).or_else(pressed(MouseButton::Left))),
|
|
|
|
|
un_skip_animation.run_if(in_state(GameState::Play)).run_if(
|
|
|
|
|
just_released(KeyCode::Enter).or_else(just_released(MouseButton::Left)),
|
|
|
|
|
),
|
|
|
|
|
monitor_animations
|
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
|
.run_if(any_component_changed::<AnimationPlayer>()),
|
|
|
|
|
set_animation_player_speed
|
|
|
|
|
.run_if(any_component_added::<Animating>()
|
|
|
|
|
.or_else(resource_changed::<AnimationSpeed>)),
|
|
|
|
|
set_animation_speed
|
|
|
|
|
.run_if(
|
|
|
|
|
just_pressed(KeyCode::Enter)
|
|
|
|
|
.or_else(just_pressed(MouseButton::Left))
|
|
|
|
|
.or_else(just_released(KeyCode::Enter))
|
|
|
|
|
.or_else(just_released(MouseButton::Left))
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
@ -128,25 +133,25 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
(
|
|
|
|
|
// Toggle hidden/visible 3d entities
|
|
|
|
|
manage_state_entities::<DisplayState>(),
|
|
|
|
|
// fixup_shadows,
|
|
|
|
|
color_grading_tweak.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
fog_tweak.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
bloom_tweak.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
update_pieces.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
(
|
|
|
|
|
setup_dissolve_materials
|
|
|
|
|
.run_if(in_state(GameState::Intro))
|
|
|
|
|
.run_if(
|
|
|
|
|
any_component_added::<Handle<StandardMaterial>>()
|
|
|
|
|
.or_else(any_component_changed::<Handle<StandardMaterial>>()),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
OnEnter(GameState::Play),
|
|
|
|
|
(
|
|
|
|
|
update_pieces.run_if(resource_exists::<tweak::GameTweaks>),
|
|
|
|
|
opening_animation
|
|
|
|
|
.run_if(run_once())
|
|
|
|
|
.run_if(in_state(DisplayState::Display3d)),
|
|
|
|
|
@ -154,7 +159,10 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
OnEnter(GameState::Title),
|
|
|
|
|
(fixup_shadows, intro_title_dissolve),
|
|
|
|
|
(
|
|
|
|
|
intro_title_dissolve,
|
|
|
|
|
fixup_shadows
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.add_systems(OnExit(GameState::Title), outro_title_dissolve)
|
|
|
|
|
.add_systems(
|
|
|
|
|
@ -193,6 +201,9 @@ enum DissolvingAnimation {
|
|
|
|
|
Out,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Resource)]
|
|
|
|
|
struct AnimationSpeed(f32);
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Resource, Clone)]
|
|
|
|
|
struct AssetsMap {
|
|
|
|
|
hitbox_shape: Handle<Mesh>,
|
|
|
|
|
@ -992,26 +1003,32 @@ fn opening_animation(mut players: Query<&mut AnimationPlayer, (With<Camera>, Wit
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// When called skips any running animations
|
|
|
|
|
fn skip_animation(
|
|
|
|
|
mut players: Query<&mut AnimationPlayer, With<Animating>>,
|
|
|
|
|
|
|
|
|
|
fn set_animation_speed(
|
|
|
|
|
mut animation_speed: ResMut<AnimationSpeed>,
|
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
|
keys: Res<ButtonInput<KeyCode>>,
|
|
|
|
|
mouse: Res<ButtonInput<MouseButton>>,
|
|
|
|
|
) {
|
|
|
|
|
animation_speed.0 = if keys.pressed(KeyCode::Enter) || mouse.pressed(MouseButton::Left) {
|
|
|
|
|
let tweak = tweaks
|
|
|
|
|
.get(tweaks_file.handle.clone())
|
|
|
|
|
.expect("Load tweakfile");
|
|
|
|
|
let speed = tweak.get::<f32>("animation_fast_speed").unwrap();
|
|
|
|
|
players.iter_mut().for_each(|mut p| {
|
|
|
|
|
debug!("Skipping animation");
|
|
|
|
|
p.set_speed(speed);
|
|
|
|
|
})
|
|
|
|
|
speed
|
|
|
|
|
} else {
|
|
|
|
|
1.0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn un_skip_animation(mut players: Query<&mut AnimationPlayer, With<Animating>>) {
|
|
|
|
|
// When an animation starts, or the animation speed changes, update player speed
|
|
|
|
|
fn set_animation_player_speed(
|
|
|
|
|
mut players: Query<&mut AnimationPlayer, With<Animating>>,
|
|
|
|
|
animation_speed: Res<AnimationSpeed>,
|
|
|
|
|
) {
|
|
|
|
|
players.iter_mut().for_each(|mut p| {
|
|
|
|
|
debug!("Un-Skipping animation");
|
|
|
|
|
p.set_speed(1.0);
|
|
|
|
|
p.set_speed(animation_speed.0);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -1093,7 +1110,7 @@ fn setup_dissolve_materials(
|
|
|
|
|
.filter(|(child, _, _)| query.iter_many(parents.iter_ancestors(*child)).count() > 0)
|
|
|
|
|
// Handle this entity (mesh)
|
|
|
|
|
.for_each(|(child, std_handle, name)| {
|
|
|
|
|
debug!("Setting up dissolve material for {:?} {:?}", name, child);
|
|
|
|
|
info!("Setting up dissolve material for {:?} {:?}", name, child);
|
|
|
|
|
|
|
|
|
|
// Get dissolvable data for percentage start
|
|
|
|
|
let dissolvable = query
|
|
|
|
|
@ -1139,6 +1156,8 @@ fn capture_piece(
|
|
|
|
|
mut state: Local<Option<game::CaptureFlow>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
score: Res<game::Score>,
|
|
|
|
|
mut timer: Local<f32>,
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
) {
|
|
|
|
|
match *state {
|
|
|
|
|
// State is None, so we need to initiate the animation
|
|
|
|
|
@ -1158,11 +1177,16 @@ fn capture_piece(
|
|
|
|
|
game::CaptureFlow::FadeOut(_entity) => {
|
|
|
|
|
// Wait for fade-out animation
|
|
|
|
|
// If all pieces are done dissolving
|
|
|
|
|
if dissolving.is_empty() {
|
|
|
|
|
if dissolving.is_empty() && *timer >= 3.0 {
|
|
|
|
|
debug!("Nothing dissolving, moving on to next step!");
|
|
|
|
|
// reset the timer
|
|
|
|
|
*timer = 0.0;
|
|
|
|
|
|
|
|
|
|
// Move to next state now that animation is done
|
|
|
|
|
*state = s.next();
|
|
|
|
|
// This takes effect after updating all children
|
|
|
|
|
} else {
|
|
|
|
|
*timer += time.delta_seconds();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
game::CaptureFlow::Store(entity) => {
|
|
|
|
|
@ -1295,45 +1319,34 @@ fn dissolve_animation(
|
|
|
|
|
mut dissolve_materials: ResMut<Assets<DissolveMaterial>>,
|
|
|
|
|
object_materials: Query<(Entity, &Handle<DissolveMaterial>)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
keys: Res<ButtonInput<KeyCode>>,
|
|
|
|
|
mouse: Res<ButtonInput<MouseButton>>,
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
mut next: ResMut<NextState<DissolvingAnimation>>,
|
|
|
|
|
animation_speed: Res<AnimationSpeed>,
|
|
|
|
|
) {
|
|
|
|
|
query
|
|
|
|
|
.iter_mut()
|
|
|
|
|
.for_each(|(entity, dissolvable, mut dissolving)| {
|
|
|
|
|
debug!("Entity {:?} has Dissolving {:?}", entity, dissolving);
|
|
|
|
|
|
|
|
|
|
let skip = keys.just_pressed(KeyCode::Enter) || mouse.just_pressed(MouseButton::Left);
|
|
|
|
|
|
|
|
|
|
let percentage = match *dissolving {
|
|
|
|
|
Dissolving::In(mut sec) => {
|
|
|
|
|
if skip {
|
|
|
|
|
1.0
|
|
|
|
|
} else {
|
|
|
|
|
// Check if seconds is below 0.0
|
|
|
|
|
sec = (sec - time.delta_seconds()).max(0.0);
|
|
|
|
|
sec = (sec - (time.delta_seconds() * animation_speed.0)).max(0.0);
|
|
|
|
|
|
|
|
|
|
*dissolving = Dissolving::In(sec);
|
|
|
|
|
|
|
|
|
|
// Calculate the target percentage value
|
|
|
|
|
1.0 - (sec / dissolvable.duration)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Dissolving::Out(mut sec) => {
|
|
|
|
|
if skip {
|
|
|
|
|
0.0
|
|
|
|
|
} else {
|
|
|
|
|
// Check if seconds is below 0.0
|
|
|
|
|
sec = (sec - time.delta_seconds()).max(0.0);
|
|
|
|
|
sec = (sec - (time.delta_seconds() * animation_speed.0)).max(0.0);
|
|
|
|
|
|
|
|
|
|
*dissolving = Dissolving::Out(sec);
|
|
|
|
|
|
|
|
|
|
// Calculate the target percentage value
|
|
|
|
|
sec / dissolvable.duration
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
object_materials
|
|
|
|
|
@ -1364,7 +1377,7 @@ fn fixup_shadows(
|
|
|
|
|
mut point_lights: Query<&mut PointLight>,
|
|
|
|
|
mut directional_lights: Query<&mut DirectionalLight>,
|
|
|
|
|
) {
|
|
|
|
|
debug!("Fixing up shadows");
|
|
|
|
|
info!("Fixing up shadows");
|
|
|
|
|
spot_lights.iter_mut().for_each(|mut l| {
|
|
|
|
|
l.shadows_enabled = true;
|
|
|
|
|
});
|
|
|
|
|
|