|
|
|
@ -78,8 +78,9 @@ impl Plugin for Display3dPlugin {
|
|
|
|
.run_if(
|
|
|
|
.run_if(
|
|
|
|
in_state(debug::DebugState::Enabled)
|
|
|
|
in_state(debug::DebugState::Enabled)
|
|
|
|
.and_then(on_event::<MouseMotion>())
|
|
|
|
.and_then(on_event::<MouseMotion>())
|
|
|
|
.or_else(just_pressed(MouseButton::Left))
|
|
|
|
.or_else(just_pressed(MouseButton::Left)),
|
|
|
|
).before(select),
|
|
|
|
)
|
|
|
|
|
|
|
|
.before(select),
|
|
|
|
select
|
|
|
|
select
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
.run_if(in_state(DisplayState::Display3d))
|
|
|
|
.run_if(in_state(DisplayState::Display3d))
|
|
|
|
@ -118,7 +119,7 @@ impl Plugin for Display3dPlugin {
|
|
|
|
(
|
|
|
|
(
|
|
|
|
animate_title_light_in.run_if(in_state(DissolvingAnimation::In)),
|
|
|
|
animate_title_light_in.run_if(in_state(DissolvingAnimation::In)),
|
|
|
|
animate_title_light_out.run_if(in_state(DissolvingAnimation::Out)),
|
|
|
|
animate_title_light_out.run_if(in_state(DissolvingAnimation::Out)),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
OnEnter(GameState::Intro),
|
|
|
|
OnEnter(GameState::Intro),
|
|
|
|
@ -133,11 +134,12 @@ impl Plugin for Display3dPlugin {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
Update,
|
|
|
|
setup_dissolve_materials.run_if(in_state(GameState::Intro))
|
|
|
|
setup_dissolve_materials
|
|
|
|
|
|
|
|
.run_if(in_state(GameState::Intro))
|
|
|
|
.run_if(
|
|
|
|
.run_if(
|
|
|
|
any_component_added::<Handle<StandardMaterial>>()
|
|
|
|
any_component_added::<Handle<StandardMaterial>>()
|
|
|
|
.or_else(any_component_changed::<Handle<StandardMaterial>>()),
|
|
|
|
.or_else(any_component_changed::<Handle<StandardMaterial>>()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
OnEnter(GameState::Play),
|
|
|
|
OnEnter(GameState::Play),
|
|
|
|
@ -186,7 +188,7 @@ enum DissolvingAnimation {
|
|
|
|
#[default]
|
|
|
|
#[default]
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
In,
|
|
|
|
In,
|
|
|
|
Out
|
|
|
|
Out,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Resource, Clone)]
|
|
|
|
#[derive(Debug, Resource, Clone)]
|
|
|
|
@ -487,7 +489,10 @@ fn set_board_model(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn set_title_model(
|
|
|
|
fn set_title_model(
|
|
|
|
mut titles: Query<(&mut Handle<Scene>, &mut Transform, &mut Visibility), (Added<TitleText>, With<Display3d>)>,
|
|
|
|
mut titles: Query<
|
|
|
|
|
|
|
|
(&mut Handle<Scene>, &mut Transform, &mut Visibility),
|
|
|
|
|
|
|
|
(Added<TitleText>, With<Display3d>),
|
|
|
|
|
|
|
|
>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
@ -495,29 +500,31 @@ fn set_title_model(
|
|
|
|
let tweak = tweaks
|
|
|
|
let tweak = tweaks
|
|
|
|
.get(tweaks_file.handle.clone())
|
|
|
|
.get(tweaks_file.handle.clone())
|
|
|
|
.expect("Load tweakfile");
|
|
|
|
.expect("Load tweakfile");
|
|
|
|
titles.iter_mut().for_each(|(mut handle, mut transform, mut visibility)| {
|
|
|
|
titles
|
|
|
|
info!("Setting title model");
|
|
|
|
.iter_mut()
|
|
|
|
let assets_handle = tweak
|
|
|
|
.for_each(|(mut handle, mut transform, mut visibility)| {
|
|
|
|
.get_handle::<Gltf>("display3d_models_assets_file")
|
|
|
|
info!("Setting title model");
|
|
|
|
.unwrap();
|
|
|
|
let assets_handle = tweak
|
|
|
|
let gltf = gltfs.get(assets_handle).expect("Load GLTF content");
|
|
|
|
.get_handle::<Gltf>("display3d_models_assets_file")
|
|
|
|
*handle = gltf
|
|
|
|
.unwrap();
|
|
|
|
.named_scenes
|
|
|
|
let gltf = gltfs.get(assets_handle).expect("Load GLTF content");
|
|
|
|
.get(
|
|
|
|
*handle = gltf
|
|
|
|
tweak
|
|
|
|
.named_scenes
|
|
|
|
.get::<String>("display3d_models_scenes_title")
|
|
|
|
.get(
|
|
|
|
.unwrap()
|
|
|
|
tweak
|
|
|
|
.as_str(),
|
|
|
|
.get::<String>("display3d_models_scenes_title")
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.expect("Game title model")
|
|
|
|
.as_str(),
|
|
|
|
.clone();
|
|
|
|
)
|
|
|
|
|
|
|
|
.expect("Game title model")
|
|
|
|
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
|
|
|
|
transform.translation -= Vec3::Y * 0.5;
|
|
|
|
transform.translation -= Vec3::Y * 0.5;
|
|
|
|
transform.rotate_local_z(std::f32::consts::PI);
|
|
|
|
transform.rotate_local_z(std::f32::consts::PI);
|
|
|
|
transform.rotate_local_y(std::f32::consts::PI / 2.0);
|
|
|
|
transform.rotate_local_y(std::f32::consts::PI / 2.0);
|
|
|
|
|
|
|
|
|
|
|
|
*visibility = Visibility::Hidden;
|
|
|
|
*visibility = Visibility::Hidden;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Given a board index returns the Vec3 location in space
|
|
|
|
/// Given a board index returns the Vec3 location in space
|
|
|
|
@ -682,8 +689,8 @@ fn select(
|
|
|
|
selections.send(game::Selection(**board_index));
|
|
|
|
selections.send(game::Selection(**board_index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_ => ()
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -724,24 +731,21 @@ fn entity_pointer(
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.filter_map(|(entity, hit)| {
|
|
|
|
.filter_map(|(entity, hit)| {
|
|
|
|
// Find this entity in the set of selectable entities
|
|
|
|
// Find this entity in the set of selectable entities
|
|
|
|
selectable
|
|
|
|
selectable.iter().find_map(|e| {
|
|
|
|
.iter()
|
|
|
|
let hit_check = {
|
|
|
|
.find_map(|e| {
|
|
|
|
// This entity was hit (tile hitboxes)
|
|
|
|
let hit_check = {
|
|
|
|
let primary = entity == e;
|
|
|
|
// This entity was hit (tile hitboxes)
|
|
|
|
|
|
|
|
let primary = entity == e;
|
|
|
|
// A child was hit (pieces)
|
|
|
|
|
|
|
|
let secondary =
|
|
|
|
// A child was hit (pieces)
|
|
|
|
children.iter_descendants(e).any(|child| child == entity);
|
|
|
|
let secondary = children
|
|
|
|
|
|
|
|
.iter_descendants(e)
|
|
|
|
primary || secondary
|
|
|
|
.any(|child| child == entity);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
primary || secondary
|
|
|
|
// Return the board index of this piece
|
|
|
|
};
|
|
|
|
hit_check.then_some((e, hit.clone()))
|
|
|
|
|
|
|
|
})
|
|
|
|
// Return the board index of this piece
|
|
|
|
|
|
|
|
hit_check.then_some((e, hit.clone()))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// Compare the distance of all hits, choosing the closest one
|
|
|
|
// Compare the distance of all hits, choosing the closest one
|
|
|
|
.min_by(|(_, hit_a), (_, hit_b)| {
|
|
|
|
.min_by(|(_, hit_a), (_, hit_b)| {
|
|
|
|
@ -840,11 +844,12 @@ fn pick_up(
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
info!(" Child: {:?}", child);
|
|
|
|
info!(" Child: {:?}", child);
|
|
|
|
if let Ok((name, mut player)) = players.get_mut(child) {
|
|
|
|
if let Ok((name, mut player)) = players.get_mut(child) {
|
|
|
|
let pickup_animation = format!(
|
|
|
|
let pickup_animation =
|
|
|
|
"display3d_models_animations_pick_up_{}",
|
|
|
|
format!("display3d_models_animations_pick_up_{}", name.as_str(),);
|
|
|
|
name.as_str(),
|
|
|
|
info!(
|
|
|
|
|
|
|
|
"Picking up {:?} ({:?}) {:?} {:?}",
|
|
|
|
|
|
|
|
name, entity, piece, pickup_animation
|
|
|
|
);
|
|
|
|
);
|
|
|
|
info!("Picking up {:?} ({:?}) {:?} {:?}", name, entity, piece, pickup_animation);
|
|
|
|
|
|
|
|
let pickup_handle = gltf
|
|
|
|
let pickup_handle = gltf
|
|
|
|
.named_animations
|
|
|
|
.named_animations
|
|
|
|
.get(
|
|
|
|
.get(
|
|
|
|
@ -854,10 +859,7 @@ fn pick_up(
|
|
|
|
.as_str(),
|
|
|
|
.as_str(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.expect("Pickup Animation");
|
|
|
|
.expect("Pickup Animation");
|
|
|
|
let idle_animation = format!(
|
|
|
|
let idle_animation = format!("display3d_models_animations_idle_{}", name.as_str());
|
|
|
|
"display3d_models_animations_idle_{}",
|
|
|
|
|
|
|
|
name.as_str()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
let idle_handle = gltf
|
|
|
|
let idle_handle = gltf
|
|
|
|
.named_animations
|
|
|
|
.named_animations
|
|
|
|
.get(
|
|
|
|
.get(
|
|
|
|
@ -890,10 +892,7 @@ fn pick_up(
|
|
|
|
|
|
|
|
|
|
|
|
fn put_down(
|
|
|
|
fn put_down(
|
|
|
|
mut events: RemovedComponents<game::Selected>,
|
|
|
|
mut events: RemovedComponents<game::Selected>,
|
|
|
|
mut query: Query<
|
|
|
|
mut query: Query<Entity, (With<game::Piece>, With<game::Selectable>, With<Display3d>)>,
|
|
|
|
Entity,
|
|
|
|
|
|
|
|
(With<game::Piece>, With<game::Selectable>, With<Display3d>),
|
|
|
|
|
|
|
|
>,
|
|
|
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
children: Query<&Children>,
|
|
|
|
children: Query<&Children>,
|
|
|
|
mut players: Query<(&Name, &mut AnimationPlayer)>,
|
|
|
|
mut players: Query<(&Name, &mut AnimationPlayer)>,
|
|
|
|
@ -915,7 +914,8 @@ fn put_down(
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
if let Ok((name, mut player)) = players.get_mut(child) {
|
|
|
|
if let Ok((name, mut player)) = players.get_mut(child) {
|
|
|
|
info!("Putting down {:?}", entity);
|
|
|
|
info!("Putting down {:?}", entity);
|
|
|
|
let putdown_animation = format!("display3d_models_animations_put_down_{}", name.as_str());
|
|
|
|
let putdown_animation =
|
|
|
|
|
|
|
|
format!("display3d_models_animations_put_down_{}", name.as_str());
|
|
|
|
let putdown_handle = gltf
|
|
|
|
let putdown_handle = gltf
|
|
|
|
.named_animations
|
|
|
|
.named_animations
|
|
|
|
.get(
|
|
|
|
.get(
|
|
|
|
@ -935,7 +935,10 @@ fn put_down(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.set_repeat(RepeatAnimation::Never);
|
|
|
|
.set_repeat(RepeatAnimation::Never);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
info!("Clip {:?}({:?}) not compatible with {:?}", putdown_animation, putdown_clip, name);
|
|
|
|
info!(
|
|
|
|
|
|
|
|
"Clip {:?}({:?}) not compatible with {:?}",
|
|
|
|
|
|
|
|
putdown_animation, putdown_clip, name
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
info!("Clip not found");
|
|
|
|
info!("Clip not found");
|
|
|
|
@ -1481,4 +1484,4 @@ fn animate_title_light_out(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|