|
|
|
@ -12,9 +12,12 @@ use bevy::{
|
|
|
|
Skybox,
|
|
|
|
Skybox,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input::mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel},
|
|
|
|
input::mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel},
|
|
|
|
pbr::{ScreenSpaceAmbientOcclusionBundle, ScreenSpaceAmbientOcclusionSettings, MaterialExtension, ExtendedMaterial, OpaqueRendererMethod},
|
|
|
|
pbr::{
|
|
|
|
|
|
|
|
ExtendedMaterial, MaterialExtension, OpaqueRendererMethod,
|
|
|
|
|
|
|
|
ScreenSpaceAmbientOcclusionBundle, ScreenSpaceAmbientOcclusionSettings,
|
|
|
|
|
|
|
|
},
|
|
|
|
render::{
|
|
|
|
render::{
|
|
|
|
render_resource::{TextureViewDescriptor, TextureViewDimension, ShaderRef,AsBindGroup},
|
|
|
|
render_resource::{AsBindGroup, ShaderRef, TextureViewDescriptor, TextureViewDimension},
|
|
|
|
view::ColorGrading,
|
|
|
|
view::ColorGrading,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
window::PrimaryWindow,
|
|
|
|
window::PrimaryWindow,
|
|
|
|
@ -27,81 +30,89 @@ impl Plugin for Display3dPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_plugins((
|
|
|
|
app.add_plugins((
|
|
|
|
TemporalAntiAliasPlugin,
|
|
|
|
TemporalAntiAliasPlugin,
|
|
|
|
MaterialPlugin::<DissolveMaterial>::default(),
|
|
|
|
MaterialPlugin::<DissolveMaterial>::default(),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.insert_resource(Msaa::Off)
|
|
|
|
.insert_resource(Msaa::Off)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
(initialize, fix_skybox.before(initialize), update_tweaks.run_if(resource_exists::<tweak::GameTweaks>()),),
|
|
|
|
(
|
|
|
|
)
|
|
|
|
initialize,
|
|
|
|
.add_systems(
|
|
|
|
fix_skybox.before(initialize),
|
|
|
|
Update,
|
|
|
|
update_tweaks.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
(
|
|
|
|
),
|
|
|
|
load_assets
|
|
|
|
)
|
|
|
|
.run_if(in_state(GameState::Loading))
|
|
|
|
.add_systems(
|
|
|
|
.run_if(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
Update,
|
|
|
|
hydrate_camera.run_if(any_component_added::<Camera3d>),
|
|
|
|
(
|
|
|
|
set_piece_model.run_if(any_component_added::<Piece>),
|
|
|
|
load_assets
|
|
|
|
set_board_model.run_if(any_component_added::<game::BoardComponent>),
|
|
|
|
.run_if(in_state(GameState::Loading))
|
|
|
|
set_board_model.run_if(any_component_added::<TilesComponent>),
|
|
|
|
.run_if(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
set_valid_move_model.run_if(any_component_added::<game::ValidMove>),
|
|
|
|
hydrate_camera.run_if(any_component_added::<Camera3d>),
|
|
|
|
set_tile_hitbox.run_if(any_component_added::<game::Tile>),
|
|
|
|
set_piece_model.run_if(any_component_added::<Piece>),
|
|
|
|
set_piece_position.run_if(any_component_changed::<BoardIndex>),
|
|
|
|
set_board_model.run_if(any_component_added::<game::BoardComponent>),
|
|
|
|
set_piece_texture.run_if(any_component_changed::<Side>).run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
set_board_model.run_if(any_component_added::<TilesComponent>),
|
|
|
|
select
|
|
|
|
set_valid_move_model.run_if(any_component_added::<game::ValidMove>),
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
set_tile_hitbox.run_if(any_component_added::<game::Tile>),
|
|
|
|
.run_if(in_state(DisplayState::Display3d))
|
|
|
|
set_piece_position.run_if(any_component_changed::<BoardIndex>),
|
|
|
|
.run_if(on_event::<MouseButtonInput>()),
|
|
|
|
set_piece_texture
|
|
|
|
pick_up.run_if(any_component_added::<game::Selected>),
|
|
|
|
.run_if(any_component_changed::<Side>)
|
|
|
|
put_down.run_if(any_component_removed::<game::Selected>()),
|
|
|
|
.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
switch_sides
|
|
|
|
select
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
|
|
|
|
.run_if(state_changed::<game::TurnState>()),
|
|
|
|
|
|
|
|
update_tweaks.run_if(on_event::<AssetEvent<Tweaks>>()).run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
|
|
|
|
scale_lighting.run_if(
|
|
|
|
|
|
|
|
any_component_added::<DirectionalLight>
|
|
|
|
|
|
|
|
.or_else(any_component_added::<SpotLight>)
|
|
|
|
|
|
|
|
.or_else(any_component_added::<PointLight>)
|
|
|
|
|
|
|
|
.or_else(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
capture_piece.run_if(any_with_component::<game::Captured>()),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_systems(
|
|
|
|
|
|
|
|
Update,
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
move_camera.run_if(on_event::<MouseMotion>()),
|
|
|
|
|
|
|
|
mouse_zoom.run_if(on_event::<MouseWheel>()),
|
|
|
|
|
|
|
|
gizmo_system,
|
|
|
|
|
|
|
|
selected_gizmo,
|
|
|
|
|
|
|
|
moves_gizmo,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>())
|
|
|
|
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
.run_if(in_state(DisplayState::Display3d)),
|
|
|
|
.run_if(in_state(DisplayState::Display3d))
|
|
|
|
)
|
|
|
|
.run_if(on_event::<MouseButtonInput>()),
|
|
|
|
.add_systems(
|
|
|
|
pick_up.run_if(any_component_added::<game::Selected>),
|
|
|
|
OnEnter(DisplayState::Display3d),
|
|
|
|
put_down.run_if(any_component_removed::<game::Selected>()),
|
|
|
|
(
|
|
|
|
switch_sides
|
|
|
|
activate::<Display3d>,
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
set_piece_texture.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
.run_if(state_changed::<game::TurnState>()),
|
|
|
|
opening_animation
|
|
|
|
update_tweaks
|
|
|
|
.run_if(run_once())
|
|
|
|
.run_if(on_event::<AssetEvent<Tweaks>>())
|
|
|
|
.run_if(in_state(GameState::Play)),
|
|
|
|
.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
|
|
|
|
scale_lighting.run_if(
|
|
|
|
|
|
|
|
any_component_added::<DirectionalLight>
|
|
|
|
|
|
|
|
.or_else(any_component_added::<SpotLight>)
|
|
|
|
|
|
|
|
.or_else(any_component_added::<PointLight>)
|
|
|
|
|
|
|
|
.or_else(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
capture_piece.run_if(any_with_component::<game::Captured>()),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_systems(
|
|
|
|
|
|
|
|
Update,
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
move_camera.run_if(on_event::<MouseMotion>()),
|
|
|
|
|
|
|
|
mouse_zoom.run_if(on_event::<MouseWheel>()),
|
|
|
|
|
|
|
|
gizmo_system,
|
|
|
|
|
|
|
|
selected_gizmo,
|
|
|
|
|
|
|
|
moves_gizmo,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(OnExit(DisplayState::Display3d), deactivate::<Display3d>)
|
|
|
|
.run_if(resource_exists::<debug::DebugEnabled>())
|
|
|
|
.add_systems(
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
OnEnter(GameState::Play),
|
|
|
|
.run_if(in_state(DisplayState::Display3d)),
|
|
|
|
(
|
|
|
|
)
|
|
|
|
activate::<Display3d>.run_if(in_state(DisplayState::Display3d)),
|
|
|
|
.add_systems(
|
|
|
|
set_piece_texture,
|
|
|
|
OnEnter(DisplayState::Display3d),
|
|
|
|
update_tweaks.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
(
|
|
|
|
opening_animation
|
|
|
|
activate::<Display3d>,
|
|
|
|
.run_if(run_once())
|
|
|
|
set_piece_texture.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
.run_if(in_state(DisplayState::Display3d)),
|
|
|
|
opening_animation
|
|
|
|
),
|
|
|
|
.run_if(run_once())
|
|
|
|
);
|
|
|
|
.run_if(in_state(GameState::Play)),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_systems(OnExit(DisplayState::Display3d), deactivate::<Display3d>)
|
|
|
|
|
|
|
|
.add_systems(
|
|
|
|
|
|
|
|
OnEnter(GameState::Play),
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
activate::<Display3d>.run_if(in_state(DisplayState::Display3d)),
|
|
|
|
|
|
|
|
set_piece_texture,
|
|
|
|
|
|
|
|
update_tweaks.run_if(resource_exists::<tweak::GameTweaks>()),
|
|
|
|
|
|
|
|
opening_animation
|
|
|
|
|
|
|
|
.run_if(run_once())
|
|
|
|
|
|
|
|
.run_if(in_state(DisplayState::Display3d)),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -177,14 +188,14 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
|
|
|
|
));
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Valid move indicators
|
|
|
|
// Valid move indicators
|
|
|
|
game::tiles().for_each(|(index, _)| {
|
|
|
|
game::tiles().for_each(|(index, _)| {
|
|
|
|
let side = Board::side(index).expect("Spawn valid side");
|
|
|
|
let side = Board::side(index).expect("Spawn valid side");
|
|
|
|
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((
|
|
|
|
Display3d,
|
|
|
|
Display3d,
|
|
|
|
index,
|
|
|
|
index,
|
|
|
|
SceneBundle {
|
|
|
|
SceneBundle {
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
transform: Transform::from_translation(board_translation(&index)),
|
|
|
|
transform: Transform::from_translation(board_translation(&index)),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
@ -280,10 +291,9 @@ fn hydrate_camera(
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
.as_str(),
|
|
|
|
.as_str(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
}.expect("Camera Startup");
|
|
|
|
}
|
|
|
|
player
|
|
|
|
.expect("Camera Startup");
|
|
|
|
.play(animation.clone())
|
|
|
|
player.play(animation.clone()).pause();
|
|
|
|
.pause();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -738,7 +748,11 @@ fn select(
|
|
|
|
meshes: Res<Assets<Mesh>>,
|
|
|
|
meshes: Res<Assets<Mesh>>,
|
|
|
|
cameras: Query<(&Camera, &GlobalTransform)>,
|
|
|
|
cameras: Query<(&Camera, &GlobalTransform)>,
|
|
|
|
windows: Query<&Window, With<PrimaryWindow>>,
|
|
|
|
windows: Query<&Window, With<PrimaryWindow>>,
|
|
|
|
selectable: Query<(Entity, &BoardIndex, &Side, Option<&Piece>), (With<game::Selectable>, With<Display3d>)>,
|
|
|
|
selectable: Query<
|
|
|
|
|
|
|
|
(Entity, &BoardIndex, &Side),
|
|
|
|
|
|
|
|
(With<game::Selectable>, With<Display3d>),
|
|
|
|
|
|
|
|
>,
|
|
|
|
|
|
|
|
selected: Query<Entity, With<game::Selected>>,
|
|
|
|
children: Query<&Children>,
|
|
|
|
children: Query<&Children>,
|
|
|
|
mut selections: EventWriter<game::Selection>,
|
|
|
|
mut selections: EventWriter<game::Selection>,
|
|
|
|
state: Res<State<game::TurnState>>,
|
|
|
|
state: Res<State<game::TurnState>>,
|
|
|
|
@ -760,20 +774,24 @@ fn select(
|
|
|
|
hit::intersects3d(&ray, mesh, >).and_then(|_hit| {
|
|
|
|
hit::intersects3d(&ray, mesh, >).and_then(|_hit| {
|
|
|
|
selectable
|
|
|
|
selectable
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.find_map(|(e, &board_index, &side, piece_ish)| {
|
|
|
|
.find_map(|(e, &board_index, &side)| {
|
|
|
|
// Check if this piece is on the active side
|
|
|
|
// Check the side of the selection if no piece is selected
|
|
|
|
let side_check = piece_ish.is_some() && *state.get() == side;
|
|
|
|
// Otherwise this is fine, select away
|
|
|
|
|
|
|
|
let side_check = !selected.is_empty() || *state.get() == side;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let hit_check = {
|
|
|
|
|
|
|
|
// This entity was hit (tile hitboxes)
|
|
|
|
|
|
|
|
let primary = entity == e;
|
|
|
|
|
|
|
|
|
|
|
|
// This entity was hit (tile hitboxes)
|
|
|
|
// A child was hit (pieces)
|
|
|
|
let primary = entity == e;
|
|
|
|
let secondary = children
|
|
|
|
|
|
|
|
.iter_descendants(e)
|
|
|
|
|
|
|
|
.any(|child| child == entity);
|
|
|
|
|
|
|
|
|
|
|
|
// A child was hit (pieces)
|
|
|
|
primary || secondary
|
|
|
|
let secondary = children
|
|
|
|
};
|
|
|
|
.iter_descendants(e)
|
|
|
|
|
|
|
|
.any(|child| child == entity);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(side_check && (primary || secondary)).then_some(board_index)
|
|
|
|
(side_check && hit_check).then_some(board_index)
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.for_each(|&board_index| {
|
|
|
|
.for_each(|&board_index| {
|
|
|
|
@ -816,7 +834,10 @@ fn moves_gizmo(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn set_valid_move_model(
|
|
|
|
fn set_valid_move_model(
|
|
|
|
mut events: Query<(&mut Handle<Scene>, &mut Visibility), (With<Display3d>, Added<game::ValidMove>)>,
|
|
|
|
mut events: Query<
|
|
|
|
|
|
|
|
(&mut Handle<Scene>, &mut Visibility),
|
|
|
|
|
|
|
|
(With<Display3d>, Added<game::ValidMove>),
|
|
|
|
|
|
|
|
>,
|
|
|
|
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>,
|
|
|
|
@ -874,20 +895,28 @@ fn pick_up(
|
|
|
|
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) {
|
|
|
|
info!("Picking up {:?} ({:?}) {:?}", name, entity, piece);
|
|
|
|
info!("Picking up {:?} ({:?}) {:?}", name, entity, piece);
|
|
|
|
let pickup_animation = format!("display3d_models_animations_pick_up_{:?}", piece).to_ascii_lowercase();
|
|
|
|
let pickup_animation =
|
|
|
|
let pickup_handle = gltf.named_animations.get(
|
|
|
|
format!("display3d_models_animations_pick_up_{:?}", piece).to_ascii_lowercase();
|
|
|
|
tweak
|
|
|
|
let pickup_handle = gltf
|
|
|
|
.get::<String>(pickup_animation.as_str())
|
|
|
|
.named_animations
|
|
|
|
.unwrap()
|
|
|
|
.get(
|
|
|
|
.as_str(),
|
|
|
|
tweak
|
|
|
|
).expect("Pickup Animation");
|
|
|
|
.get::<String>(pickup_animation.as_str())
|
|
|
|
let idle_animation = format!("display3d_models_animations_idle_{:?}", piece).to_ascii_lowercase();
|
|
|
|
.unwrap()
|
|
|
|
let idle_handle = gltf.named_animations.get(
|
|
|
|
.as_str(),
|
|
|
|
tweak
|
|
|
|
)
|
|
|
|
.get::<String>(idle_animation.as_str())
|
|
|
|
.expect("Pickup Animation");
|
|
|
|
.unwrap()
|
|
|
|
let idle_animation =
|
|
|
|
.as_str(),
|
|
|
|
format!("display3d_models_animations_idle_{:?}", piece).to_ascii_lowercase();
|
|
|
|
).expect("Idle animation");
|
|
|
|
let idle_handle = gltf
|
|
|
|
|
|
|
|
.named_animations
|
|
|
|
|
|
|
|
.get(
|
|
|
|
|
|
|
|
tweak
|
|
|
|
|
|
|
|
.get::<String>(idle_animation.as_str())
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.as_str(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.expect("Idle animation");
|
|
|
|
if let Some(pickup_clip) = clips.get(pickup_handle) {
|
|
|
|
if let Some(pickup_clip) = clips.get(pickup_handle) {
|
|
|
|
if let Some(idle_clip) = clips.get(idle_handle) {
|
|
|
|
if let Some(idle_clip) = clips.get(idle_handle) {
|
|
|
|
if pickup_clip.compatible_with(name) && idle_clip.compatible_with(name) {
|
|
|
|
if pickup_clip.compatible_with(name) && idle_clip.compatible_with(name) {
|
|
|
|
@ -931,13 +960,18 @@ 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_{:?}", piece).to_ascii_lowercase();
|
|
|
|
let putdown_animation =
|
|
|
|
let putdown_handle = gltf.named_animations.get(
|
|
|
|
format!("display3d_models_animations_put_down_{:?}", piece)
|
|
|
|
tweak
|
|
|
|
.to_ascii_lowercase();
|
|
|
|
.get::<String>(putdown_animation.as_str())
|
|
|
|
let putdown_handle = gltf
|
|
|
|
.unwrap()
|
|
|
|
.named_animations
|
|
|
|
.as_str(),
|
|
|
|
.get(
|
|
|
|
).expect("PutDown Animation");
|
|
|
|
tweak
|
|
|
|
|
|
|
|
.get::<String>(putdown_animation.as_str())
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.as_str(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.expect("PutDown Animation");
|
|
|
|
if let Some(putdown_clip) = clips.get(putdown_handle) {
|
|
|
|
if let Some(putdown_clip) = clips.get(putdown_handle) {
|
|
|
|
if putdown_clip.compatible_with(name) {
|
|
|
|
if putdown_clip.compatible_with(name) {
|
|
|
|
player
|
|
|
|
player
|
|
|
|
@ -1006,7 +1040,11 @@ fn switch_sides(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn scale_lighting(
|
|
|
|
fn scale_lighting(
|
|
|
|
mut directional: Query<(Entity, &mut DirectionalLight, Option<&Original<DirectionalLight>>)>,
|
|
|
|
mut directional: Query<(
|
|
|
|
|
|
|
|
Entity,
|
|
|
|
|
|
|
|
&mut DirectionalLight,
|
|
|
|
|
|
|
|
Option<&Original<DirectionalLight>>,
|
|
|
|
|
|
|
|
)>,
|
|
|
|
mut spot: Query<(Entity, &mut SpotLight, Option<&Original<SpotLight>>)>,
|
|
|
|
mut spot: Query<(Entity, &mut SpotLight, Option<&Original<SpotLight>>)>,
|
|
|
|
mut point: Query<(Entity, &mut PointLight, Option<&Original<PointLight>>)>,
|
|
|
|
mut point: Query<(Entity, &mut PointLight, Option<&Original<PointLight>>)>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
@ -1017,18 +1055,24 @@ fn scale_lighting(
|
|
|
|
.get(tweaks_file.handle.clone())
|
|
|
|
.get(tweaks_file.handle.clone())
|
|
|
|
.expect("Load tweakfile");
|
|
|
|
.expect("Load tweakfile");
|
|
|
|
|
|
|
|
|
|
|
|
let directional_tweak = tweak.get::<f32>("display3d_lights_scaling_directional").expect("Directional lighting scalar");
|
|
|
|
let directional_tweak = tweak
|
|
|
|
directional.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
.get::<f32>("display3d_lights_scaling_directional")
|
|
|
|
debug!("Scaling directional light {:?}", entity);
|
|
|
|
.expect("Directional lighting scalar");
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
directional
|
|
|
|
val.illuminance = v.illuminance * directional_tweak;
|
|
|
|
.iter_mut()
|
|
|
|
} else {
|
|
|
|
.for_each(|(entity, mut val, original)| {
|
|
|
|
commands.entity(entity).insert(Original(val.clone()));
|
|
|
|
debug!("Scaling directional light {:?}", entity);
|
|
|
|
val.illuminance *= directional_tweak;
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
}
|
|
|
|
val.illuminance = v.illuminance * directional_tweak;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
commands.entity(entity).insert(Original(val.clone()));
|
|
|
|
|
|
|
|
val.illuminance *= directional_tweak;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let spot_tweak = tweak.get::<f32>("display3d_lights_scaling_spot").expect("Spot lighting scalar");
|
|
|
|
let spot_tweak = tweak
|
|
|
|
|
|
|
|
.get::<f32>("display3d_lights_scaling_spot")
|
|
|
|
|
|
|
|
.expect("Spot lighting scalar");
|
|
|
|
spot.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
spot.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
debug!("Scaling spot light {:?}", entity);
|
|
|
|
debug!("Scaling spot light {:?}", entity);
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
@ -1039,7 +1083,9 @@ fn scale_lighting(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let point_tweak = tweak.get::<f32>("display3d_lights_scaling_point").expect("Point lighting scalar");
|
|
|
|
let point_tweak = tweak
|
|
|
|
|
|
|
|
.get::<f32>("display3d_lights_scaling_point")
|
|
|
|
|
|
|
|
.expect("Point lighting scalar");
|
|
|
|
point.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
point.iter_mut().for_each(|(entity, mut val, original)| {
|
|
|
|
debug!("Scaling point light {:?}", entity);
|
|
|
|
debug!("Scaling point light {:?}", entity);
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
if let Some(Original(v)) = original {
|
|
|
|
@ -1224,14 +1270,14 @@ type DissolveMaterial = ExtendedMaterial<StandardMaterial, DissolveExtension>;
|
|
|
|
/// Material extension for dissolving effect
|
|
|
|
/// Material extension for dissolving effect
|
|
|
|
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
|
|
|
|
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)]
|
|
|
|
struct DissolveExtension {
|
|
|
|
struct DissolveExtension {
|
|
|
|
#[uniform(100)]
|
|
|
|
#[uniform(100)]
|
|
|
|
percentage: f32,
|
|
|
|
percentage: f32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl MaterialExtension for DissolveExtension {
|
|
|
|
impl MaterialExtension for DissolveExtension {
|
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
fn fragment_shader() -> ShaderRef {
|
|
|
|
"shaders/dissolve.wgsl".into()
|
|
|
|
"shaders/dissolve.wgsl".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Component for 'backing up' components which are temporarily not used
|
|
|
|
// Component for 'backing up' components which are temporarily not used
|
|
|
|
@ -1245,10 +1291,13 @@ struct Backup<T: Component>(T);
|
|
|
|
/// The animation is like a 'beam me up scotty' sorta thing.
|
|
|
|
/// The animation is like a 'beam me up scotty' sorta thing.
|
|
|
|
fn capture_piece(
|
|
|
|
fn capture_piece(
|
|
|
|
events: Query<Entity, (With<Display3d>, Added<game::Captured>)>,
|
|
|
|
events: Query<Entity, (With<Display3d>, Added<game::Captured>)>,
|
|
|
|
mut query: Query<(&mut Visibility, &mut Transform, &Side), (With<Display3d>, With<game::Captured>)>,
|
|
|
|
mut query: Query<
|
|
|
|
|
|
|
|
(&mut Visibility, &mut Transform, &Side),
|
|
|
|
|
|
|
|
(With<Display3d>, With<game::Captured>),
|
|
|
|
|
|
|
|
>,
|
|
|
|
mut state: Local<Option<game::CaptureFlow>>,
|
|
|
|
mut state: Local<Option<game::CaptureFlow>>,
|
|
|
|
standard_materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
standard_materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
mut dissolve_materials: ResMut<Assets<DissolveMaterial>>,
|
|
|
|
mut dissolve_materials: ResMut<Assets<DissolveMaterial>>,
|
|
|
|
object_standard_materials: Query<&Handle<StandardMaterial>>,
|
|
|
|
object_standard_materials: Query<&Handle<StandardMaterial>>,
|
|
|
|
object_dissolve_materials: Query<&Handle<DissolveMaterial>>,
|
|
|
|
object_dissolve_materials: Query<&Handle<DissolveMaterial>>,
|
|
|
|
backup_material: Query<&Backup<Handle<StandardMaterial>>>,
|
|
|
|
backup_material: Query<&Backup<Handle<StandardMaterial>>>,
|
|
|
|
@ -1270,31 +1319,32 @@ fn capture_piece(
|
|
|
|
|
|
|
|
|
|
|
|
// Play fade-out animation
|
|
|
|
// Play fade-out animation
|
|
|
|
{
|
|
|
|
{
|
|
|
|
object_dissolve_materials
|
|
|
|
object_dissolve_materials.iter().for_each(|handle| {
|
|
|
|
.iter()
|
|
|
|
let extended_material = dissolve_materials
|
|
|
|
.for_each(|handle| {
|
|
|
|
.get_mut(handle)
|
|
|
|
let extended_material = dissolve_materials
|
|
|
|
.expect("Get the dissolve material");
|
|
|
|
.get_mut(handle)
|
|
|
|
|
|
|
|
.expect("Get the dissolve material");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate how much of the animation has passed
|
|
|
|
// Calculate how much of the animation has passed
|
|
|
|
let delta = time.delta_seconds() / duration;
|
|
|
|
let delta = time.delta_seconds() / duration;
|
|
|
|
|
|
|
|
|
|
|
|
// Change the material's value to create animation
|
|
|
|
// Change the material's value to create animation
|
|
|
|
extended_material.extension.percentage -= delta; // TODO: Tweak this timing
|
|
|
|
extended_material.extension.percentage -= delta; // TODO: Tweak this timing
|
|
|
|
|
|
|
|
|
|
|
|
debug!("Play fade out animation {:?} {:?}", delta, extended_material.extension.percentage);
|
|
|
|
debug!(
|
|
|
|
|
|
|
|
"Play fade out animation {:?} {:?}",
|
|
|
|
|
|
|
|
delta, extended_material.extension.percentage
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if extended_material.extension.percentage <= 0.0 {
|
|
|
|
if extended_material.extension.percentage <= 0.0 {
|
|
|
|
// Set to exactly 0 for simplicity
|
|
|
|
// Set to exactly 0 for simplicity
|
|
|
|
extended_material.extension.percentage = 0.0;
|
|
|
|
extended_material.extension.percentage = 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
// Move to next state now that animation is done
|
|
|
|
// Move to next state now that animation is done
|
|
|
|
*state = s.next();
|
|
|
|
*state = s.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
game::CaptureFlow::Store(entity) => {
|
|
|
|
game::CaptureFlow::Store(entity) => {
|
|
|
|
let (mut v, mut t, side) = query
|
|
|
|
let (mut v, mut t, side) = query
|
|
|
|
.get_mut(entity)
|
|
|
|
.get_mut(entity)
|
|
|
|
@ -1306,7 +1356,7 @@ fn capture_piece(
|
|
|
|
t.translation = capture_translation(side, score.get(*side));
|
|
|
|
t.translation = capture_translation(side, score.get(*side));
|
|
|
|
|
|
|
|
|
|
|
|
*state = s.next();
|
|
|
|
*state = s.next();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
game::CaptureFlow::FadeIn(entity) => {
|
|
|
|
game::CaptureFlow::FadeIn(entity) => {
|
|
|
|
let (mut v, _, _) = query
|
|
|
|
let (mut v, _, _) = query
|
|
|
|
.get_mut(entity)
|
|
|
|
.get_mut(entity)
|
|
|
|
@ -1317,67 +1367,69 @@ fn capture_piece(
|
|
|
|
|
|
|
|
|
|
|
|
// Play fade-in animation
|
|
|
|
// Play fade-in animation
|
|
|
|
{
|
|
|
|
{
|
|
|
|
object_dissolve_materials
|
|
|
|
object_dissolve_materials.iter().for_each(|handle| {
|
|
|
|
.iter()
|
|
|
|
let extended_material = dissolve_materials
|
|
|
|
.for_each(|handle| {
|
|
|
|
.get_mut(handle)
|
|
|
|
let extended_material = dissolve_materials
|
|
|
|
.expect("Get the dissolve material");
|
|
|
|
.get_mut(handle)
|
|
|
|
|
|
|
|
.expect("Get the dissolve material");
|
|
|
|
// Calculate how much of the animation has passed
|
|
|
|
|
|
|
|
let delta = time.delta_seconds() / duration;
|
|
|
|
// Calculate how much of the animation has passed
|
|
|
|
|
|
|
|
let delta = time.delta_seconds() / duration;
|
|
|
|
// Change the material's value to create animation
|
|
|
|
|
|
|
|
extended_material.extension.percentage += delta; // TODO: Tweak this timing
|
|
|
|
// Change the material's value to create animation
|
|
|
|
|
|
|
|
extended_material.extension.percentage += delta; // TODO: Tweak this timing
|
|
|
|
debug!(
|
|
|
|
|
|
|
|
"Play fade in animation {:?} {:?}",
|
|
|
|
debug!("Play fade in animation {:?} {:?}", delta, extended_material.extension.percentage);
|
|
|
|
delta, extended_material.extension.percentage
|
|
|
|
|
|
|
|
);
|
|
|
|
if extended_material.extension.percentage >= 1.0 {
|
|
|
|
|
|
|
|
// Move to next state now that animation is done
|
|
|
|
if extended_material.extension.percentage >= 1.0 {
|
|
|
|
*state = s.next();
|
|
|
|
// Move to next state now that animation is done
|
|
|
|
|
|
|
|
*state = s.next();
|
|
|
|
// Remove the captured component for bookkeeping
|
|
|
|
|
|
|
|
commands.entity(entity).remove::<game::Captured>();
|
|
|
|
// Remove the captured component for bookkeeping
|
|
|
|
|
|
|
|
commands.entity(entity).remove::<game::Captured>();
|
|
|
|
// Remove the dissolve material
|
|
|
|
|
|
|
|
commands.entity(entity).remove::<Handle<DissolveMaterial>>();
|
|
|
|
// Remove the dissolve material
|
|
|
|
|
|
|
|
commands.entity(entity).remove::<Handle<DissolveMaterial>>();
|
|
|
|
// Re-add the original material
|
|
|
|
|
|
|
|
if let Ok(Backup(orig)) = backup_material.get(entity) {
|
|
|
|
// Re-add the original material
|
|
|
|
commands.entity(entity).insert(orig.clone());
|
|
|
|
if let Ok(Backup(orig)) = backup_material.get(entity) {
|
|
|
|
commands.entity(entity).remove::<Backup<Handle<StandardMaterial>>>();
|
|
|
|
commands.entity(entity).insert(orig.clone());
|
|
|
|
} else {
|
|
|
|
commands
|
|
|
|
warn!("Entity {:?} does not have original material", entity)
|
|
|
|
.entity(entity)
|
|
|
|
}
|
|
|
|
.remove::<Backup<Handle<StandardMaterial>>>();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
warn!("Entity {:?} does not have original material", entity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
*state = events.iter().next().map(|entity| {
|
|
|
|
*state = events.iter().next().map(|entity| {
|
|
|
|
children
|
|
|
|
children
|
|
|
|
.iter_descendants(entity)
|
|
|
|
.iter_descendants(entity)
|
|
|
|
.filter_map(|e| {
|
|
|
|
.filter_map(|e| object_standard_materials.get(e).ok().map(|h| (e, h)))
|
|
|
|
object_standard_materials.get(e).ok().map(|h| (e, h))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.for_each(|(child, handle)| {
|
|
|
|
.for_each(|(child, handle)| {
|
|
|
|
// Extension we will add to existing gltf-sourced materials
|
|
|
|
// Extension we will add to existing gltf-sourced materials
|
|
|
|
let extension = DissolveExtension { percentage: 1.0 };
|
|
|
|
let extension = DissolveExtension { percentage: 1.0 };
|
|
|
|
// Base material we will extend for the duration of the dissolve effect
|
|
|
|
// Base material we will extend for the duration of the dissolve effect
|
|
|
|
let mut base = standard_materials.get(handle).expect("Resolve material data").clone();
|
|
|
|
let mut base = standard_materials
|
|
|
|
|
|
|
|
.get(handle)
|
|
|
|
base.opaque_render_method = OpaqueRendererMethod::Auto;
|
|
|
|
.expect("Resolve material data")
|
|
|
|
base.alpha_mode = AlphaMode::Mask(0.5);
|
|
|
|
.clone();
|
|
|
|
|
|
|
|
|
|
|
|
commands.entity(child).insert(
|
|
|
|
base.opaque_render_method = OpaqueRendererMethod::Auto;
|
|
|
|
dissolve_materials.add(ExtendedMaterial {
|
|
|
|
base.alpha_mode = AlphaMode::Mask(0.5);
|
|
|
|
base,
|
|
|
|
|
|
|
|
extension,
|
|
|
|
commands
|
|
|
|
})
|
|
|
|
.entity(child)
|
|
|
|
).insert(Backup(handle.clone()))
|
|
|
|
.insert(dissolve_materials.add(ExtendedMaterial { base, extension }))
|
|
|
|
.remove::<Handle<StandardMaterial>>();
|
|
|
|
.insert(Backup(handle.clone()))
|
|
|
|
|
|
|
|
.remove::<Handle<StandardMaterial>>();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Set the next state to start fading out
|
|
|
|
// Set the next state to start fading out
|
|
|
|
@ -1385,4 +1437,4 @@ fn capture_piece(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|