|
|
|
|
@ -61,8 +61,9 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
any_component_added::<DirectionalLight>
|
|
|
|
|
.or_else(any_component_added::<SpotLight>)
|
|
|
|
|
.or_else(any_component_added::<PointLight>)
|
|
|
|
|
.or_else(on_event::<AssetEvent<Tweaks>>())
|
|
|
|
|
.or_else(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
|
),
|
|
|
|
|
capture_piece.run_if(any_with_component::<game::Captured>()),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
@ -473,6 +474,26 @@ fn board_translation(&BoardIndex { x, y }: &BoardIndex) -> Vec3 {
|
|
|
|
|
Vec3::new(x, 0.0, y)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn capture_translation(side: &Side, num: usize) -> Vec3 {
|
|
|
|
|
info!("Side: {:?} Num: {:?}", side, num);
|
|
|
|
|
match side {
|
|
|
|
|
Side::B => {
|
|
|
|
|
let x = -((num % 4) as f32 * 1.3 + 4.0); // mod(num, 4)
|
|
|
|
|
let z = (num / 4) as f32 * 1.3 + 4.0; // floor(div(num, 4))
|
|
|
|
|
let y = -1.3;
|
|
|
|
|
info!("Vec3({}, {}, {})", x, y, z);
|
|
|
|
|
Vec3::new(x, y, z)
|
|
|
|
|
},
|
|
|
|
|
Side::A => {
|
|
|
|
|
let x = (num % 4) as f32 * 1.3 + 4.0; // mod(num, 4)
|
|
|
|
|
let z = -((num / 4) as f32 * 1.3 + 4.0); // floor(div(num, 4))
|
|
|
|
|
let y = -1.3;
|
|
|
|
|
info!("Vec3({}, {}, {})", x, y, z);
|
|
|
|
|
Vec3::new(x, y, z)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn gizmo_system(mut gizmos: Gizmos) {
|
|
|
|
|
for y in 0..4 {
|
|
|
|
|
for x in 0..8 {
|
|
|
|
|
@ -786,6 +807,7 @@ fn moves_gizmo(
|
|
|
|
|
|
|
|
|
|
/// Spawn 3d "Valid move" indicators when a piece is selected
|
|
|
|
|
/// Another system registers these new entities and associates the correct models and plays animations.
|
|
|
|
|
/// TODO: Do not create/delete entities at runtime
|
|
|
|
|
fn create_valid_move_entity(
|
|
|
|
|
events: Query<&BoardIndex, (With<game::Piece>, Added<game::Selected>, With<Display3d>)>,
|
|
|
|
|
board: Res<Board>,
|
|
|
|
|
@ -841,7 +863,7 @@ fn _play_valid_move_animation(_players: Query<&AnimationPlayer>) {
|
|
|
|
|
todo!();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Move this to game.rs
|
|
|
|
|
// TODO: Do not create/delete entities at runtime
|
|
|
|
|
/// Remove "Valid Move" indicators when a piece is de-selected
|
|
|
|
|
fn remove_valid_move_entity(
|
|
|
|
|
mut events: RemovedComponents<game::Selected>,
|
|
|
|
|
@ -1025,7 +1047,7 @@ fn scale_lighting(
|
|
|
|
|
|
|
|
|
|
let directional_tweak = tweak.get::<f32>("display3d_lights_scaling_directional").expect("Directional lighting scalar");
|
|
|
|
|
directional.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
|
info!("Scaling directional light {:?}", entity);
|
|
|
|
|
debug!("Scaling directional light {:?}", entity);
|
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
|
val.illuminance = v.illuminance * directional_tweak;
|
|
|
|
|
} else {
|
|
|
|
|
@ -1036,7 +1058,7 @@ fn scale_lighting(
|
|
|
|
|
|
|
|
|
|
let spot_tweak = tweak.get::<f32>("display3d_lights_scaling_spot").expect("Spot lighting scalar");
|
|
|
|
|
spot.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
|
info!("Scaling spot light {:?}", entity);
|
|
|
|
|
debug!("Scaling spot light {:?}", entity);
|
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
|
val.intensity = v.intensity * spot_tweak;
|
|
|
|
|
} else {
|
|
|
|
|
@ -1047,7 +1069,7 @@ fn scale_lighting(
|
|
|
|
|
|
|
|
|
|
let point_tweak = tweak.get::<f32>("display3d_lights_scaling_point").expect("Point lighting scalar");
|
|
|
|
|
point.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
|
info!("Scaling point light {:?}", entity);
|
|
|
|
|
debug!("Scaling point light {:?}", entity);
|
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
|
val.intensity = v.intensity * point_tweak;
|
|
|
|
|
} else {
|
|
|
|
|
@ -1223,3 +1245,73 @@ pub(super) mod tweaks {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// When a piece is captured...
|
|
|
|
|
/// 1. Play a cool "captured" animation and a neat sound
|
|
|
|
|
/// 2. Move the piece to the side of the board
|
|
|
|
|
/// 3. Play the same "captured" animation in reverse
|
|
|
|
|
/// The animation is like a 'beam me up scotty' sorta thing.
|
|
|
|
|
fn capture_piece(
|
|
|
|
|
mut events: Query<Entity, (With<Display3d>, Added<game::Captured>)>,
|
|
|
|
|
mut query: Query<(&mut Visibility, &mut Transform, &Side), (With<Display3d>, With<game::Captured>)>,
|
|
|
|
|
mut state: Local<Option<game::CaptureFlow>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
match *state {
|
|
|
|
|
Some(s) => {
|
|
|
|
|
match s {
|
|
|
|
|
game::CaptureFlow::FadeOut(entity) => {
|
|
|
|
|
let (mut v, _, _) = query
|
|
|
|
|
.get_mut(entity)
|
|
|
|
|
.expect("Visibility and Transform of captured piece");
|
|
|
|
|
|
|
|
|
|
// Play fade-out animation
|
|
|
|
|
{
|
|
|
|
|
error!("Run fade-out animation");
|
|
|
|
|
|
|
|
|
|
// Move to next state now that animation is done
|
|
|
|
|
*state = s.next();
|
|
|
|
|
|
|
|
|
|
// Hide piece now that animation is done
|
|
|
|
|
*v = Visibility::Hidden;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
game::CaptureFlow::Store(entity) => {
|
|
|
|
|
let (_, mut t, side) = query
|
|
|
|
|
.get_mut(entity)
|
|
|
|
|
.expect("Visibility and Transform of captured piece");
|
|
|
|
|
|
|
|
|
|
// Move piece to next spot at side of table
|
|
|
|
|
error!("Move piece to side of table");
|
|
|
|
|
// TODO: Dynamic number based on side's score
|
|
|
|
|
t.translation = capture_translation(side, 1);
|
|
|
|
|
|
|
|
|
|
*state = s.next();
|
|
|
|
|
},
|
|
|
|
|
game::CaptureFlow::FadeIn(entity) => {
|
|
|
|
|
let (mut v, _, _) = query
|
|
|
|
|
.get_mut(entity)
|
|
|
|
|
.expect("Visibility and Transform of captured piece");
|
|
|
|
|
|
|
|
|
|
// Show piece now that it is moved
|
|
|
|
|
*v = Visibility::Inherited;
|
|
|
|
|
|
|
|
|
|
// Play fade-in animation
|
|
|
|
|
{
|
|
|
|
|
error!("Run fade-in animation");
|
|
|
|
|
// When animation is done, move to next phase of flow
|
|
|
|
|
*state = s.next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove the captured component for bookkeeping
|
|
|
|
|
commands.entity(entity).remove::<game::Captured>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
None => {
|
|
|
|
|
*state = events.iter().next().map(|entity| {
|
|
|
|
|
game::CaptureFlow::FadeOut(entity)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|