|
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
|
|
|
|
prelude::*,
|
|
|
|
|
};
|
|
|
|
|
use bevy::{
|
|
|
|
|
animation::RepeatAnimation,
|
|
|
|
|
core_pipeline::{tonemapping::DebandDither, Skybox},
|
|
|
|
|
input::mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel},
|
|
|
|
|
render::{
|
|
|
|
|
@ -169,16 +170,18 @@ fn hydrate_camera(
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
state: Res<State<game::TurnState>>,
|
|
|
|
|
_clips: Res<Assets<AnimationClip>>,
|
|
|
|
|
mut players: Query<&mut AnimationPlayer>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
events
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(|(name, _)| name.as_str() == "GameCam")
|
|
|
|
|
.for_each(|(_, entity)| {
|
|
|
|
|
.find(|(name, _)| name.as_str() == "GameCam")
|
|
|
|
|
.iter()
|
|
|
|
|
.for_each(|(_name, entity)| {
|
|
|
|
|
info!("Initialize 3d camera");
|
|
|
|
|
// Populate the components for the camera
|
|
|
|
|
commands.entity(entity).insert((
|
|
|
|
|
commands.entity(*entity).insert((
|
|
|
|
|
Display3d,
|
|
|
|
|
DisplayState::Display3d,
|
|
|
|
|
Camera3dBundle {
|
|
|
|
|
@ -207,15 +210,19 @@ fn hydrate_camera(
|
|
|
|
|
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
// Set it to the default position by starting the initial animation
|
|
|
|
|
if let Ok(mut player) = players.get_mut(entity) {
|
|
|
|
|
if let Ok(mut player) = players.get_mut(*entity) {
|
|
|
|
|
debug!("Animations: {:?}", gltf.named_animations.keys());
|
|
|
|
|
// GameCamIntro1, GameCamIntro2, GameCamSide1>2, GameCamSide2>1
|
|
|
|
|
info!("Animation 1: {:?}", _clips.get(gltf.named_animations.get("GameCamIntro1").unwrap()));
|
|
|
|
|
info!("Animation 2: {:?}", _clips.get(gltf.named_animations.get("GameCamIntro2").unwrap()));
|
|
|
|
|
let animation = match state.get() {
|
|
|
|
|
game::TurnState::SideA => gltf.named_animations.get("GameCamIntro1"),
|
|
|
|
|
game::TurnState::SideB => gltf.named_animations.get("GameCamIntro2"),
|
|
|
|
|
};
|
|
|
|
|
}.expect("Camera startup");
|
|
|
|
|
info!("Compatible: {:?}", _clips.get(animation).unwrap().compatible_with(_name));
|
|
|
|
|
info!("Entity: {:?}", *entity);
|
|
|
|
|
player
|
|
|
|
|
.play(animation.expect("Camera Startup").clone())
|
|
|
|
|
.play(animation.clone())
|
|
|
|
|
.pause();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
@ -318,7 +325,7 @@ fn move_camera(
|
|
|
|
|
mut events: EventReader<MouseMotion>,
|
|
|
|
|
mut camera: Query<&mut Transform, (With<Display3d>, With<Camera>)>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|MouseMotion { delta }| {
|
|
|
|
|
events.read().for_each(|MouseMotion { delta }| {
|
|
|
|
|
if buttons.pressed(MouseButton::Left) {
|
|
|
|
|
camera.iter_mut().for_each(|mut t| {
|
|
|
|
|
t.rotate_around(Vec3::ZERO, Quat::from_rotation_y(delta.x / 256.0));
|
|
|
|
|
@ -333,7 +340,7 @@ fn mouse_zoom(
|
|
|
|
|
mut events: EventReader<MouseWheel>,
|
|
|
|
|
mut camera: Query<&mut Transform, (With<Display3d>, With<Camera>)>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|MouseWheel { unit, y, .. }| {
|
|
|
|
|
events.read().for_each(|MouseWheel { unit, y, .. }| {
|
|
|
|
|
camera.iter_mut().for_each(|mut t| {
|
|
|
|
|
match unit {
|
|
|
|
|
MouseScrollUnit::Line => {
|
|
|
|
|
@ -480,7 +487,7 @@ fn select(
|
|
|
|
|
mut selections: EventWriter<game::Selection>,
|
|
|
|
|
) {
|
|
|
|
|
events
|
|
|
|
|
.iter()
|
|
|
|
|
.read()
|
|
|
|
|
.filter(|ev| ev.state == ButtonState::Pressed)
|
|
|
|
|
.for_each(|_| {
|
|
|
|
|
windows.iter().for_each(|window| {
|
|
|
|
|
@ -586,7 +593,7 @@ fn put_down(
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
mut players: Query<&mut AnimationPlayer>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|entity| {
|
|
|
|
|
events.read().for_each(|entity| {
|
|
|
|
|
if let Ok(_piece) = query.get_mut(entity) {
|
|
|
|
|
let gltf = gltfs.get(&assets_map.models).expect("Load GLTF content");
|
|
|
|
|
children.iter_descendants(entity).for_each(|child| {
|
|
|
|
|
@ -598,7 +605,7 @@ fn put_down(
|
|
|
|
|
animation.expect("PutDown Animation").clone(),
|
|
|
|
|
Duration::from_secs_f32(0.75),
|
|
|
|
|
)
|
|
|
|
|
.stop_repeating();
|
|
|
|
|
.set_repeat(RepeatAnimation::Never);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|